获取有关在单击按钮时所有五个组合框的值的提示 [英] Tips to get the values of all the five comboboxes on Button click
本文介绍了获取有关在单击按钮时所有五个组合框的值的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请根据五个组合框的值选择,向我发送触发按钮单击事件的代码.
更新:
Please send me code for button click event to fire on the basis of selection of values of five comboboxes.
UPDATE:
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 Form2 : Form
{
private static readonly string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionString");
private static readonly string connectionString = connectionStringName;
public Form2()
{
InitializeComponent();
this.cmbRestaurant.SelectedIndexChanged -= new System.EventHandler(this.cmbRestaurant_SelectedIndexChanged);
Restaurant();
this.cmbRestaurant.SelectedIndexChanged += new System.EventHandler(this.cmbRestaurant_SelectedIndexChanged);
}
public DataSet Restaurant()
{
SqlConnection connection;
SqlDataAdapter adapter;
SqlCommand cmd = new SqlCommand();
DataSet D = new DataSet();
connection = new SqlConnection(connectionString);
connection.Open();
cmd.Connection = connection;
// cmbRestaurant.Items.Insert(0, new List<>"Select Region", "NA"));
//Load user list
cmd.CommandType = CommandType.Text;
cmd.CommandText = "dbo.om_Equipment";
adapter = new SqlDataAdapter(cmd);
string Q = "select distinct 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;
}
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);
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;
}
public DataSet Equipments()
{
// String selectedStoreName = ((DataRowView)cmbRestaurant.SelectedItem).Row["point_location"].ToString();
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_service_window, dbo.om_sw_location_map, dbo.om_Equipment";
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
string Q2 = "select distinct e.equip_id from dbo.om_Equipment e join dbo.om_sw_location_map s on s.point_location=e.point_location join dbo.om_service_window sw on sw.sw_id=s.sw_id where e.p_equip_id is null and sw.sw_name='" + ServiceWindow.ToString() + "'";
adapter.SelectCommand = new SqlCommand(Q2, connection);
adapter.SelectCommand.ExecuteNonQuery();
DataSet DS2 = new DataSet();
adapter.Fill(DS2, "DS2");
DataTable DSTbl2 = DS2.Tables["DS2"];
cmbEquipments.DataSource = DS2.Tables[0].DefaultView;
cmbEquipments.DisplayMember = "sw_name";
cmbEquipments.ValueMember = "equip_id";
connection.Close();
connection.Dispose();
cmd.Parameters.Clear();
return DS2;
}
public DataSet SubSystems()
{
// String selectedStoreName = ((DataRowView)cmbRestaurant.SelectedItem).Row["point_location"].ToString();
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);
string Q3 = "select distinct equip_id from dbo.om_Equipment where p_equip_id='" + Equipments.ToString() + "'";
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;
}
public DataSet Meter()
{
// String selectedStoreName = ((DataRowView)cmbRestaurant.SelectedItem).Row["point_location"].ToString();
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, dbo.om_Equipment";
connection.Open();
// cmd = new SqlCommand("select equip_id from dbo.om_equip_functionblock", connection);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
string Q4 = "select distinct source_type_id from dbo.r_equp_meter_map r join dbo.om_Equipment e on r.point_location=e.point_location where e.equip_id='"+SubSystems.ToString()+"'";
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;
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void cmbRestaurant_SelectedIndexChanged(object sender, EventArgs e)
{
this.cmbServiceWindow.SelectedIndexChanged -= new System.EventHandler(this.cmbServiceWindow_SelectedIndexChanged);
ServiceWindow();
this.cmbServiceWindow.SelectedIndexChanged += new System.EventHandler(this.cmbServiceWindow_SelectedIndexChanged);
}
private void cmbServiceWindow_SelectedIndexChanged(object sender, EventArgs e)
{
this.cmbEquipments.SelectedIndexChanged -= new System.EventHandler(this.cmbEquipments_SelectedIndexChanged);
Equipments();
this.cmbEquipments.SelectedIndexChanged += new System.EventHandler(this.cmbEquipments_SelectedIndexChanged);
}
private void cmbEquipments_SelectedIndexChanged(object sender, EventArgs e)
{
this.cmbSubSystems.SelectedIndexChanged -= new System.EventHandler(this.cmbSubSystems_SelectedIndexChanged);
SubSystems();
this.cmbSubSystems.SelectedIndexChanged += new System.EventHandler(this.cmbSubSystems_SelectedIndexChanged);
}
private void cmbSubSystems_SelectedIndexChanged(object sender, EventArgs e)
{
// this.cmbMeter.SelectedIndexChanged -= new System.EventHandler(this.cmbMeter_SelectedIndexChanged);
Meter();
//this.cmbMeter.SelectedIndexChanged += new System.EventHandler(this.cmbMeter_SelectedIndexChanged);
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
推荐答案
this.button1.Click -= new System.EventHandler(this.button1_Click);
String selectedStoreName = ((DataRowView)cmbRestaurant.SelectedItem).Row["point_location"].ToString();
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.Click -= new System.EventHandler(this.button1_Click);
String ServiceWindow = ((DataRowView)cmbServiceWindow.SelectedItem).Row["sw_name"].ToString();
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.Click -= new System.EventHandler(this.button1_Click);
String Equipments = ((DataRowView)cmbEquipments.SelectedItem).Row["equip_id"].ToString();
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.Click -= new System.EventHandler(this.button1_Click);
String SubSystems = ((DataRowView)cmbSubSystems.SelectedItem).Row["equip_id"].ToString();
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.Click -= new System.EventHandler(this.button1_Click);
String Meter = ((DataRowView)cmbMeter.SelectedItem).Row["source_type_id"].ToString();
this.button1.Click += new System.EventHandler(this.button1_Click);
我现在已经创建了此事件处理程序,如何将组合框选择的值导出到excel?
I have created this event handlers now how to export the combobox selected values to excel?
这篇关于获取有关在单击按钮时所有五个组合框的值的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文