using System; using System.Data; using System.Drawing; using System.Text; using System.Threading; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.SMT { public partial class SMT_Feeding : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; DataTable dt; LogStringBuilder sql = new LogStringBuilder(); RadioButton[] RadioButton; //判断用户是否执行过筛选 bool Filtered = false; //勾选的RadioButton RadioButton CheckedRadio; //一些全局变量作为传值条件 //站位表的物料编号 string psl_prodcode; //站位表的替代料 string psl_repcode; double barremain; string barcode; string forcastremain; string psltable = ""; string bar_prodcode; //DevSmtLocation表主键 string dsl_id; //DevSmtLocation表主键 int dsl_remainqty; //DevSmtLocation表条码号 string dsl_barcode; //制造单号的机台编号 string ma_smtcode; SMT_MakeShift MShift; public SMT_Feeding() { InitializeComponent(); } private void SMT上料_Load(object sender, EventArgs e) { de_table.Text = "全部"; asc.controllInitializeSize(this); dh = new DataHelper(); //机台编号 de_code.FormName = Name; de_code.SetValueField = new string[] { "ma_code", "de_runstatus", "de_code", "de_table" }; de_code.TableName = "device left join make on de_macode=ma_code"; de_code.SelectField = "de_code # 设备编号,de_linecode # 线别编号,de_name # 设备名称,de_runstatus # 运行状态,ma_code # 工单号,de_table # 版面"; de_code.Condition = "de_linecode='" + User.UserLineCode + "'"; //工单号 ma_code.TableName = "make left join product on ma_prodcode=pr_code"; ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 物料编号,ma_qty # 数量,ma_prodname # 物料名称,ma_wccode # 工作中心编号,ma_linecode # 工单线别,pr_spec # 产品规格"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "ma_qty", "ma_prodspec", "ma_id", "ma_linecode", "ma_prodcode", "pr_spec" }; RadioButton = new RadioButton[] { UpLoad, DownLoad, Shift, PickUp }; } private void Input_KeyDown(object sender, KeyEventArgs e) { if (Keys.Enter == e.KeyData) { //点击过筛选按钮才允许 if (Filtered) { switch (CheckedRadio.Name.ToUpper()) { //上料 case "UPLOAD": //首先录入面板号 if (psl_location.Text == "") { sql.Clear(); sql.Append("select psl_prodcode,psl_repcode,psl_table from productsmtlocation left join productsmt on ps_id=psl_psid "); sql.Append("left join make on ma_smtcode=ps_code where ma_code='" + ma_code.Text + "' and psl_location='" + Input.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); LogManager.DoLog("【" + Text + "】上料操作", sql.GetString()); if (dt.Rows.Count > 0) { psltable = dt.Rows[0]["psl_table"].ToString(); psl_prodcode = dt.Rows[0]["psl_prodcode"].ToString(); psl_repcode = dt.Rows[0]["psl_repcode"].ToString(); sql.Clear(); sql.Append("select dsl_id,dsl_barcode from devSMTLocation left join make on ma_code=dsl_makecode and dsl_linecode="); sql.Append("ma_linecode where dSL_MAKECODE='" + ma_code.Text + "' and dsl_devcode ='" + de_code.Text + "' And"); sql.Append(" dsl_location='" + Input.Text + "' and dsl_status = 0"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0) { psl_location.Text = Input.Text; OperateResult.AppendText(">>站位采集" + Input.Text + "成功,请采集物料" + psl_prodcode + " 的料卷号\n", Color.Green); } else { OperateResult.AppendText(">>站位已有料卷" + dt.Rows[0]["dsl_barcode"].ToString() + ",不允许重复上料\n", Color.Red); } Input.Text = ""; } else { OperateResult.AppendText(">>站位错误,不存在上料排位表中\n", Color.Red); } } //采集料圈数量 else if (bar_code.Text == "") { dt = (DataTable)dh.ExecuteSql("select bar_remain,nvl(bar_place,1) bar_place,bar_prodcode,bar_code,bar_forcastremain from barcode where bar_code='" + Input.Text + "' and bar_status=1", "select"); //查询回来的有库存的话 if (dt.Rows.Count > 0) { forcastremain = dt.Rows[0]["bar_forcastremain"].ToString(); barremain = double.Parse(dt.Rows[0]["bar_remain"].ToString()); barcode = dt.Rows[0]["bar_code"].ToString(); //并且库存不为0 //到此步骤已采集成功站位和料卷号 if (dt.Rows[0]["bar_remain"].ToString() != "0") { if (dt.Rows[0]["bar_place"].ToString() == "1") { bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString(); //如果采集的料卷的物料编号和站位表的物料或者替代料相等 if (bar_prodcode == psl_prodcode || psl_repcode.Contains(bar_prodcode)) { if (forcastremain != "0" && forcastremain != "" && forcastremain != barremain.ToString()) { bar_code.Text = Input.Text; bar_remain.Text = forcastremain; } else { bar_remain.Text = double.Parse(barremain.ToString()).ToString(); //插入数据至devSMTLocation sql.Clear(); sql.Append("insert into DEVSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,"); sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)"); sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',"); sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "',"); sql.Append("'" + barcode + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt on ma_smtcode=ps_code "); sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and psl_location='" + psl_location.Text + "' and rownum<=1"); dh.ExecuteSql(sql.GetString(), "insert"); //如果几台绑定的工单号未空的情况下更新成当前采集料的 if (dh.getFieldDataByCondition("device", "de_macode", "de_code='" + de_code.Text + "'").ToString() == "") { dh.ExecuteSql("update device set de_macode='" + ma_code.Text + "' where de_code='" + de_code.Text + "'", "update"); } //更新条码(barcode)状态在线上 bar_Place=工单号 dh.ExecuteSql("update barcode set bar_Place='" + ma_code.Text + "' where bar_code='" + Input.Text + "' and bar_status=1", "update"); OperateResult.AppendText(">>料卷采集成功,数量" + barremain + "\n", Color.Green); LoadGridData(); CleanInf(); } } else { OperateResult.AppendText(">>采集的物料号" + Input.Text + "不匹配\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">>料卷" + Input.Text + "已上线\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">> 料卷编号" + Input.Text + "错误,库存数量为0\n", Color.Green); Input.Text = ""; } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red); Input.Text = ""; } } else if (bar_code.Text != "" && psl_location.Text != "" && bar_remain.Text != "") { bar_remain.Text = double.Parse(barremain.ToString()).ToString(); //插入数据至devSMTLocation sql.Clear(); sql.Append("insert into DEVSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,"); sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)"); sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',"); sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "',"); sql.Append("'" + barcode + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt on ma_smtcode=ps_code "); sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and psl_location='" + psl_location.Text + "' and rownum<=1"); dh.ExecuteSql(sql.GetString(), "insert"); //如果几台绑定的工单号未空的情况下更新成当前采集料的 if (dh.getFieldDataByCondition("device", "de_macode", "de_code='" + de_code.Text + "'").ToString() == "") { dh.ExecuteSql("update device set de_macode='" + ma_code.Text + "' where de_code='" + de_code.Text + "'", "update"); } //更新条码(barcode)状态在线上 bar_Place=工单号 dh.ExecuteSql("update barcode set bar_Place='" + ma_code.Text + "' where bar_code='" + Input.Text + "' and bar_status=1", "update"); OperateResult.AppendText(">>料卷采集成功,数量" + barremain + "\n", Color.Green); LoadGridData(); CleanInf(); } break; //下料 case "DOWNLOAD": sql.Clear(); sql.Append("select dsl_location,dsl_barcode,dsl_remainqty,dsl_prodcode from devSMTLocation left join make on ma_code=dsl_makecode and ma_linecode=dsl_linecode "); sql.Append("where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and (dsl_barcode='" + Input.Text + "' or "); sql.Append("dsl_location='" + Input.Text + "') and nvl(dsl_status,0)=0"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { string dsl_location = dt.Rows[0]["dsl_location"].ToString(); string dsl_barcode = dt.Rows[0]["dsl_barcode"].ToString(); string dsl_remainqty = dt.Rows[0]["dsl_remainqty"].ToString(); string dsl_prodcode = dt.Rows[0]["dsl_prodcode"].ToString(); dh.UpdateByCondition("DEVSMTLocation", "dsl_status=-1,dsl_invalidtime=sysdate", "dsl_location='" + dsl_location + "'"); dh.UpdateByCondition("barcode", "bar_place=1,bar_forcastremain =" + dsl_remainqty, "bar_code='" + dsl_barcode + "'"); OperateResult.AppendText(">>退料成功\n", Color.Green); //下料后判断当前的设备时候还有料存在 sql.Clear(); sql.Append("select dsl_makecode from device left join devSMTLocation "); sql.Append("on de_code=dsl_devcode where de_code='" + de_code.Text + "' and dsl_status=0 and dsl_makecode<>'" + ma_code.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0) { dh.ExecuteSql("update device set de_macode='' where de_code='" + de_code.Text + "'", "update"); } LoadGridData(); } else { OperateResult.AppendText(">>料卷号或者站位错误,无需退料\n", Color.Red); } break; //接料 case "PICKUP": //查询站位是否存在 if (psl_location.Text == "") { sql.Clear(); sql.Append("select psl_prodcode,psl_repcode from productsmtlocation left join productsmt on ps_id=psl_psid left join make on "); sql.Append("ma_smtcode=ps_code where ma_code='" + ma_code.Text + "' and psl_location='" + Input.Text + "' "); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { psl_location.Text = Input.Text; Input.Text = ""; //获取物料号和替代料 psl_prodcode = dt.Rows[0]["psl_prodcode"].ToString(); psl_repcode = dt.Rows[0]["psl_repcode"].ToString(); OperateResult.AppendText(">>站位采集成功,请采集物料" + psl_prodcode + " 的料卷号\n", Color.Green); } else { OperateResult.AppendText(">>站位错误,不存在上料排位表中\n", Color.Red); } } else if (bar_code.Text == "") { dt = (DataTable)dh.ExecuteSql("select bar_remain,bar_forcastremain from barcode where bar_code='" + Input.Text + "' and bar_status=1", "select"); barremain = double.Parse(dt.Rows[0]["bar_remain"].ToString()); forcastremain = dt.Rows[0]["bar_remain"].ToString(); if (dt.Rows.Count > 0) { //如果剩余的数量不为0的话 if (dt.Rows[0]["bar_remain"].ToString() != "0") { sql.Clear(); sql.Append("select * from devSMTLocation left join make on ma_code=dsl_makecode and ma_linecode=dsl_linecode where dsl_makecode='" + ma_code.Text + "'"); sql.Append(" and dsl_devcode='" + de_code.Text + "' and dsl_location='" + psl_location.Text + "' and dsl_status=0"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { //上一条码的剩余数量 int dsl_remainqty = int.Parse(dt.Rows[0]["dsl_remainqty"].ToString()); string dsl_barcode = dt.Rows[0]["dsl_barcode"].ToString(); string dsl_id = dt.Rows[0]["dsl_id"].ToString(); dt = (DataTable)dh.ExecuteSql("select nvl(bar_place,1) bar_place,bar_remain,bar_prodcode from barcode where bar_code='" + Input.Text + "'", "select"); if (dt.Rows.Count > 0) { if (dt.Rows[0]["bar_place"].ToString() == "1") { string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString(); //本次切换的料卷剩余的 barremain = int.Parse(dt.Rows[0]["bar_remain"].ToString()); if (psl_prodcode == bar_prodcode || psl_repcode == bar_prodcode) { if (forcastremain != "0" && forcastremain != "" && forcastremain != barremain.ToString()) { bar_code.Text = Input.Text; bar_remain.Text = forcastremain; } else { bar_remain.Text = barremain.ToString(); //插入数据至devSMTLocation sql.Clear(); sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,"); sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_smtid,dsl_indate) select devSMTLocation_SEQ.nextval,"); sql.Append("ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',"); sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "','" + Input.Text + "',"); sql.Append("ma_linecode,'" + de_code.Text + "',0,ps_id,sysdate from make left join productsmt on ma_smtcode=ps_code "); sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' "); sql.Append("and psl_location='" + psl_location.Text + "' and rownum<=1 "); dh.ExecuteSql(sql.GetString(), "insert"); //更新站位原料卷号下线,bar_forcastremain 剩余数为0 //dh.UpdateByCondition("barcode", "bar_place=1,bar_forcastremain=0", "bar_code='" + dsl_barcode + "'"); //更新条码状态在线上 bar_Place=2 dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'"); LoadGridData(); CleanInf(); OperateResult.AppendText(">>采集成功\n", Color.Green); } Input.Text = ""; } else { OperateResult.AppendText(">>采集的物料号" + Input.Text + "不匹配\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">>料卷" + Input.Text + "已经上料或者备料\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">>站位" + Input.Text + "错误,无此机台工单站位\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,库存数量为0\n", Color.Red); Input.Text = ""; } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red); Input.Text = ""; } } else if (bar_code.Text != "" && psl_location.Text != "" && bar_remain.Text != "") { bar_remain.Text = barremain.ToString(); //插入数据至devSMTLocation sql.Clear(); sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,"); sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_smtid,dsl_indate) select devSMTLocation_SEQ.nextval,"); sql.Append("ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',"); sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "','" + Input.Text + "',"); sql.Append("ma_linecode,'" + de_code.Text + "',0,ps_id,sysdate from make left join productsmt on ma_smtcode=ps_code "); sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' "); sql.Append("and psl_location='" + psl_location.Text + "' and rownum<=1 "); dh.ExecuteSql(sql.GetString(), "insert"); //更新站位原料卷号下线,bar_forcastremain 剩余数为0 //dh.UpdateByCondition("barcode", "bar_place=1,bar_forcastremain=0", "bar_code='" + dsl_barcode + "'"); //更新条码状态在线上 bar_Place=2 dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'"); LoadGridData(); CleanInf(); OperateResult.AppendText(">>采集成功\n", Color.Green); } break; //换料 case "SHIFT": if (psl_location.Text == "") { sql.Clear(); sql.Append("select psl_prodcode,psl_repcode from productsmtlocation left join productsmt on ps_id=psl_psid left join make on "); sql.Append("ma_smtcode=ps_code where ma_code='" + ma_code.Text + "' and psl_location='" + Input.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { psl_location.Text = Input.Text; Input.Text = ""; //获取物料号和替代料 psl_prodcode = dt.Rows[0]["psl_prodcode"].ToString(); psl_repcode = dt.Rows[0]["psl_repcode"].ToString(); OperateResult.AppendText(">>站位采集成功,请采集物料" + psl_prodcode + " 的料卷号\n", Color.Green); } else { OperateResult.AppendText(">>站位错误,不存在上料排位表中\n", Color.Red); } } else if (bar_code.Text == "") { dt = (DataTable)dh.ExecuteSql("select bar_remain,bar_forcastremain from barcode where bar_code='" + Input.Text + "' and bar_status=1", "select"); if (dt.Rows.Count > 0) { //如果剩余的数量不为0的话 if (dt.Rows[0]["bar_remain"].ToString() != "0") { bar_remain.Text = dt.Rows[0]["bar_remain"].ToString(); forcastremain = dt.Rows[0]["bar_forcastremain"].ToString(); sql.Clear(); sql.Append("select * from devSMTLocation left join make on ma_code=dsl_makecode and ma_linecode=dsl_linecode "); sql.Append("where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and dsl_location='" + psl_location.Text + "'"); sql.Append("and dsl_status=0 "); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { //上一条码的剩余数量 dsl_remainqty = int.Parse(dt.Rows[0]["dsl_remainqty"].ToString()); dsl_barcode = dt.Rows[0]["dsl_barcode"].ToString(); dsl_id = dt.Rows[0]["dsl_id"].ToString(); dt = (DataTable)dh.ExecuteSql("select nvl(bar_place,1) bar_place,bar_remain,bar_prodcode from barcode where bar_code='" + Input.Text + "'", "select"); if (dt.Rows.Count > 0) { if (dt.Rows[0]["bar_place"].ToString() == "1") { string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString(); //本次切换的料卷剩余的 barremain = int.Parse(dt.Rows[0]["bar_remain"].ToString()); if (psl_prodcode == bar_prodcode || psl_repcode == bar_prodcode) { if (forcastremain != "0" && forcastremain != "" && forcastremain != barremain.ToString()) { bar_code.Text = Input.Text; bar_remain.Text = forcastremain; } else { //更新原料卷站位状态下料dsl_status=-1 dh.ExecuteSql("Update devSMTLocation set dsl_status=-1 where dsl_id=" + dsl_id, "update"); //更新站位原料卷号下线,bar_forcastremain 剩余数 dsl_remain dh.UpdateByCondition("barcode", "bar_forcastremain=" + dsl_remainqty + ",bar_place=1", "bar_code='" + dsl_barcode + "'"); //将新条码数据插入至devSMTLocation sql.Clear(); sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,dsl_indate,"); sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)"); sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',"); sql.Append("'" + psl_repcode + "',psl_feeder,sysdate,'" + bar_remain.Text + "','" + bar_remain.Text + "',"); sql.Append("'" + Input.Text + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt "); sql.Append("on ma_smtcode=ps_code left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and "); sql.Append("psl_location='" + psl_location.Text + "' and rownum<=1"); dh.ExecuteSql(sql.GetString(), "insert"); //更新新条码状态在线上 bar_Place=2 dh.UpdateByCondition("barcode", "bar_Place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'"); //更新原条码上料记录 LoadGridData(); CleanInf(); OperateResult.AppendText(">>换料成功\n", Color.Green); } } else { OperateResult.AppendText(">>采集的物料号" + Input.Text + "不匹配\n", Color.Red); } } else { OperateResult.AppendText(">>料卷" + Input.Text + "已经上料或者备料\n", Color.Red); } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red); } } else { OperateResult.AppendText(">>站位" + Input.Text + "错误,无此机台工单站位\n", Color.Red); } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,库存数量为0\n", Color.Red); } } else { OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red); } } else if (bar_code.Text != "" && psl_location.Text != "" && bar_remain.Text != "") { //更新原料卷站位状态下料dsl_status=-1 dh.ExecuteSql("Update devSMTLocation set dsl_status=-1 where dsl_id=" + dsl_id, "update"); //更新站位原料卷号下线,bar_forcastremain 剩余数 dsl_remain dh.UpdateByCondition("barcode", "bar_forcastremain=" + dsl_remainqty + ",bar_place=1", "bar_code='" + dsl_barcode + "'"); //将新条码数据插入至devSMTLocation sql.Clear(); sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,"); sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)"); sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',"); sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "',"); sql.Append("'" + Input.Text + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt "); sql.Append("on ma_smtcode=ps_code left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and "); sql.Append("psl_location='" + psl_location.Text + "' and rownum<=1"); dh.ExecuteSql(sql.GetString(), "insert"); //更新新条码状态在线上 bar_Place=2 dh.UpdateByCondition("barcode", "bar_Place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'"); //更新原条码上料记录 LoadGridData(); CleanInf(); OperateResult.AppendText(">>换料成功\n", Color.Green); } break; } Input.Text = ""; } else { MessageBox.Show("必须执行过筛选操作"); } } } private void SMT上料_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } /// /// 筛选按钮 /// /// /// private void Screen_Click(object sender, EventArgs e) { CleanInf(); if (ma_code.Text != "" && de_code.Text != "") { sql.Clear(); sql.Append("select dsl_makecode from device left join devsmtlocation "); sql.Append("on de_code=dsl_devcode where de_code='" + de_code.Text + "' and dsl_status=0 and dsl_makecode<>'" + ma_code.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); LogManager.DoLog("【" + Text + "】筛选操作", sql.GetString()); //判断机台是否存在工单 if (dt.Rows.Count > 0) { OperateResult.AppendText(">>机台号:" + de_code.Text + " ,存在工单:" + dt.Rows[0]["dsl_makecode"].ToString() + "的料卷未下料,请先下料!\n", Color.Red); return; } sql.Clear(); sql.Append("select dsl_devcode from devsmtlocation where dsl_devcode<>'" + de_code.Text + "' and dsl_status=0 and dsl_makecode='" + ma_code.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //判断工单是否已经在机台上线 if (dt.Rows.Count > 0) { OperateResult.AppendText(">>工单号:" + ma_code.Text + " ,已上机台号:" + de_code.Text + "需要转线才能重新上其他机台!\n", Color.Red); return; } //判断岗位资源的线别和制造单的线别是否相等 dt = (DataTable)dh.ExecuteSql("select ma_smtcode,ma_linecode from make where ma_code='" + ma_code.Text + "'", "select"); ma_smtcode = dt.Rows[0]["ma_smtcode"].ToString(); if (User.UserLineCode != dt.Rows[0]["ma_linecode"].ToString()) { OperateResult.AppendText(">>岗位资源的线别必须等于制造单的线别\n", Color.Red); return; } LoadGridData(); Filtered = true; Filter.Text = "已筛选"; MakeShift.Visible = true; if (Filtered) { for (int i = 0; i < RadioButton.Length; i++) { switch (RadioButton[i].Name.ToUpper()) { //上料 case "UPLOAD": if (RadioButton[i].Checked) { CheckedRadio = RadioButton[i]; OperateResult.AppendText(">>请采集站位\n", Color.Green); } if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED")) { RadioButton[i].CheckedChanged += RadioCheckedChange; } break; //下料 case "DOWNLOAD": if (RadioButton[i].Checked) { CheckedRadio = RadioButton[i]; OperateResult.AppendText(">>请采集需要退料的料卷号或者站位\n", Color.Green); } if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED")) { RadioButton[i].CheckedChanged += RadioCheckedChange; } break; //换料 case "SHIFT": if (RadioButton[i].Checked) { CheckedRadio = RadioButton[i]; OperateResult.AppendText(">>请采集需要换料的站位\n", Color.Green); } if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED")) { RadioButton[i].CheckedChanged += RadioCheckedChange; } break; //接料 case "PICKUP": if (RadioButton[i].Checked) { CheckedRadio = RadioButton[i]; OperateResult.AppendText(">>请采集需要接料的站位\n", Color.Green); } if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED")) { RadioButton[i].CheckedChanged += RadioCheckedChange; } break; } } } } else { MessageBox.Show("工单号和机台号不允许为空"); } } private void RadioCheckedChange(object sender, EventArgs e) { if ((sender as RadioButton).Checked) { CleanInf(); switch ((sender as RadioButton).Name.ToUpper()) { //上料 case "UPLOAD": OperateResult.AppendText(">>请采集站位\n", Color.Green); CheckedRadio = sender as RadioButton; break; //下料 case "DOWNLOAD": OperateResult.AppendText(">>请采集需要退料的料卷号或者站位\n", Color.Green); CheckedRadio = sender as RadioButton; break; //换料 case "SHIFT": OperateResult.AppendText(">>请采集需要换料的站位\n", Color.Green); CheckedRadio = sender as RadioButton; break; //接料 case "PICKUP": OperateResult.AppendText(">>请采集需要接料的站位\n", Color.Green); CheckedRadio = sender as RadioButton; break; default: break; } } } /// /// 根据四个不同的RadioButton的勾选状态不同执行不同的逻辑 /// /// /// private void Confirm_Click(object sender, EventArgs e) { KeyEventArgs e2 = new KeyEventArgs(Keys.Enter); Input_KeyDown(sender, e2); } private void Start_Click(object sender, EventArgs e) { if (Filtered) { if (de_code.Text != "") { if (de_table.Text != "全部") { sql.Clear(); sql.Append("select ps_id from productsmt left join productsmtlocation on ps_id=psl_psid where ps_code='" + ma_smtcode + "' and psl_table='" + de_table.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { string psl_psid = dt.Rows[0]["ps_id"].ToString(); //1、刚开始启动的时候更新版面,单位用量 sql.Clear(); sql.Append("update devsmtlocation set dsl_baseqty=(select psl_baseqty from productsmtlocation where psl_psid='" + psl_psid + "' and psl_table='" + de_table.Text + "' "); sql.Append("and psl_location=dsl_location) where dsl_makecode='" + ma_code.Text + "' and dsl_linecode='" + User.UserLineCode + "' and dsl_devcode='" + de_code.Text + "' and dsl_status=0 "); dh.ExecuteSql(sql.GetString(), "update"); //2、判断站位是否上齐料 sql.Clear(); sql.Append("SELECT wm_concat(psl_location) FROM Productsmtlocation where psl_psid='" + psl_psid + "' and psl_table='" + de_table.Text + "' "); sql.Append("and not exists (select 1 from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_linecode='" + User.UserLineCode + "'"); sql.Append("and dsl_devcode='" + de_code.Text + "' and dsl_devcode='" + de_code.Text + "' and dsl_status=0 and dsl_location=psl_location) and rownum<=20"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows[0][0].ToString() == "") { LogManager.DoLog("【" + Text + "】启用机台操作", dh.UpdateByCondition("device", "de_runstatus = '运行中',de_table='" + de_table.Text + "'", "de_code = '" + de_code.Text + "' and de_runstatus = '停止'")); de_code.RefreshDB(sender, e); MessageBox.Show("启用机台成功"); } else { MessageBox.Show("站位" + dt.Rows[0][0].ToString() + "未上料"); } } else { MessageBox.Show("该版面不存在于排位表中"); } } else { MessageBox.Show("必须选择一个版面"); } } else { MessageBox.Show("机台号不能为空!"); } } else { MessageBox.Show("必须执行过筛选操作"); } } private void DownLoadAll_Click(object sender, EventArgs e) { if (Filtered) { sql.Clear(); sql.Append("select count(1) from devSmtLocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); LogManager.DoLog("【" + Text + "】全部下料操作", sql.GetString()); if (dt.Rows[0][0].ToString() != "0") { //更新在线料卷所在场所,剩余数 sql.Clear(); sql.Append("update barcode set bar_place='1',bar_forcastremain=(select dsl_remainqty from "); sql.Append("devsmtlocation where dsl_barcode=bar_code and dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and "); sql.Append("nvl(dsl_status,0)=0) where exists (select 1 from devsmtlocation where "); sql.Append("dsl_barcode=bar_code and dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and dsl_status=0)"); dh.ExecuteSql(sql.GetString(), "update"); //将信息插入MakeSMTLocation表中 sql.Clear(); sql.Append("insert into makeSMTLocation(msl_id,msl_maid,msl_makecode, msl_mmdetno,msl_location,msl_prodcode,msl_repcode,msl_fespec,msl_invalidtime,"); sql.Append("msl_baseqty,msl_table,msl_needqty,msl_getqty,msl_remainqty,msl_barcode,msl_linecode,msl_devcode,msl_status,msl_validtime,msl_indate)"); sql.Append("select makeSMTLocation_SEQ.nextval,dsl_maid,dsl_makecode,dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,sysdate,"); sql.Append("dsl_baseqty,dsl_table,dsl_needqty,dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,-1,dsl_validtime,dsl_indate "); sql.Append("from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'"); dh.ExecuteSql(sql.GetString(), "insert"); //从DevSMTLocation中移除 dh.ExecuteSql("delete from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'", "delete"); LogManager.DoLog("【" + Text + "】全部下料操作", sql.GetString()); //更新上料排位表状态为-1 LogManager.DoLog("【" + Text + "】全部下料操作", sql.GetString()); OperateResult.AppendText(">>" + Input.Text + "退料成功\n", Color.Green); dh.ExecuteSql("update device set de_macode='',de_table='' where de_code='" + de_code.Text + "'", "update"); ma_code.Enabled = true; de_table.Enabled = true; LoadGridData(); } else { OperateResult.AppendText(">>没有需要下料的料卷\n", Color.Red); LogManager.DoLog("【" + Text + "】没有需要下料的料卷"); } } else { MessageBox.Show("必须执行过筛选操作"); } } /// /// 工单切换 /// /// /// private void MakeShift_Click(object sender, EventArgs e) { MShift = new SMT_MakeShift(); //给小窗口的确认按钮加一个事件 MShift.Controls["Confirm"].Click += MakeShiftButtonClick; BaseUtil.SetFormCenter(MShift); MShift.ShowDialog(); } private void MakeShiftButtonClick(object sender, EventArgs e) { //从工单切换窗口取得字符串 string macode = MShift.Controls["ma_code"].Text; string maprodcode = MShift.Controls["ma_prodcode"].Text; string maid = MShift.Controls["ma_id"].Text; string maqty = MShift.Controls["ma_qty"].Text; string maline = MShift.Controls["ma_linecode"].Text; string masmtcode = MShift.Controls["ma_smtcode"].Text; sql.Clear(); sql.Append("select dsl_smtid from devsmtlocation where dsl_devcode='" + de_code.Text + "' and "); sql.Append("NVL(dsl_status,0)=0 and dsl_makecode='" + ma_code.Text + "' and dsl_remainqty>0"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { //判断工单站位是否一致 //原工单 string dsl_smtid = dt.Rows[0]["dsl_smtid"].ToString(); //新工单 string psl_id1 = dh.getFieldDataByCondition("productsmt left join productsmtlocation on ps_id=psl_psid", "psl_psid", "ps_code='" + masmtcode + "'").ToString(); sql.Clear(); sql.Append("select psl_location from productsmtlocation where psl_psid=:dsl_smtid minus select psl_location from productsmtlocation where psl_psid=:psl_id1"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", dsl_smtid, psl_id1); if (dt.Rows.Count > 0) { OperateResult.AppendText(">>切换站位工单不一致\n", Color.Red); return; } sql.Clear(); sql.Append("select psl_location from productsmtlocation where psl_psid=:dsl_smtid minus select psl_location from productsmtlocation where psl_psid=:psl_id1"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", psl_id1, dsl_smtid); if (dt.Rows.Count > 0) { OperateResult.AppendText(">>切换站位工单不一致\n", Color.Red); return; } sql.Clear(); sql.Append("select a.psl_location,wm_concat(a.psl_prodcode||','||a.psl_repcode) a_prodcode,wm_concat(','||b.psl_prodcode||','"); sql.Append("||b.psl_repcode) b_prodcode from productsmtlocation a left join productsmtlocation b on a.psl_location"); sql.Append("=b.psl_location where a.psl_psid=:dsl_smtid and b.psl_psid=:psl_id1 group by a.psl_location"); bool Break = false; dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", dsl_smtid, psl_id1); for (int i = 0; i < dt.Rows.Count; i++) { string[] a_prodcode = dt.Rows[i]["a_prodcode"].ToString().Split(','); for (int j = 0; j < a_prodcode.Length; j++) { if (dt.Rows[i]["b_prodcode"].ToString().Contains("," + a_prodcode[i] + ",")) { Break = true; break; } } if (Break) { break; } } if (!Break) { OperateResult.AppendText(">>工单物料不匹配\n", Color.Red); return; } sql.Clear(); sql.Append("select count(1) cn from devsmtlocation where dsl_makecode='" + macode + "' and NVL(dsl_status,0)=0"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows[0][0].ToString() == "0") { if (User.UserLineCode == maline) { //该机台原工单中在线剩余数为0的料卷更新所在场所为下线 sql.Clear(); sql.Append("update barcode set bar_place=1,bar_forcastremain=0 where exists (select 1 from devsmtlocation "); sql.Append("where dsl_barcode=bar_code and dsl_makecode='" + ma_code.Text + "' and dsl_status=0 and nvl(dsl_remainqty,0)=0)"); dh.ExecuteSql(sql.GetString(), "update"); //将数据插入MakeSmtLoaction表中 sql.Clear(); sql.Append("insert into makeSMTLocation(msl_id,msl_maid,msl_makecode, msl_mmdetno,msl_location,msl_prodcode,msl_repcode,msl_fespec,msl_invalidtime,"); sql.Append("msl_baseqty,msl_table,msl_needqty,msl_getqty,msl_remainqty,msl_barcode,msl_linecode,msl_devcode,msl_status,msl_validtime,msl_indate)"); sql.Append("select makeSMTLocation_SEQ.nextval,dsl_maid,dsl_makecode,dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,sysdate,"); sql.Append("dsl_baseqty,dsl_table,dsl_needqty,dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,-1,dsl_validtime,dsl_indate "); sql.Append("from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'"); dh.ExecuteSql(sql.GetString(), "insert"); //从DevSMTLocation中移除 dh.ExecuteSql("delete from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'", "delete"); //更新机台绑定的工单为空 dh.UpdateByCondition("device", "de_macode='" + macode + "'", "de_code='" + de_code.Text + "'"); MShift.Close(); //重新加载数据 de_code.RefreshDB(sender, e); MessageBox.Show("切换成功"); } else { OperateResult.AppendText(">>切换的工单" + macode + "线别不一致\n", Color.Red); } } else { OperateResult.AppendText(">>切换的工单" + macode + "已在其他机台上料\n", Color.Red); } } else { OperateResult.AppendText(">>该机台工单无在线料卷无法切换\n", Color.Red); } } private void Pause_Click(object sender, EventArgs e) { if (de_code.Text != "") { dh.ExecuteSql("update device set de_runstatus='停止' where de_code='" + de_code.Text + "' and de_runstatus='运行中'", "update"); LogManager.DoLog(Text + "暂停使用机台", "update device set de_runstatus='停止' where de_code='" + de_code.Text + "' and de_runstatus='运行中'"); de_code.RefreshDB(sender, e); MessageBox.Show("停用机台成功"); } else { MessageBox.Show("机台号不能为空!"); } } private void Clean_Click(object sender, EventArgs e) { OperateResult.Clear(); } private void LoadGridData() { sql.Clear(); sql.Append("select v_location,v_table,v_prodcode,v_baseqty,v_baseqty*ma_qty v_needqty,v_feeder,v_barcode,v_remainqty,v_indate,v_nextbarcode, "); sql.Append("v_nextremainqty from make left join MES_SMTLOCATION_VIEW on MA_SMTCODE=V_SMTCODE where ma_code =:ma_code "); if (de_table.Text != "全部") { sql.Append(" and v_table =:v_table"); } dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", ma_code.Text, de_table.Text); BaseUtil.FillDgvWithDataTable(SMTInf, dt); } //清除采集信息 private void CleanInf() { psl_location.Text = ""; bar_code.Text = ""; Input.Text = ""; bar_remain.Text = ""; } private void Clearpsl_location_Click(object sender, EventArgs e) { psl_location.Text = ""; OperateResult.AppendText(">>请采集站位\n", Color.Green); } //Text事件触发界面赋值的方法 private void de_macode_UserControlTextChanged(object sender, EventArgs e) { ma_code.TextBox_Leave(sender, e); //如果通过Leavl事件找到了数据 if (ma_code.LeaveFindData) { if (de_code.Text != "" && ma_code.Text != "") { Screen_Click(sender, new EventArgs()); } } } //机台号的EnTer事件,触发筛选 private void de_code_TextKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (de_code.Text != "" && ma_code.Text != "") { Screen_Click(sender, new EventArgs()); } } } private void AddDataToDataTable(params object[] param) { DataTable copydata = (DataTable)(SMTInf.DataSource); DataRow dr = copydata.NewRow(); for (int i = 0; i < copydata.Columns.Count; i++) { switch (copydata.Columns[i].DataType.ToString()) { case "System.String": dr[i] = param[i].ToString(); break; case "System.Decimal": dr[i] = (decimal)param[i]; break; case "System.DateTime": if (param[i] == null) { dr[i] = DBNull.Value; } else { dr[i] = (DateTime)param[i]; } break; default: break; } } copydata.Rows.Add(dr); } private void Clearbar_code_Click(object sender, EventArgs e) { bar_code.Text = ""; } private void de_code_UserControlTextChanged(object sender, EventArgs e) { de_code.TextBox_Leave(sender, e); //如果工单号不为空并且找到了数据 if (ma_code.Text != "" && de_code.LeaveFindData) { ma_code.Enabled = false; } if (de_table.Text != "全部") { de_table.Enabled = false; } } } }