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 UAS_MES_NEW.PublicForm; using LabelManager2; using System.IO; using System.Text.RegularExpressions; using System.Runtime.InteropServices; namespace UAS_MES_NEW.Make { public partial class Make_SnwriteCollection : Form { DataHelper dh = null; DataTable dt = null; //当前工序的名称 [DllImport("User32.dll", EntryPoint = "FindWindow")] public extern static IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] public static extern int RegisterWindowMessage(string lpString); [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = System.Runtime.InteropServices.CharSet.Auto)] // public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam); [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam, int lparam); enum GetWindow_Cmd : uint { GW_HWNDFIRST = 0, GW_HWNDLAST = 1, GW_HWNDNEXT = 2, GW_HWNDPREV = 3, GW_OWNER = 4, GW_CHILD = 5, GW_ENABLEDPOPUP = 6 } //应用程序发送此消息来设置一个窗口的文本 const int WM_SETTEXT = 0x0C; //应用程序发送此消息来复制对应窗口的文本到缓冲区 const int WM_GETTEXT = 0x0D; const int WM_GETTEXTLENGTH = 0x000E; const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; string zxstring = ""; 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; string labelname; DataTable Dbfind; ApplicationClass lbl; Thread thread; // Document doc; public Make_SnwriteCollection() { InitializeComponent(); } public void RegisterControlforMessages() { RegisterWindowMessage("WM_GETTEXT"); } 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; labelname = System.Windows.Forms.Application.StartupPath + @"\badsn.lab"; //thread = new Thread(NewPrint); // SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序"); //BaseUtil.SetFormCenter(stw); // stw.ShowDialog(); //工单号放大镜配置 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(); timer1.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) { if (sender.ToString() != "123") { if (!mtkche.Checked && !zxche.Checked && !mtkche1.Checked) { OperateResult.AppendText(">>选择写号平台\n", Color.Red, ms_sncode); return; } } 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(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(); if (sncode != ms_sncode.Text) { OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode); return; } ifrework = dt.Rows[0]["ms_ifrework"].ToString(); if (GoodProduct.Checked) { if (sender.ToString() != "123") { if (mtkche.Checked) { if (!dh.CheckExist("makesnlist", "msl_sncode = '" + ms_sncode.Text + "'")) { OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号为导入至SN清单,无法采集\n", Color.Red, ms_sncode); return; } string bt = dh.getFieldDataByCondition("makesnlist", "msl_bt", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string mac = dh.getFieldDataByCondition("makesnlist", "msl_mac", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string imei = dh.getFieldDataByCondition("makesnlist", "msl_imei", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string imei1 = dh.getFieldDataByCondition("makesnlist", "msl_imei1", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); IntPtr maindHwnd = FindWindow(null, "SN Writer V1.2020.0.0-TEE-v4360"); //获得标题外部运行程序的句柄 // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄 if (maindHwnd != IntPtr.Zero) { //Scan Data IntPtr Secform = FindWindow(null, "Scan Data"); //获得标题外部运行程序的句柄 if (Secform == IntPtr.Zero) { IntPtr hbuttonbox = FindWindowEx(maindHwnd, IntPtr.Zero, null, "Start");//通过按键名称获取按键ID SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键 SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键 Thread.Sleep(500); Secform = FindWindow(null, "Scan Data"); } if (Secform != IntPtr.Zero) { IntPtr snp = FindWindowEx(Secform, IntPtr.Zero, null, "SerialNo.:");//通过类型获取第一个文本编辑框 IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr btp = FindWindowEx(Secform, IntPtr.Zero, null, "BT Addr:");//通过类型获取第一个文本编辑框 IntPtr bte = FindWindowEx(Secform, btp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr macp = FindWindowEx(Secform, IntPtr.Zero, null, "Wifi Addr:");//通过类型获取第一个文本编辑框 IntPtr mace = FindWindowEx(Secform, macp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imeip = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_1:");//通过类型获取第一个文本编辑框 IntPtr imeie = FindWindowEx(Secform, imeip, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imei1p = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_2:");//通过类型获取第一个文本编辑框 IntPtr imei1e = FindWindowEx(Secform, imei1p, "Edit", null);//通过类型获取第二个文本编辑框 SendMessage(sne, WM_SETTEXT, IntPtr.Zero, ms_sncode.Text); SendMessage(imeie, WM_SETTEXT, IntPtr.Zero, imei); SendMessage(imei1e, WM_SETTEXT, IntPtr.Zero, imei1); SendMessage(bte, WM_SETTEXT, IntPtr.Zero, bt); SendMessage(mace, WM_SETTEXT, IntPtr.Zero, mac); IntPtr hbuttonbox = FindWindowEx(Secform, IntPtr.Zero, null, "OK");//通过按键名称获取按键ID SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键 SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键 OperateResult.AppendText(">>序列号" + ms_sncode.Text + "写号信息已录入程序\n", Color.Green, ms_sncode); return; } } else { MessageBox.Show("没有找到窗口"); } return; } else if (mtkche1.Checked) { if (!dh.CheckExist("makesnlist", "msl_sncode = '" + ms_sncode.Text + "'")) { OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号为导入至SN清单,无法采集\n", Color.Red, ms_sncode); return; } string bt = dh.getFieldDataByCondition("makesnlist", "msl_bt", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string mac = dh.getFieldDataByCondition("makesnlist", "msl_mac", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string imei = dh.getFieldDataByCondition("makesnlist", "msl_imei", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string imei1 = dh.getFieldDataByCondition("makesnlist", "msl_imei1", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); IntPtr maindHwnd = FindWindow(null, "SN Writer V1.2020.0.0-TEE-v4360"); //获得标题外部运行程序的句柄 // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄 if (maindHwnd != IntPtr.Zero) { //Scan Data IntPtr Secform = FindWindow(null, "Scan Data"); //获得标题外部运行程序的句柄 if (Secform == IntPtr.Zero) { IntPtr hbuttonbox = FindWindowEx(maindHwnd, IntPtr.Zero, null, "Start");//通过按键名称获取按键ID SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键 SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键 Thread.Sleep(500); Secform = FindWindow(null, "Scan Data"); } if (Secform != IntPtr.Zero) { IntPtr snp = FindWindowEx(Secform, IntPtr.Zero, null, "Barcode:");//通过类型获取第一个文本编辑框 IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr btp = FindWindowEx(Secform, IntPtr.Zero, null, "BT Addr:");//通过类型获取第一个文本编辑框 IntPtr bte = FindWindowEx(Secform, btp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr macp = FindWindowEx(Secform, IntPtr.Zero, null, "Wifi Addr:");//通过类型获取第一个文本编辑框 IntPtr mace = FindWindowEx(Secform, macp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imeip = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_1:");//通过类型获取第一个文本编辑框 IntPtr imeie = FindWindowEx(Secform, imeip, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imei1p = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_2:");//通过类型获取第一个文本编辑框 IntPtr imei1e = FindWindowEx(Secform, imei1p, "Edit", null);//通过类型获取第二个文本编辑框 string qianzhui = dh.getFieldDataByCondition("product", "pr_istr", "pr_code = '" + ma_prodcode.Text + "'").ToString(); string houzhui = dh.getFieldDataByCondition("product", "pr_ostr", "pr_code = '" + ma_prodcode.Text + "'").ToString(); SendMessage(sne, WM_SETTEXT, IntPtr.Zero, qianzhui + ms_sncode.Text + houzhui); SendMessage(imeie, WM_SETTEXT, IntPtr.Zero, imei); SendMessage(imei1e, WM_SETTEXT, IntPtr.Zero, imei1); SendMessage(bte, WM_SETTEXT, IntPtr.Zero, bt); SendMessage(mace, WM_SETTEXT, IntPtr.Zero, mac); IntPtr hbuttonbox = FindWindowEx(Secform, IntPtr.Zero, null, "OK");//通过按键名称获取按键ID SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键 SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键 OperateResult.AppendText(">>序列号" + ms_sncode.Text + "写号信息已录入程序\n", Color.Green, ms_sncode); return; } } else { MessageBox.Show("没有找到窗口"); } return; } else if (zxche.Checked) { IntPtr maindHwnd = FindWindow(null, "WriteIMEI R19.18.2101"); //获得标题外部运行程序的句柄 // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄 if (maindHwnd != IntPtr.Zero) { string bt = dh.getFieldDataByCondition("makesnlist", "msl_bt", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string mac = dh.getFieldDataByCondition("makesnlist", "msl_mac", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string imei = dh.getFieldDataByCondition("makesnlist", "msl_imei", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); string imei1 = dh.getFieldDataByCondition("makesnlist", "msl_imei1", "msl_sncode = '" + ms_sncode.Text + "'").ToString(); IntPtr snp = FindWindowEx(maindHwnd, IntPtr.Zero, null, "请输入SN1:");//通过类型获取第一个文本编辑框 IntPtr sne = GetWindow(snp, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框 IntPtr btp = FindWindowEx(maindHwnd, IntPtr.Zero, null, "蓝牙地址:");//通过类型获取第一个文本编辑框 // IntPtr bte = GetWindow(btp, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框 IntPtr macp = FindWindowEx(maindHwnd, IntPtr.Zero, null, "WIFI地址:");//通过类型获取第一个文本编辑框 IntPtr mace = GetWindow(macp, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框 IntPtr imeip = FindWindowEx(maindHwnd, IntPtr.Zero, null, "设置");//通过类型获取第一个文本编辑框 //IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imeie = FindWindowEx(maindHwnd, imeip, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imei1e = FindWindowEx(maindHwnd, imeie, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr bte = FindWindowEx(maindHwnd, imei1e, "Edit", null);//通过类型获取第二个文本编辑框 SendMessage(sne, WM_SETTEXT, IntPtr.Zero, ms_sncode.Text); SendMessage(imeie, WM_SETTEXT, IntPtr.Zero, imei); SendMessage(imei1e, WM_SETTEXT, IntPtr.Zero, imei1); SendMessage(bte, WM_SETTEXT, IntPtr.Zero, bt); SendMessage(mace, WM_SETTEXT, IntPtr.Zero, mac); IntPtr hbuttonbox = FindWindowEx(maindHwnd, IntPtr.Zero, null, "写入");//通过按键名称获取按键ID SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键 SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键 zxstring = ms_sncode.Text; OperateResult.AppendText(">>序列号" + ms_sncode.Text + "写号信息已录入程序\n", Color.Green, ms_sncode); return; } else { MessageBox.Show("没有找到窗口"); } } } //if (ifrework != "0") //{ // if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0") // { // OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode); // return; // } //} //else //{ // if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0") // { // OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode); // return; // } //} } 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 (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 (AutoBadCode.Checked) //{ // string str = BaseUtil.GetDataFromDevice("DEVICES"); // str = str.Replace("LIST OF DEVICES ATTACHED", "").Replace("\n", ""); // if (!(str.Length == 0)) // { // Console.WriteLine("有链接"); // BaseUtil.GetDataFromDevice("RESET"); // } // else // { // OperateResult.AppendText(">>无设备链接,无法恢复出厂设置,采集失败\n", Color.Red, ms_sncode); // return; // } //} //良品信息采集 if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage)) { //if (WriteSoftWare.Checked) //{ // string Message = BaseUtil.GetDataFromDevice("INSTALL", SoftWarePath.Text); // OperateResult.AppendText(">>" + Message + "\n"); //} //提示正确返回时传递的信息 if (ErrorMessage.Contains("AFTERSUCCESS")) OperateResult.AppendText(">>" + ErrorMessage + "\n"); ////恢复出厂设置 //if (AutoBadCode.Checked) // BaseUtil.GetDataFromDevice("RESET"); 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,mcd_ngqty,mcd_okqty,mcd_totalng from make left join makecraftdetail_view 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) { timer1.Stop(); BaseUtil.ClosePrint(lbl); //if (engine != null) // engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); 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 NewPrint() { try { // engine = new BarTender.Application(); lbl = new ApplicationClass(); BaseUtil.WriteLbl(); } catch (Exception ex) { OperateResult.AppendText("未正确安装CodeSoft软件\n" + ex.Message, Color.Red); } } private void normalButton1_Click(object sender, EventArgs e) { } private void StartWatch_Click(object sender, EventArgs e) { if (FolderPath.Text == "") { OperateResult.AppendText("请选择监控文件夹\n"); return; } else { if (!Directory.Exists(FolderPath.Text)) { OperateResult.AppendText("监控文件夹不存在\n"); return; } } if (!mtkche.Checked && !zxche.Checked && !mtkche1.Checked) { OperateResult.AppendText(">>选择写号平台\n", Color.Red, ms_sncode); return; } XmlWatcher.Path = FolderPath.Text; if (mtkche.Checked || mtkche1.Checked) { XmlWatcher.Filter = "SN Writer.log"; } else { XmlWatcher.Filter = "*.Log"; } XmlWatcher.EnableRaisingEvents = true; //设置缓存数据 BaseUtil.SetCacheData("FolderPath", FolderPath.Text); //设置按钮不可点击 StartWatch.Enabled = false; ChooseFolder.Enabled = false; StopWatch.Enabled = true; OperateResult.AppendText("开始执行监控\n"); } private void StopWatch_Click(object sender, EventArgs e) { XmlWatcher.EnableRaisingEvents = false; StartWatch.Enabled = true; ChooseFolder.Enabled = true; StopWatch.Enabled = false; OperateResult.AppendText("停止执行监控\n"); } private void XmlWatcher_Created(object sender, FileSystemEventArgs e) { } private void ChooseFolder_Click(object sender, EventArgs e) { FolderBrowserDialog folder = new FolderBrowserDialog(); folder.Description = "选择监控文件夹"; DialogResult result = folder.ShowDialog(); if (result == DialogResult.OK) { FolderPath.Text = folder.SelectedPath; } } private void label5_Click(object sender, EventArgs e) { } private void bc_groupcode_label_Click(object sender, EventArgs e) { } private void bc_code_TextChanged(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void Filter_Load(object sender, EventArgs e) { } private void WaitRejectList_SelectedIndexChanged(object sender, EventArgs e) { } private void ChoosedRejectList_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { } private void XmlWatcher_Changed(object sender, FileSystemEventArgs e) { if (!zxche.Checked) { Stream stream = null; while (true) { try { Thread.Sleep(500); using (stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (stream != null) stream.Close(); break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Thread.Sleep(500); StreamReader _Sr = new StreamReader(e.FullPath, Encoding.UTF8); String[] strData; string line; string ssn = ""; string imei = ""; string imei1 = ""; string bt = ""; string mac = ""; Boolean ispass = false; Boolean havekey = false; try { if (mtkche.Checked) { while ((line = _Sr.ReadLine()) != null) { //if (line.Contains("Barcode[0]")) //{ // Regex regex = new Regex("\"[^\"]*\""); // ssn = regex.Match(line).Value.Replace("\"", ""); //} if (line.Contains("Prod_Info->ADBSeriaNo")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); ssn = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->IMEI[0]")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); imei = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->IMEI[1]")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); imei1 = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->BtAddress")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); bt = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->WiFiAddress")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); mac = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Check prod_info data PASS!!")) { ispass = true; } } if (ssn != "") { if (ispass) { ms_sncode.Text = ssn; ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter)); } else { OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到PASS\n", Color.Red); } //if (imei!="") //{ // dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update"); //} //if (imei1 != "") //{ // dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); //} //if (bt != "") //{ // dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); //} //if (mac != "") //{ // dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); //} } } else if (mtkche1.Checked) { while ((line = _Sr.ReadLine()) != null) { //if (line.Contains("Barcode[0]")) //{ // Regex regex = new Regex("\"[^\"]*\""); // ssn = regex.Match(line).Value.Replace("\"", ""); //} if (line.Contains("Prod_Info->Barcode")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); ssn = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->IMEI[0]")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); imei = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->IMEI[1]")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); imei1 = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->BtAddress")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); bt = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Prod_Info->WiFiAddress")) { strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('='); Regex regex = new Regex("\\[[^*]+\\]"); mac = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); } else if (line.Contains("Check prod_info data PASS!!")) { ispass = true; } else if (line.Contains("recycle drmkey ok")) { havekey = true; } } if (ssn != "") { string qianzhui = dh.getFieldDataByCondition("product", "nvl(pr_ilct,0)", "pr_code = '" + ma_prodcode.Text + "'").ToString(); string houzhui = dh.getFieldDataByCondition("product", "nvl(pr_olct,0)", "pr_code = '" + ma_prodcode.Text + "'").ToString(); ssn = ssn.Remove(0, int.Parse(qianzhui)); ssn = ssn.Substring(0, ssn.Length - int.Parse(houzhui)); if (!havekey) { OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到写KEY\n", Color.Red); } if (ispass) { ms_sncode.Text = ssn; ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter)); } else { OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到PASS\n", Color.Red); } //if (imei!="") //{ // dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update"); //} //if (imei1 != "") //{ // dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); //} //if (bt != "") //{ // dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); //} //if (mac != "") //{ // dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); //} } } //else if (zxche.Checked) //{ // while ((line = _Sr.ReadLine()) != null) // { // //if (line.Contains("Barcode[0]")) // //{ // // Regex regex = new Regex("\"[^\"]*\""); // // ssn = regex.Match(line).Value.Replace("\"", ""); // //} // if (line.Contains("WriteSN 1:")) // { // strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "").Split(']'); // //Regex regex = new Regex("\\[[^*]+\\]"); // //ssn = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", ""); // ssn = strData[1].Split(':')[1]; // } // ispass = true; // } // if (ssn != "") // { // if (ispass) // { // ms_sncode.Text = ssn; // ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter)); // } // else // { // OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到PASS\n", Color.Red); // } // //if (imei!="") // //{ // // dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update"); // //} // //if (imei1 != "") // //{ // // dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); // //} // //if (bt != "") // //{ // // dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); // //} // //if (mac != "") // //{ // // dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update"); // //} // } //} } catch (Exception ex) { MessageBox.Show(ex.Message); _Sr.Close(); } _Sr.Close(); } } private void timer1_Tick(object sender, EventArgs e) { if (zxche.Checked) { IntPtr maindHwnd = FindWindow(null, "WriteIMEI R19.18.2101"); //获得标题外部运行程序的句柄 // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄 if (maindHwnd != IntPtr.Zero) { IntPtr imeip = FindWindowEx(maindHwnd, IntPtr.Zero, null, "Simlock Config:");//通过类型获取第一个文本编辑框 //IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框 IntPtr imeie = GetWindow(imeip, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框 StringBuilder title = new StringBuilder(); // Get the size of the string required to hold the window title. Int32 size = SendMessage((int)imeie, WM_GETTEXTLENGTH, 0, 0).ToInt32(); // If the return is 0, there is no title. if (size > 0) { title = new StringBuilder(size + 1); SendMessage(imeie, (int)WM_GETTEXT, title.Capacity, title); //zxstring; if (title.ToString().Contains("Secure Provisioning Finished") && title.ToString().Contains(zxstring) && zxstring != "") { ms_sncode.Text = zxstring; zxstring = ""; ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter)); } } } } } } }