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.Configuration;
using System.Data.SqlClient;
using Microsoft.CSharp;
using Excel = Microsoft.Office.Interop.Excel;
namespace ImportDataToExcelSP
{
public partial class Form1 : Form
{
private static readonly string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionString");
private static readonly string connectionString = connectionStringName;
public Form1()
{
InitializeComponent();
//cmbRestaurant.SelectedIndex = 0;
Restaurant();
}
public DataSet Restaurant()
{
SqlConnection connection;
SqlDataAdapter adapter;
SqlCommand cmd = new SqlCommand();
DataSet D = new DataSet();
connection = new SqlConnection(connectionString);
connection.Open();
cmd.Connection = connection;
//Load user list
cmd.CommandType = CommandType.Text;
cmd.CommandText = "dbo.om_Equipment";
adapter = new SqlDataAdapter(cmd);
string Q = "select point_location from dbo.om_Equipment";
adapter.SelectCommand = new SqlCommand(Q, connection);
adapter.SelectCommand.ExecuteNonQuery();
DataSet DS5 = new DataSet();
adapter.Fill(DS5, "DS5");
DataTable DSTbl5 = DS5.Tables["DS5"];
cmbRestaurant.DataSource = DS5.Tables[0].DefaultView;
cmbRestaurant.DisplayMember = "point_location";
cmbRestaurant.ValueMember = "point_location";
connection.Close();
connection.Dispose();
cmd.Parameters.Clear();
return D;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void cmbRestaurant_SelectedIndexChanged(object sender, EventArgs e)
{
// string selectedStoreName = cmbRestaurant.SelectedIndex.ToString();
ServiceWindow();
}
public DataSet ServiceWindow()
{
String selectedStoreName = ((DataRowView)cmbRestaurant.SelectedItem).Row["point_location"].ToString();
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "dbo.om_service_window, dbo.om_sw_location_map, dbo.om_Equipment";
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adapter.Fill(ds);
//cmbServiceWindow.DataSource = ds.Tables[0].DefaultView;
//cmbServiceWindow.DisplayMember = "sw_name";
//cmbServiceWindow.ValueMember = "selectedstore_name";
////connection.Close();
//connection.Dispose();
//cmd.Parameters.Clear();
string Q2 = "select distinct sw.sw_name from dbo.om_service_window sw join dbo.om_sw_location_map s on sw.sw_id=s.sw_id join dbo.om_Equipment e on s.point_location=e.point_location where s.point_location='"+selectedStoreName.ToString() +"'";
adapter.SelectCommand = new SqlCommand(Q2, connection);
adapter.SelectCommand.ExecuteNonQuery();
DataSet DS2 = new DataSet();
adapter.Fill(DS2, "DS2");
DataTable DSTbl2 = DS2.Tables["DS2"];
cmbServiceWindow.DataSource = DS2.Tables[0].DefaultView;
cmbServiceWindow.DisplayMember = "sw_name";
cmbServiceWindow.ValueMember = "sw_name";
connection.Close();
connection.Dispose();
cmd.Parameters.Clear();
return DS2;
}
private void cmbServiceWindow_SelectedIndexChanged(object sender, EventArgs e)
{
Equipments();
}
public DataSet Equipments()
{
String ServiceWindow = ((DataRowView)cmbServiceWindow.SelectedItem).Row["sw_name"].ToString();
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "dbo.om_Equipment";
connection.Open();
//cmd = new SqlCommand("select f.p_equip_id from dbo.om_equip_functionblock f join dbo.om_sw_location_map s on f.point_location=s.point_location join dbo.om_service_window sw on s.sw_id=sw.sw_id", connection);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adapter.Fill(ds);
//cmbEquipments.DataSource = ds.Tables[0].DefaultView;
//cmbEquipments.DisplayMember = "p_equip_id";
//cmbServiceWindow.ValueMember = "selectedservice_window";
//connection.Close();
//connection.Dispose();
//cmd.Parameters.Clear();
string Q1 = "select equip_id from dbo.om_Equipment where p_equip_id is null and point_location = 'IR_Schmale' ";
adapter.SelectCommand = new SqlCommand(Q1, connection);
adapter.SelectCommand.ExecuteNonQuery();
DataSet DS1 = new DataSet();
adapter.Fill(DS1, "DS1");
DataTable DSTbl1 = DS1.Tables["DS1"];
cmbEquipments.DataSource = DS1.Tables[0].DefaultView;
cmbEquipments.DisplayMember = "equip_id";
cmbEquipments.ValueMember = "equip_id";
connection.Close();
connection.Dispose();
cmd.Parameters.Clear();
return DS1;
}
private void cmbEquipments_SelectedIndexChanged(object sender, EventArgs e)
{
SubSystems();
}
public DataSet SubSystems()
{
String Equipments = ((DataRowView)cmbEquipments.SelectedItem).Row["equip_id"].ToString();
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "dbo.om_Equipment";
connection.Open();
// cmd = new SqlCommand("select equip_id from dbo.om_equip_functionblock", connection);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adapter.Fill(ds);
//cmbSubSystems.DataSource = ds.Tables[0].DefaultView;
//cmbSubSystems.DisplayMember = "equip_id";
//cmbSubSystems.ValueMember = "equip_id";
//connection.Close();
//connection.Dispose();
//cmd.Parameters.Clear();
string Q3 = "select equip_id from dbo.om_Equipment where p_equip_id='PF' and point_location='IR_Schmale'";
adapter.SelectCommand = new SqlCommand(Q3, connection);
adapter.SelectCommand.ExecuteNonQuery();
DataSet DS3 = new DataSet();
adapter.Fill(DS3, "DS3");
DataTable DSTbl3 = DS3.Tables["DS3"];
cmbSubSystems.DataSource = DS3.Tables[0].DefaultView;
cmbSubSystems.DisplayMember = "equip_id";
cmbSubSystems.ValueMember = "equip_id";
connection.Close();
connection.Dispose();
cmd.Parameters.Clear();
return DS3;
}
private void cmbSubSystems_SelectedIndexChanged(object sender, EventArgs e)
{
Meter();
}
public DataSet Meter()
{
String SubSystems = ((DataRowView)cmbSubSystems.SelectedItem).Row["equip_id"].ToString();
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "dbo.r_equp_meter_map";
connection.Open();
// cmd = new SqlCommand("select equip_id from dbo.om_equip_functionblock", connection);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adapter.Fill(ds);
//cmbSubSystems.DataSource = ds.Tables[0].DefaultView;
//cmbSubSystems.DisplayMember = "equip_id";
//cmbSubSystems.ValueMember = "equip_id";
//connection.Close();
//connection.Dispose();
//cmd.Parameters.Clear();
string Q4 = "select distinct source_type_id from dbo.r_equp_meter_map";
adapter.SelectCommand = new SqlCommand(Q4, connection);
adapter.SelectCommand.ExecuteNonQuery();
DataSet DS4 = new DataSet();
adapter.Fill(DS4, "DS4");
DataTable DSTbl4 = DS4.Tables["DS4"];
cmbMeter.DataSource = DS4.Tables[0].DefaultView;
cmbMeter.DisplayMember = "source_type_id";
cmbMeter.ValueMember = "source_type_id";
connection.Close();
connection.Dispose();
cmd.Parameters.Clear();
return DS4;
}
}
}
But all comboboxes are loading at a time.
(restaurant,service window,Equipments and subsystems) but i want to load them one by one.
On restaurant selected index change service window should be loaded like that.