using System; using System.Data; using System.Text; using System.Threading; using System.Drawing; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; using System.Collections.Generic; using UAS_MES_NEW.CustomControl.PowerControlForm; using System.Xml; using System.IO; using ExcelHelper; using NPOI.SS.UserModel; using NPOI.HSSF.UserModel; using NPOI.SS.Formula.Eval; using NPOI.HSSF.Util; using NPOI.SS.Util; namespace UAS_MES_NEW.Make { public partial class Make_TestCollectionlux : Form { DataHelper dh = null; DataTable dt = null; //当前工序的名称 string ErrorMessage = ""; //用于保存是否之前输入的ms_sncode string LastSncode; string oMakeCode = ""; string oMSID = ""; string ifrework = ""; string reworkstatus = ""; LogStringBuilder sql = new LogStringBuilder(); AutoSizeFormClass asc = new AutoSizeFormClass(); /// /// 已选的不良 /// List ChoosedList = new List(); /// /// 待选的不良 /// List WaitList = new List(); bool AutoCut = false; bool LockSn = false; DataTable Dbfind; public Make_TestCollectionlux() { InitializeComponent(); } private void TestCollection_Load(object sender, EventArgs e) { GoodProduct.Checked = true; asc.controllInitializeSize(this); ms_sncode.Focus(); //设置锁定工单 LockMakeCode.GetMakeCodeCtl(ma_code); ma_code.SetLockCheckBox(LockMakeCode); ControlLockTimer.Tick += ControlLockTimer_Tick; ControlLockTimer.Interval = 100; //工单号放大镜配置 ma_code.TableName = "make left join product on ma_prodcode=pr_code"; ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" }; ma_code.Condition = "ma_statuscode='STARTED'"; ma_code.DbChange += Ma_code_DbChange; dh = SystemInf.dh; StepCount.StepCode = User.CurrentStepCode; StepCount.Source = User.UserSourceCode; StepCount.LineCode = User.UserLineCode; StepCount.Dh = dh; StepCount.Start(); } private void ControlLockTimer_Tick(object sender, EventArgs e) { this.Activate(); ms_sncode.Focus(); } private void Ma_code_DbChange(object sender, EventArgs e) { Dbfind = ma_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); LoadCollectedNum(); LoadCheckQTY(); } private void CleanInfo_Click(object sender, EventArgs e) { OperateResult.Clear(); } private void ms_code_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { WaitList.Clear(); ChoosedList.Clear(); if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage)) { bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage); if (!NoteAlready) { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode); return; } if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage)) { //是否提示过工单切换框,检测前后执行 if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage)) { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode); return; } if (ma_code.Text != oMakeCode && oMakeCode != null) { dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); LockMakeCode.Checked = true; } } dt = (DataTable)dh.ExecuteSql("select ms_nextstepcode,ms_sncode,ms_reworkstatus,nvl(ms_ifrework,0)ms_ifrework,ms_stepcode,ms_status,nvl(ms_netcode,' ') ms_netcode,nvl(st_ifrepair,0) st_ifrepair from makeserial left join step on ms_stepcode=st_code where ms_id='" + oMSID + "'", "select"); string status = dt.Rows[0]["ms_status"].ToString(); reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString(); string stepcode = dt.Rows[0]["ms_stepcode"].ToString(); string ifrepair = dt.Rows[0]["st_ifrepair"].ToString(); string sncode = dt.Rows[0]["ms_sncode"].ToString(); string ms_netcode = dt.Rows[0]["ms_netcode"].ToString(); string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString(); if (ms_netcode != " " && dh.CheckExist("makeserial", "ms_netcode = '" + ms_netcode + "' and ms_sncode <>'" + ms_sncode.Text + "'")) { string othersn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_netcode = '" + ms_netcode + "' and ms_sncode <>'" + ms_sncode.Text + "'").ToString(); OperateResult.AppendText(">>" + ms_sncode.Text + "对应wifibox:"+ms_netcode+"已被SN:"+othersn+"使用\n", Color.Red, ms_sncode); return; } if (sncode != ms_sncode.Text) { OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode); return; } ifrework = dt.Rows[0]["ms_ifrework"].ToString(); DataTable dtx = (DataTable)dh.ExecuteSql("select nvl(pr_omax,0)pr_omax,nvl(pr_omin,0)pr_omin,nvl(pr_tmax,0)pr_tmax,nvl(pr_tmin,0)pr_tmin from product where pr_code = '"+ma_prodcode.Text+"'", "select"); double pr_omax = double.Parse(dtx.Rows[0]["pr_omax"].ToString()); double pr_omin = double.Parse(dtx.Rows[0]["pr_omin"].ToString()); double pr_tmax = double.Parse(dtx.Rows[0]["pr_tmax"].ToString()); double pr_tmin = double.Parse(dtx.Rows[0]["pr_tmin"].ToString()); if (pr_omax == 0 || pr_omin == 0 || pr_tmax == 0 || pr_tmin == 0) { OperateResult.AppendText(">>未获取到光感校准范围值\n", Color.Red, ms_sncode); return; } OperateResult.AppendText(">>设备检测\n", Color.Black); double avg1 = 0; double avg2 = 0; double ver1 = 0; double ver2 = 0; string str = BaseUtil.GetDataAdb("devices").ToUpper().Replace("LIST OF DEVICES ATTACHED", "").Replace("DEVICE", "").Replace("\n", ""); if (!str.Contains(ms_sncode.Text)) { OperateResult.AppendText(">>" + ms_sncode.Text + "与获取SN:"+str+"不一致\n", Color.Red, ms_sncode); return; } OperateResult.AppendText(">>核对SN成功,关闭抽屉\n", Color.Black); BaseUtil.GetDatacmd("Close_Drawer"); Thread.Sleep(7000); OperateResult.AppendText(">>关闭暗箱所有灯光\n", Color.Black); BaseUtil.GetDatacmd("Close_Light_A"); BaseUtil.GetDatacmd("Close_Light_B"); OperateResult.AppendText(">>关闭产品背光\n", Color.Black); BaseUtil.GetDataAdb("shell letools setBacklightState off"); OperateResult.AppendText(">>读取当前光感数值\n", Color.Black); try { double nowdata = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue")); if (nowdata >= 5) { OperateResult.AppendText(">>当前光感"+nowdata+"大于5,重新测试\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } } catch (Exception ex) { OperateResult.AppendText(">>"+ex.Message+"\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } OperateResult.AppendText(">>读取关灯光感数值3次并求出平均值\n", Color.Black); try { for (int i = 0; i < 3; i++) { avg1 = avg1 + double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue")); } avg1 = Math.Round(avg1 / 3, 2); } catch (Exception ex) { OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } OperateResult.AppendText(">>写入关灯光感值"+ avg1 + "\n", Color.Black); BaseUtil.GetDataAdb("shell letools setLightSensorZero "+avg1); dh.ExecuteSql("update makeserial set ms_avg1 = '"+avg1+"' where ms_sncode = '"+ms_sncode.Text+"'", "update"); OperateResult.AppendText(">>暂打开200lux光源\n", Color.Black); BaseUtil.GetDatacmd("Open_Light_A"); OperateResult.AppendText(">>读取当前光感数值\n", Color.Black); try { double nowdata = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue")); if (nowdata < 150) { OperateResult.AppendText(">>当前光感" + nowdata + "小于150,重新测试\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } } catch (Exception ex) { OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } OperateResult.AppendText(">>读取当前200lux光感数值3次并求出平均值\n", Color.Black); avg2 = 0; try { for (int i = 0; i < 3; i++) { avg2 = avg2 + double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue")); } avg2 = Math.Round(avg2 / 3, 2); } catch (Exception ex) { OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } OperateResult.AppendText(">>写入200lux光感值" + avg2 + "\n", Color.Black); BaseUtil.GetDataAdb("shell letools setLightSensorCorr " + avg2); dh.ExecuteSql("update makeserial set ms_avg2 = '" + avg2 + "' where ms_sncode = '" + ms_sncode.Text + "'", "update"); OperateResult.AppendText(">>读取校准后200lux光感\n", Color.Black); ver1 = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValueCorrected")); if (ver1 < pr_omin || ver1 > pr_omax) { OperateResult.AppendText(">>200lux校准光感为" + ver1 + ",不在预设范围内,重新测试\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } OperateResult.AppendText(">>200lux光感校准值"+ ver1 + "保存\n", Color.Black); dh.ExecuteSql("update makeserial set ms_ver1 = '" + ver1 + "' where ms_sncode = '" + ms_sncode.Text + "'", "update"); OperateResult.AppendText(">>关闭200lux并打开20lux\n", Color.Black); BaseUtil.GetDatacmd("Close_Light_A"); BaseUtil.GetDatacmd("Open_Light_B"); OperateResult.AppendText(">>读取校准后20lux光感\n", Color.Black); ver2 = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValueCorrected")); if (ver2 < pr_tmin || ver2 > pr_tmax) { OperateResult.AppendText(">>20lux校准光感为" + ver2 + ",不在预设范围内,重新测试\n", Color.Red, ms_sncode); BaseUtil.GetDatacmd("Open_Drawer"); return; } OperateResult.AppendText(">>20lux光感校准值" + ver2 + "保存\n", Color.Black); dh.ExecuteSql("update makeserial set ms_ver2 = '" + ver2 + "' where ms_sncode = '" + ms_sncode.Text + "'", "update"); OperateResult.AppendText(">>读取WIFI MAC和BT MAC\n", Color.Black); string mac = BaseUtil.GetDataAdb("shell ft.sh getmac wifi"); string bt = BaseUtil.GetDataAdb("shell ft.sh getmac bt"); OperateResult.AppendText(">>保存WIFI:"+mac+",BT:"+bt+"\n", Color.Black); dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "',ms_bt = '"+bt+"' where ms_sncode = '" + ms_sncode.Text + "'", "update"); OperateResult.AppendText(">>测试完成打开抽屉\n", Color.Black); BaseUtil.GetDatacmd("Open_Drawer"); int index = LabelDataGridView.Rows.Add(); LabelDataGridView.Rows[index].Cells["SN"].Value = ms_sncode.Text; LabelDataGridView.Rows[index].Cells["avg1"].Value = avg1; LabelDataGridView.Rows[index].Cells["avg2"].Value = avg2; LabelDataGridView.Rows[index].Cells["ver1"].Value = ver1; LabelDataGridView.Rows[index].Cells["ver2"].Value = ver2; LabelDataGridView.Rows[index].Cells["wifis"].Value = mac; LabelDataGridView.Rows[index].Cells["bts"].Value = bt; if (!File.Exists(SystemInf.CacheFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".xls")) { //创建内存流 MemoryStream ms = new MemoryStream(); //创建一个Book,相当于一个Excel文件 HSSFWorkbook book = new HSSFWorkbook(); //Excel中的Sheet ISheet sheet = book.CreateSheet("sheet1"); //获取行数量和列数量 int rowNum = LabelDataGridView.Rows.Count; int columnNum = LabelDataGridView.Columns.Count; //设置列的宽度,根据首行的列的内容的长度来设置 for (int i = 0; i < columnNum; i++) { int dataLength = LabelDataGridView.Columns[i].Width; if (dataLength == 5) { sheet.SetColumnWidth(i, 0); } else { sheet.SetColumnWidth(i, dataLength * 25); } } //首先画好第一行带颜色的,单独写出来,避免写在循环里面 IRow row = sheet.CreateRow(0); //冻结第一行 sheet.CreateFreezePane(0, 1, 0, 1); ICellStyle style = book.CreateCellStyle(); style.FillForegroundColor = HSSFColor.PALE_BLUE.index; style.FillPattern = FillPatternType.BIG_SPOTS; style.FillBackgroundColor = HSSFColor.LIGHT_GREEN.index; //设置边框 style.BorderBottom = NPOI.SS.UserModel.BorderStyle.THICK; style.BorderLeft = NPOI.SS.UserModel.BorderStyle.THICK; style.BorderRight = NPOI.SS.UserModel.BorderStyle.THICK; style.BorderTop = NPOI.SS.UserModel.BorderStyle.THICK; row.HeightInPoints = 20; //固定第一行 //row.RowStyle.IsLocked=true; //给第一行的标签赋值样式和值 for (int j = 0; j < columnNum; j++) { row.CreateCell(j); row.Cells[j].CellStyle = style; row.Cells[j].CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row.Cells[j].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER; row.Cells[j].SetCellValue(LabelDataGridView.Columns[j].HeaderText); } //将DataTable的值循环赋值给book,Aligment设置居中 //之前已经画了带颜色的第一行,所以从i=1开始画 IRow row1 = sheet.CreateRow(sheet.LastRowNum + 1); row1.HeightInPoints = 20; row1.CreateCell(0); row1.Cells[0].SetCellValue(ms_sncode.Text); row1.GetCell(0).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(1); row1.Cells[1].SetCellValue(avg1); row1.GetCell(1).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(2); row1.Cells[2].SetCellValue(avg2); row1.GetCell(2).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(3); row1.Cells[3].SetCellValue(ver1); row1.GetCell(3).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(4); row1.Cells[4].SetCellValue(ver2); row1.GetCell(4).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(5); row1.Cells[5].SetCellValue(mac); row1.GetCell(5).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(6); row1.Cells[6].SetCellValue(bt); row1.GetCell(6).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; //将book的内容写入内存流中返回 book.Write(ms); //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限 string filePath = SystemInf.CacheFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"; FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); byte[] data = ms.ToArray(); fs.Write(data, 0, data.Length); fs.Flush(); //释放当前Excel文件,否则打开文件的时候会显示文件被占用 ms.Dispose(); fs.Dispose(); } else { //创建内存流 MemoryStream ms = new MemoryStream(); string filePath = SystemInf.CacheFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"; FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); HSSFWorkbook book = new HSSFWorkbook(fs); ISheet sheet = book.GetSheet("sheet1"); IRow row1 = sheet.CreateRow(sheet.LastRowNum + 1); row1.HeightInPoints = 20; row1.CreateCell(0); row1.Cells[0].SetCellValue(ms_sncode.Text); row1.GetCell(0).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(1); row1.Cells[1].SetCellValue(avg1); row1.GetCell(1).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(2); row1.Cells[2].SetCellValue(avg2); row1.GetCell(2).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(3); row1.Cells[3].SetCellValue(ver1); row1.GetCell(3).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(4); row1.Cells[4].SetCellValue(ver2); row1.GetCell(4).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(5); row1.Cells[5].SetCellValue(mac); row1.GetCell(5).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; row1.CreateCell(6); row1.Cells[6].SetCellValue(bt); row1.GetCell(6).CellStyle.VerticalAlignment = VerticalAlignment.CENTER; fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); fs.Flush(); book.Write(fs); fs.Close(); } SetCollectResult(); } else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode); } else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode); } } /// /// 设置良品或者不良品的采集结果 /// private void SetCollectResult() { string ErrorMessage = ""; //如果勾选的是不良品 if (Reject.Checked) { OperateResult.AppendText(">>请采集不良代码\n", Color.Green); //勾选了自动产生代码 if (AutoBadCode.Checked) Save_Click(new object(), new EventArgs()); } else if (GoodProduct.Checked) { //如果不是返修的 if (ifrework == "0") { dt = (DataTable)dh.ExecuteSql("select mb_id,bc_name,mbr_mbid from makebad left join makebadreason on mbr_mbid=mb_id left join badcode on mb_badcode=bc_code where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0", "select"); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString()) ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】"; } //存在不良记录 if (ErrorMessage != "") { OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red); return; } else { //良品信息采集 if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage)) { //提示正确返回时传递的信息 if (ErrorMessage.Contains("AFTERSUCCESS")) OperateResult.AppendText(">>" + ErrorMessage + "\n"); LastSncode = ms_sncode.Text; OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode); //记录操作日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text); } else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode); } } else { if (reworkstatus != "3") { if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage)) { //提示正确返回时传递的信息 if (ErrorMessage.Contains("AFTERSUCCESS")) OperateResult.AppendText(">>" + ErrorMessage + "\n"); LastSncode = ms_sncode.Text; OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode); //记录操作日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text); } else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode); } else { OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red); } } } //加载页面信息 LoadCollectedNum(); LoadCheckQTY(); } private void 测试采集_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void LoadCollectedNum() { dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select"); BaseUtil.SetFormValue(Controls, dt); } private void Save_Click(object sender, EventArgs e) { if (ms_sncode.Text == "") { OperateResult.AppendText(">>序列号不允许为空\n", Color.Red); return; } if (GoodProduct.Checked) ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } private void LoadCheckQTY() { sql.Clear(); string condition = ""; int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text); int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text); if (nowcheckqty + 1 == batchqty && AutoCut) { condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'"; } else { condition = "and ob_status='ENTERING' "; } if (pr_sendchecktype.Text == "SaleCode") { condition += " and ob_salecode='" + ma_salecode.Text + "'"; } sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where "); sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and "); sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString(); ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString(); ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString(); ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString(); nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text); batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text); if (nowcheckqty == batchqty) { ob_nowcheckqty.ForeColor = Color.Red; OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red); if (AutoCut) { OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Blue); } } } else { BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno); SendCheck.Enabled = false; } if (ob_batchqty.Text != "") { SendCheck.Enabled = true; } else { SendCheck.Enabled = false; } } private void GoodProduct_CheckedChanged(object sender, EventArgs e) { if (GoodProduct.Checked) { Save.Visible = false; } else { Save.Visible = true; } if (ms_sncode.Text == "") { ms_sncode.Focus(); } } private void SendCheck_Click(object sender, EventArgs e) { sql.Clear(); sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'"); dh.ExecuteSql(sql.GetString(), "select"); ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString(); ob_nowcheckqty.Text = ""; ob_batchqty.Text = ""; ob_nowcheckqty.ForeColor = Color.Black; SendCheck.Enabled = false; OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue); ms_sncode.Focus(); LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode); //记录操作日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text); ob_checkno.Text = ""; } private void ob_checkno_TextChanged(object sender, EventArgs e) { if (ob_checkno.Text != "") { string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString(); if (Cut == "" || Cut == "0") AutoCut = false; else AutoCut = true; SendCheck.Enabled = true; } } /// /// 工单变化修改数量 /// /// /// private void ma_code_UserControlTextChanged(object sender, EventArgs e) { if (ma_code.Text.Length > 4) { BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty); LoadCollectedNum(); LoadCheckQTY(); } } private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e) { dh.Dispose(); } private void ma_prodcode_TextChanged(object sender, EventArgs e) { } private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q) { if (!LockSn) { ControlLockTimer.Start(); LockSn = true; Lock_label.Visible = true; } else { ControlLockTimer.Stop(); LockSn = false; Lock_label.Visible = false; } } } private void button1_Click(object sender, EventArgs e) { } } }