private void FormLug_Load(object sender, EventArgs e)
{
FieldListLug.Clear();//字段清除
DI = double.Parse(tbDn.Text);//DI等于tbdn中的值 把值强制转化成DOUBLE型
string TypeName = "Y_SUPPORT_LUG_4712_3_2007_TYPE";//定义查询表名
string where = string.Format("DnX < {0} and DnD > {0}", DI);//定义查询条件
//where = "DnX < " + DI.ToString() + " and DnD > " + DI.ToString();
FieldListLug.Add("TypeC");//要查询的列
tbType = GetAccessData(TypeName, FieldListLug, where);//获得查询出来的表
TypeList = tbType.AsEnumerable()
.Select(p => p.Field<string>("TypeC")).Distinct().ToList();//将表变成列
cbType.Items.AddRange(TypeList.ToArray());//变成列加入控件中
//cbType.SelectedIndex = 0;
}
private void tbDn_TextChanged(object sender, EventArgs e)
{
#region 解除事务
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 增加事务
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里面数据变化时产生的操作
{
cbbHasCover.Enabled = true;//默认CHACKBOX初始时为可以改变
FieldListLug.Clear();//清除耳座字段列表
string TypeName = "Y_SUPPORT_LUG_4712_3_2007_TYPE";//定义查找表名的字符串
string where = string.Format("DnX < {0} and DnD > {0} and TypeC = ‘{1}‘"
, DI, cbType.Text);//定义查找条件字符串
FieldListLug.Add("HasCover");//将需要的列的字段加入字段列 可以加入多个
tbTopPlate = GetAccessData(TypeName, FieldListLug,
where);//查询表 使用查询语句将表名 条件 字段列加入获得顶板表
TopPlateList = tbTopPlate.AsEnumerable()
.Select(p => p.Field<bool>("HasCover")).Distinct().ToList();//将获得的表变成列 p.Field<>中类型要保持一致,Distinct()将重复的去除
if (TopPlateList.Count == 1)//如果TopPlateList中只有一个数据 则始终不能改变
{
if (TopPlateList[0])//获取列中第一个数据 因为是一个BOOL型的列 如果第一个数据是TURE则有盖板并且成立
{
cbbHasCover.Checked = true;//选择有盖板
cbbHasCover.Enabled = false;//并且不能改变
}
else//如果没有
{
cbbHasCover.Checked = false;//选择无盖板
cbbHasCover.Enabled = false;//也不能改变
}
}
}
private void cbbHasCover_CheckedChanged(object sender, EventArgs e)
{
FieldListLug.Clear();//继续清除字段
string TypeName = "Y_SUPPORT_LUG_4712_3_2007_TYPE";//定义查找表名的字符串
string where = string.Format("DnX < {0} and DnD > {0} and TypeC = ‘{1}‘ and HasCover = {2}",
DI, cbType.Text, cbbHasCover.Checked);//定义查找条件字符串
FieldListLug.Add("LugNumber");//将需要的列的字段加入字段列 可以加入多个
tbNum = GetAccessData
(TypeName, FieldListLug, where);//查询表 使用查询语句将表名 条件 字段列加入 获得顶板表
NumList = tbNum.AsEnumerable()
.Select(p => p.Field<int>
("LugNumber").ToString()).Distinct().ToList();//.ToString()将查询结果变成字符型,
//如果上面list定义成字符型就要转化成字符型 如果是int型与前面一致则不需要.前面int则是数据表中类型
cbNum.Items.AddRange(NumList.ToArray());//将数据列转化成数组然后加入cbnum中,只接受数组
}
private void cbNum_SelectedIndexChanged(object sender, EventArgs e)
{
FieldListLug.Clear();//继续清除字段
if (cbType.Text == A)//选择了A
{
// string killedString = "";
// killedString = "q1,q2,DnX,DnD";
string TypeName = "Y_SUPPORT_LUG_4712_3_2007_A";//查询表A
string where = string.Format("LugNumber = {0} ",
cbNum.Text);//定义查询条件
tbValue = GetAccessData(TypeName, null, where);//查出需要的表
}
else if (cbType.Text == B)//选择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)//选择C
{
string TypeName = "Y_SUPPORT_LUG_4712_3_2007_C";
string where = string.Format("LugNumber = {0} ",
cbNum.Text);
tbValue = GetAccessData(TypeName, null, where);
}
}