When the data in the From form changes, use code to get the data from the database and then join the ComboBox and get the final result from the database

Source: Internet
Author: User

private void Formlug_load (object sender, EventArgs e)
{
Fieldlistlug.clear ();//Field cleanup
DI = Double. Parse (tbdn.text);//di equals value in Tbdn force conversion of value to double type
String TypeName = "Y_support_lug_4712_3_2007_type";//define Query table name
string where = string. Format ("DnX < {0} and DnD > {0}", DI);//define query criteria
where = "DnX <" + DI. ToString () + "and DnD >" + DI. ToString ();
Fieldlistlug.add ("Typec");//the column to query
Tbtype = Getaccessdata (TypeName, Fieldlistlug, where);//Get the query out of the table
Typelist = Tbtype.asenumerable ()
. Select (p = = p.field<string> ("Typec")). Distinct (). ToList ();//Turn Tables into columns
CbType.Items.AddRange (Typelist.toarray ());//Become a column join control
Cbtype.selectedindex = 0;
}
private void Tbdn_textchanged (object sender, EventArgs e)
{
#region Dismiss a transaction
this.tbDn.HideSelectionChanged-= new System.EventHandler (this.tbdn_textchanged);
this.cbType.SelectedIndexChanged-= new System.EventHandler (this.cbtype_selectedindexchanged);
this.cbNum.SelectedIndexChanged-= new System.EventHandler (this.cbnum_selectedindexchanged);
#endregion
#region Increase Transactions
This.tbDn.HideSelectionChanged + = new System.EventHandler (this.tbdn_textchanged);
This.cbType.SelectedIndexChanged + = new System.EventHandler (this.cbtype_selectedindexchanged);
This.cbNum.SelectedIndexChanged + = new System.EventHandler (this.cbnum_selectedindexchanged);
Topplatelist.clear ();
#endregion
}

private void Cbtype_selectedindexchanged (object sender, EventArgs e)//cbtype operations generated when data changes
{
cbbhascover.enabled = true;//default Chackbox can be changed at initial time
Fieldlistlug.clear ();//Clear the ear-seat field list
String TypeName = "Y_support_lug_4712_3_2007_type";//strings that define lookup table names
string where = string. Format ("DnX < {0} and DnD > {0} and Typec = ' {1} '"
, DI, Cbtype.text);//define a Find condition string
Fieldlistlug.add ("Hascover");//Add the fields of the required columns to the field column to add multiple
Tbtopplate = Getaccessdata (TypeName, Fieldlistlug,
where);//Query Tables use Query statements to add Table name criteria field columns to the roof table
Topplatelist = Tbtopplate.asenumerable ()
. Select (p = = p.field<bool> ("Hascover")). Distinct (). ToList ()///The obtained table becomes column p.field<> type to be consistent, Distinct () will repeat the removal
if (Topplatelist.count = = 1)//If only one data in topplatelist can never be changed
{
if (topplatelist[0])//Gets the first data in the column because it is a bool type column if the first data is ture there is a cover plate and is established
{
cbbhascover.checked = true;//Select a cover plate
cbbhascover.enabled = false;//and cannot be changed
}
else//if not
{
cbbhascover.checked = false;//selection without cover plate
Cbbhascover.enabled = false;//also cannot change
}
}
}
private void Cbbhascover_checkedchanged (object sender, EventArgs e)
{
Fieldlistlug.clear ();//continue to clear fields
String TypeName = "Y_support_lug_4712_3_2007_type";//strings that define lookup table names
string where = string. Format ("DnX < {0} and DnD > {0} and Typec = ' {1} ' and Hascover = {2}",
DI, Cbtype.text, cbbhascover.checked);//define a Find condition string
Fieldlistlug.add ("Lugnumber");//Add the fields of the required columns to the field column to add multiple
Tbnum = Getaccessdata
(TypeName, Fieldlistlug, where);//Query Tables use Query statements to add table name condition field columns to the roof table
Numlist = Tbnum.asenumerable ()
. Select (p = p.field<int>
("Lugnumber"). ToString ()). Distinct (). ToList ();//. ToString () turns the query result into a character type,
If the list above is defined as a character type, it will be converted into a character type if the int type is the same as the previous one. The preceding int is the type in the data table
CbNum.Items.AddRange (Numlist.toarray ());//Convert the data column to an array and then join the Cbnum, only accept arrays
}
private void Cbnum_selectedindexchanged (object sender, EventArgs e)
{
Fieldlistlug.clear ();//continue to clear fields
if (Cbtype.text = = a)//select a
{
String killedstring = "";
killedstring = "Q1,q2,dnx,dnd";
String TypeName = "y_support_lug_4712_3_2007_a";//query Table A
string where = string. Format ("Lugnumber = {0}",
Cbnum.text);//define query criteria
Tbvalue = Getaccessdata (TypeName, NULL, where);//Isolate the required table
}
else if (Cbtype.text = = b)//select B
{
String TypeName = "Y_support_lug_4712_3_2007_b";
string where = string. Format ("Lugnumber = {0}",
Cbnum.text);
Tbvalue = Getaccessdata (TypeName, NULL, where);
}
else if (Cbtype.text = = c)//select C
{
String TypeName = "Y_support_lug_4712_3_2007_c";
string where = string. Format ("Lugnumber = {0}",
Cbnum.text);
Tbvalue = Getaccessdata (TypeName, NULL, where);
}

}

When the data in the From form changes, use code to get the data from the database and then join the ComboBox and get the final result from the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.