using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Javaher
{
    public partial class Form6 : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=javaher;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();
        DataTable dtcustomer = new DataTable();
        DataSet1 ds = new DataSet1();
        public Form6()
        {
            InitializeComponent();
        }

        private void Form6_Load(object sender, EventArgs e)
        {
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "select name from [customer]";
            SqlDataReader drcustomer = cmd.ExecuteReader();
            dtcustomer.Columns.Add("name");
            dtcustomer.Load(drcustomer);
            comboBox1.DataSource = dtcustomer;
            comboBox1.ValueMember = "name";
            comboBox1.DisplayMember = "name";
            con.Close();
            /////
            comboBox1_SelectedIndexChanged(null, null);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (con.State == ConnectionState.Open)
                con.Close();

            ds.Clear();
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "select * from [factor] where customername='"+comboBox1.SelectedValue.ToString()+"'";
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds, "tblfactor");
            con.Close();
            CrystalReport11.SetDataSource(ds.Tables["tblfactor"]);
            crystalReportViewer1.ReportSource = CrystalReport11;

        }
    }
}
