1 private void FormLug_Load(object sender, EventArgs e) 2 { 3 FieldListLug.Clear();//字段清除 4 DI = double.Parse(tbDn.Text);//DI等于tbdn中的值 把值强制转化成DOUBLE型 5 string TypeName = "Y_SUPPORT_LUG_4712_3_2007_TYPE";//定义查询表名 6 string where = string.Format("DnX < {0} and DnD > {0}", DI);//定义查询条件 7 //where = "DnX < " + DI.ToString() + " and DnD > " + DI.ToString(); 8 FieldListLug.Add("TypeC");//要查询的列 9 tbType = GetAccessData(TypeName, FieldListLug, where);//获得查询出来的表 10 TypeList = tbType.AsEnumerable() 11 .Select(p => p.Field<string>("TypeC")).Distinct().ToList();//将表变成列 12 cbType.Items.AddRange(TypeList.ToArray());//变成列加入控件中 13 //cbType.SelectedIndex = 0; 14 } 15 private void tbDn_TextChanged(object sender, EventArgs e) 16 { 17 #region 解除事务 18 this.tbDn.HideSelectionChanged -= new System.EventHandler(this.tbDn_TextChanged); 19 this.cbType.SelectedIndexChanged -= new System.EventHandler(this.cbType_SelectedIndexChanged); 20 this.cbNum.SelectedIndexChanged -= new System.EventHandler(this.cbNum_SelectedIndexChanged); 21 #endregion 22 #region 增加事务 23 this.tbDn.HideSelectionChanged += new System.EventHandler(this.tbDn_TextChanged); 24 this.cbType.SelectedIndexChanged += new System.EventHandler(this.cbType_SelectedIndexChanged); 25 this.cbNum.SelectedIndexChanged += new System.EventHandler(this.cbNum_SelectedIndexChanged); 26 TopPlateList.Clear(); 27 #endregion 28 } 29 30 private void cbType_SelectedIndexChanged(object sender, EventArgs e)//CBTYPE里面数据变化时产生的操作 31 { 32 cbbHasCover.Enabled = true;//默认CHACKBOX初始时为可以改变 33 FieldListLug.Clear();//清除耳座字段列表 34 string TypeName = "Y_SUPPORT_LUG_4712_3_2007_TYPE";//定义查找表名的字符串 35 string where = string.Format("DnX < {0} and DnD > {0} and TypeC = '{1}'" 36 , DI, cbType.Text);//定义查找条件字符串 37 FieldListLug.Add("HasCover");//将需要的列的字段加入字段列 可以加入多个 38 tbTopPlate = GetAccessData(TypeName, FieldListLug, 39 where);//查询表 使用查询语句将表名 条件 字段列加入获得顶板表 40 TopPlateList = tbTopPlate.AsEnumerable() 41 .Select(p => p.Field<bool>("HasCover")).Distinct().ToList();//将获得的表变成列 p.Field<>中类型要保持一致,Distinct()将重复的去除 42 if (TopPlateList.Count == 1)//如果TopPlateList中只有一个数据 则始终不能改变 43 { 44 if (TopPlateList[0])//获取列中第一个数据 因为是一个BOOL型的列 如果第一个数据是TURE则有盖板并且成立 45 { 46 cbbHasCover.Checked = true;//选择有盖板 47 cbbHasCover.Enabled = false;//并且不能改变 48 } 49 else//如果没有 50 { 51 cbbHasCover.Checked = false;//选择无盖板 52 cbbHasCover.Enabled = false;//也不能改变 53 } 54 } 55 } 56 private void cbbHasCover_CheckedChanged(object sender, EventArgs e) 57 { 58 FieldListLug.Clear();//继续清除字段 59 string TypeName = "Y_SUPPORT_LUG_4712_3_2007_TYPE";//定义查找表名的字符串 60 string where = string.Format("DnX < {0} and DnD > {0} and TypeC = '{1}' and HasCover = {2}", 61 DI, cbType.Text, cbbHasCover.Checked);//定义查找条件字符串 62 FieldListLug.Add("LugNumber");//将需要的列的字段加入字段列 可以加入多个 63 tbNum = GetAccessData 64 (TypeName, FieldListLug, where);//查询表 使用查询语句将表名 条件 字段列加入 获得顶板表 65 NumList = tbNum.AsEnumerable() 66 .Select(p => p.Field<int> 67 ("LugNumber").ToString()).Distinct().ToList();//.ToString()将查询结果变成字符型, 68 //如果上面list定义成字符型就要转化成字符型 如果是int型与前面一致则不需要.前面int则是数据表中类型 69 cbNum.Items.AddRange(NumList.ToArray());//将数据列转化成数组然后加入cbnum中,只接受数组 70 } 71 private void cbNum_SelectedIndexChanged(object sender, EventArgs e) 72 { 73 FieldListLug.Clear();//继续清除字段 74 if (cbType.Text == A)//选择了A 75 { 76 // string killedString = ""; 77 // killedString = "q1,q2,DnX,DnD"; 78 string TypeName = "Y_SUPPORT_LUG_4712_3_2007_A";//查询表A 79 string where = string.Format("LugNumber = {0} ", 80 cbNum.Text);//定义查询条件 81 tbValue = GetAccessData(TypeName, null, where);//查出需要的表 82 } 83 else if (cbType.Text == B)//选择B 84 { 85 string TypeName = "Y_SUPPORT_LUG_4712_3_2007_B"; 86 string where = string.Format("LugNumber = {0} ", 87 cbNum.Text); 88 tbValue = GetAccessData(TypeName, null, where); 89 } 90 else if (cbType.Text == C)//选择C 91 { 92 string TypeName = "Y_SUPPORT_LUG_4712_3_2007_C"; 93 string where = string.Format("LugNumber = {0} ", 94 cbNum.Text); 95 tbValue = GetAccessData(TypeName, null, where); 96 } 97 98 }