Make_SnwriteCollection.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. using System.Collections.Generic;
  11. using UAS_MES_NEW.CustomControl.PowerControlForm;
  12. using UAS_MES_NEW.PublicForm;
  13. using LabelManager2;
  14. using System.IO;
  15. using System.Text.RegularExpressions;
  16. using System.Runtime.InteropServices;
  17. namespace UAS_MES_NEW.Make
  18. {
  19. public partial class Make_SnwriteCollection : Form
  20. {
  21. DataHelper dh = null;
  22. DataTable dt = null;
  23. //当前工序的名称
  24. [DllImport("User32.dll", EntryPoint = "FindWindow")]
  25. public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
  26. [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
  27. public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
  28. [DllImport("User32.dll", EntryPoint = "SendMessage")]
  29. private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
  30. [DllImport("user32.dll", SetLastError = true)]
  31. static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
  32. [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  33. public static extern int RegisterWindowMessage(string lpString);
  34. [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = System.Runtime.InteropServices.CharSet.Auto)] //
  35. public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
  36. [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
  37. public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam,
  38. int lparam);
  39. enum GetWindow_Cmd : uint
  40. {
  41. GW_HWNDFIRST = 0,
  42. GW_HWNDLAST = 1,
  43. GW_HWNDNEXT = 2,
  44. GW_HWNDPREV = 3,
  45. GW_OWNER = 4,
  46. GW_CHILD = 5,
  47. GW_ENABLEDPOPUP = 6
  48. }
  49. //应用程序发送此消息来设置一个窗口的文本
  50. const int WM_SETTEXT = 0x0C;
  51. //应用程序发送此消息来复制对应窗口的文本到缓冲区
  52. const int WM_GETTEXT = 0x0D;
  53. const int WM_GETTEXTLENGTH = 0x000E;
  54. const int WM_LBUTTONDOWN = 0x0201;
  55. const int WM_LBUTTONUP = 0x0202;
  56. string zxstring = "";
  57. string ErrorMessage = "";
  58. //用于保存是否之前输入的ms_sncode
  59. string LastSncode;
  60. string oMakeCode = "";
  61. string oMSID = "";
  62. string ifrework = "";
  63. string reworkstatus = "";
  64. LogStringBuilder sql = new LogStringBuilder();
  65. AutoSizeFormClass asc = new AutoSizeFormClass();
  66. /// <summary>
  67. /// 已选的不良
  68. /// </summary>
  69. List<string> ChoosedList = new List<string>();
  70. /// <summary>
  71. /// 待选的不良
  72. /// </summary>
  73. List<string> WaitList = new List<string>();
  74. bool AutoCut = false;
  75. bool LockSn = false;
  76. string labelname;
  77. DataTable Dbfind;
  78. ApplicationClass lbl;
  79. Thread thread;
  80. // Document doc;
  81. public Make_SnwriteCollection()
  82. {
  83. InitializeComponent();
  84. }
  85. public void RegisterControlforMessages()
  86. {
  87. RegisterWindowMessage("WM_GETTEXT");
  88. }
  89. private void TestCollection_Load(object sender, EventArgs e)
  90. {
  91. GoodProduct.Checked = true;
  92. asc.controllInitializeSize(this);
  93. ms_sncode.Focus();
  94. //设置锁定工单
  95. LockMakeCode.GetMakeCodeCtl(ma_code);
  96. ma_code.SetLockCheckBox(LockMakeCode);
  97. ControlLockTimer.Tick += ControlLockTimer_Tick;
  98. ControlLockTimer.Interval = 100;
  99. labelname = System.Windows.Forms.Application.StartupPath + @"\badsn.lab";
  100. //thread = new Thread(NewPrint);
  101. // SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  102. //BaseUtil.SetFormCenter(stw);
  103. // stw.ShowDialog();
  104. //工单号放大镜配置
  105. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  106. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  107. ma_code.FormName = Name;
  108. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  109. ma_code.Condition = "ma_statuscode='STARTED'";
  110. ma_code.DbChange += Ma_code_DbChange;
  111. dh = SystemInf.dh;
  112. StepCount.StepCode = User.CurrentStepCode;
  113. StepCount.Source = User.UserSourceCode;
  114. StepCount.LineCode = User.UserLineCode;
  115. StepCount.Dh = dh;
  116. StepCount.Start();
  117. timer1.Start();
  118. }
  119. private void ControlLockTimer_Tick(object sender, EventArgs e)
  120. {
  121. this.Activate();
  122. ms_sncode.Focus();
  123. }
  124. private void Ma_code_DbChange(object sender, EventArgs e)
  125. {
  126. Dbfind = ma_code.ReturnData;
  127. BaseUtil.SetFormValue(this.Controls, Dbfind);
  128. LoadCollectedNum();
  129. LoadCheckQTY();
  130. }
  131. private void CleanInfo_Click(object sender, EventArgs e)
  132. {
  133. OperateResult.Clear();
  134. }
  135. private void ms_code_KeyDown(object sender, KeyEventArgs e)
  136. {
  137. if (e.KeyCode == Keys.Enter)
  138. {
  139. if (sender.ToString() != "123")
  140. {
  141. if (!mtkche.Checked && !zxche.Checked && !mtkche1.Checked)
  142. {
  143. OperateResult.AppendText(">>选择写号平台\n", Color.Red, ms_sncode);
  144. return;
  145. }
  146. }
  147. WaitList.Clear();
  148. ChoosedList.Clear();
  149. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  150. {
  151. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  152. if (!NoteAlready)
  153. {
  154. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  155. return;
  156. }
  157. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  158. {
  159. //是否提示过工单切换框,检测前后执行
  160. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  161. {
  162. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  163. return;
  164. }
  165. if (ma_code.Text != oMakeCode && oMakeCode != null)
  166. {
  167. 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");
  168. if (dt.Rows.Count > 0)
  169. {
  170. BaseUtil.SetFormValue(this.Controls, dt);
  171. LockMakeCode.Checked = true;
  172. }
  173. }
  174. 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");
  175. string status = dt.Rows[0]["ms_status"].ToString();
  176. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  177. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  178. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  179. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  180. if (sncode != ms_sncode.Text)
  181. {
  182. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  183. return;
  184. }
  185. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  186. if (GoodProduct.Checked)
  187. {
  188. if (sender.ToString() != "123")
  189. {
  190. if (mtkche.Checked)
  191. {
  192. if (!dh.CheckExist("makesnlist", "msl_sncode = '" + ms_sncode.Text + "'"))
  193. {
  194. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号为导入至SN清单,无法采集\n", Color.Red, ms_sncode);
  195. return;
  196. }
  197. string bt = dh.getFieldDataByCondition("makesnlist", "msl_bt", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  198. string mac = dh.getFieldDataByCondition("makesnlist", "msl_mac", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  199. string imei = dh.getFieldDataByCondition("makesnlist", "msl_imei", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  200. string imei1 = dh.getFieldDataByCondition("makesnlist", "msl_imei1", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  201. IntPtr maindHwnd = FindWindow(null, "SN Writer V1.2020.0.0-TEE-v4360"); //获得标题外部运行程序的句柄
  202. // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄
  203. if (maindHwnd != IntPtr.Zero)
  204. {
  205. //Scan Data
  206. IntPtr Secform = FindWindow(null, "Scan Data"); //获得标题外部运行程序的句柄
  207. if (Secform == IntPtr.Zero)
  208. {
  209. IntPtr hbuttonbox = FindWindowEx(maindHwnd, IntPtr.Zero, null, "Start");//通过按键名称获取按键ID
  210. SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键
  211. SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键
  212. Thread.Sleep(500);
  213. Secform = FindWindow(null, "Scan Data");
  214. }
  215. if (Secform != IntPtr.Zero)
  216. {
  217. IntPtr snp = FindWindowEx(Secform, IntPtr.Zero, null, "SerialNo.:");//通过类型获取第一个文本编辑框
  218. IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框
  219. IntPtr btp = FindWindowEx(Secform, IntPtr.Zero, null, "BT Addr:");//通过类型获取第一个文本编辑框
  220. IntPtr bte = FindWindowEx(Secform, btp, "Edit", null);//通过类型获取第二个文本编辑框
  221. IntPtr macp = FindWindowEx(Secform, IntPtr.Zero, null, "Wifi Addr:");//通过类型获取第一个文本编辑框
  222. IntPtr mace = FindWindowEx(Secform, macp, "Edit", null);//通过类型获取第二个文本编辑框
  223. IntPtr imeip = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_1:");//通过类型获取第一个文本编辑框
  224. IntPtr imeie = FindWindowEx(Secform, imeip, "Edit", null);//通过类型获取第二个文本编辑框
  225. IntPtr imei1p = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_2:");//通过类型获取第一个文本编辑框
  226. IntPtr imei1e = FindWindowEx(Secform, imei1p, "Edit", null);//通过类型获取第二个文本编辑框
  227. SendMessage(sne, WM_SETTEXT, IntPtr.Zero, ms_sncode.Text);
  228. SendMessage(imeie, WM_SETTEXT, IntPtr.Zero, imei);
  229. SendMessage(imei1e, WM_SETTEXT, IntPtr.Zero, imei1);
  230. SendMessage(bte, WM_SETTEXT, IntPtr.Zero, bt);
  231. SendMessage(mace, WM_SETTEXT, IntPtr.Zero, mac);
  232. IntPtr hbuttonbox = FindWindowEx(Secform, IntPtr.Zero, null, "OK");//通过按键名称获取按键ID
  233. SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键
  234. SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键
  235. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "写号信息已录入程序\n", Color.Green, ms_sncode);
  236. return;
  237. }
  238. }
  239. else
  240. {
  241. MessageBox.Show("没有找到窗口");
  242. }
  243. return;
  244. }
  245. else if (mtkche1.Checked)
  246. {
  247. if (!dh.CheckExist("makesnlist", "msl_sncode = '" + ms_sncode.Text + "'"))
  248. {
  249. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号为导入至SN清单,无法采集\n", Color.Red, ms_sncode);
  250. return;
  251. }
  252. string bt = dh.getFieldDataByCondition("makesnlist", "msl_bt", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  253. string mac = dh.getFieldDataByCondition("makesnlist", "msl_mac", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  254. string imei = dh.getFieldDataByCondition("makesnlist", "msl_imei", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  255. string imei1 = dh.getFieldDataByCondition("makesnlist", "msl_imei1", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  256. IntPtr maindHwnd = FindWindow(null, "SN Writer V1.2020.0.0-TEE-v4360"); //获得标题外部运行程序的句柄
  257. // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄
  258. if (maindHwnd != IntPtr.Zero)
  259. {
  260. //Scan Data
  261. IntPtr Secform = FindWindow(null, "Scan Data"); //获得标题外部运行程序的句柄
  262. if (Secform == IntPtr.Zero)
  263. {
  264. IntPtr hbuttonbox = FindWindowEx(maindHwnd, IntPtr.Zero, null, "Start");//通过按键名称获取按键ID
  265. SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键
  266. SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键
  267. Thread.Sleep(500);
  268. Secform = FindWindow(null, "Scan Data");
  269. }
  270. if (Secform != IntPtr.Zero)
  271. {
  272. IntPtr snp = FindWindowEx(Secform, IntPtr.Zero, null, "Barcode:");//通过类型获取第一个文本编辑框
  273. IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框
  274. IntPtr btp = FindWindowEx(Secform, IntPtr.Zero, null, "BT Addr:");//通过类型获取第一个文本编辑框
  275. IntPtr bte = FindWindowEx(Secform, btp, "Edit", null);//通过类型获取第二个文本编辑框
  276. IntPtr macp = FindWindowEx(Secform, IntPtr.Zero, null, "Wifi Addr:");//通过类型获取第一个文本编辑框
  277. IntPtr mace = FindWindowEx(Secform, macp, "Edit", null);//通过类型获取第二个文本编辑框
  278. IntPtr imeip = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_1:");//通过类型获取第一个文本编辑框
  279. IntPtr imeie = FindWindowEx(Secform, imeip, "Edit", null);//通过类型获取第二个文本编辑框
  280. IntPtr imei1p = FindWindowEx(Secform, IntPtr.Zero, null, "IMEI_2:");//通过类型获取第一个文本编辑框
  281. IntPtr imei1e = FindWindowEx(Secform, imei1p, "Edit", null);//通过类型获取第二个文本编辑框
  282. string qianzhui = dh.getFieldDataByCondition("product", "pr_istr", "pr_code = '" + ma_prodcode.Text + "'").ToString();
  283. string houzhui = dh.getFieldDataByCondition("product", "pr_ostr", "pr_code = '" + ma_prodcode.Text + "'").ToString();
  284. SendMessage(sne, WM_SETTEXT, IntPtr.Zero, qianzhui + ms_sncode.Text + houzhui);
  285. SendMessage(imeie, WM_SETTEXT, IntPtr.Zero, imei);
  286. SendMessage(imei1e, WM_SETTEXT, IntPtr.Zero, imei1);
  287. SendMessage(bte, WM_SETTEXT, IntPtr.Zero, bt);
  288. SendMessage(mace, WM_SETTEXT, IntPtr.Zero, mac);
  289. IntPtr hbuttonbox = FindWindowEx(Secform, IntPtr.Zero, null, "OK");//通过按键名称获取按键ID
  290. SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键
  291. SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键
  292. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "写号信息已录入程序\n", Color.Green, ms_sncode);
  293. return;
  294. }
  295. }
  296. else
  297. {
  298. MessageBox.Show("没有找到窗口");
  299. }
  300. return;
  301. }
  302. else if (zxche.Checked)
  303. {
  304. IntPtr maindHwnd = FindWindow(null, "WriteIMEI R19.18.2101"); //获得标题外部运行程序的句柄
  305. // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄
  306. if (maindHwnd != IntPtr.Zero)
  307. {
  308. string bt = dh.getFieldDataByCondition("makesnlist", "msl_bt", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  309. string mac = dh.getFieldDataByCondition("makesnlist", "msl_mac", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  310. string imei = dh.getFieldDataByCondition("makesnlist", "msl_imei", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  311. string imei1 = dh.getFieldDataByCondition("makesnlist", "msl_imei1", "msl_sncode = '" + ms_sncode.Text + "'").ToString();
  312. IntPtr snp = FindWindowEx(maindHwnd, IntPtr.Zero, null, "请输入SN1:");//通过类型获取第一个文本编辑框
  313. IntPtr sne = GetWindow(snp, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框
  314. IntPtr btp = FindWindowEx(maindHwnd, IntPtr.Zero, null, "蓝牙地址:");//通过类型获取第一个文本编辑框
  315. // IntPtr bte = GetWindow(btp, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框
  316. IntPtr macp = FindWindowEx(maindHwnd, IntPtr.Zero, null, "WIFI地址:");//通过类型获取第一个文本编辑框
  317. IntPtr mace = GetWindow(macp, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框
  318. IntPtr imeip = FindWindowEx(maindHwnd, IntPtr.Zero, null, "设置");//通过类型获取第一个文本编辑框
  319. //IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框
  320. IntPtr imeie = FindWindowEx(maindHwnd, imeip, "Edit", null);//通过类型获取第二个文本编辑框
  321. IntPtr imei1e = FindWindowEx(maindHwnd, imeie, "Edit", null);//通过类型获取第二个文本编辑框
  322. IntPtr bte = FindWindowEx(maindHwnd, imei1e, "Edit", null);//通过类型获取第二个文本编辑框
  323. SendMessage(sne, WM_SETTEXT, IntPtr.Zero, ms_sncode.Text);
  324. SendMessage(imeie, WM_SETTEXT, IntPtr.Zero, imei);
  325. SendMessage(imei1e, WM_SETTEXT, IntPtr.Zero, imei1);
  326. SendMessage(bte, WM_SETTEXT, IntPtr.Zero, bt);
  327. SendMessage(mace, WM_SETTEXT, IntPtr.Zero, mac);
  328. IntPtr hbuttonbox = FindWindowEx(maindHwnd, IntPtr.Zero, null, "写入");//通过按键名称获取按键ID
  329. SendMessage(hbuttonbox, WM_LBUTTONDOWN, IntPtr.Zero, null);//按下鼠标左键
  330. SendMessage(hbuttonbox, WM_LBUTTONUP, IntPtr.Zero, null);//抬起鼠标左键
  331. zxstring = ms_sncode.Text;
  332. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "写号信息已录入程序\n", Color.Green, ms_sncode);
  333. return;
  334. }
  335. else
  336. {
  337. MessageBox.Show("没有找到窗口");
  338. }
  339. }
  340. }
  341. //if (ifrework != "0")
  342. //{
  343. // if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
  344. // {
  345. // OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  346. // return;
  347. // }
  348. //}
  349. //else
  350. //{
  351. // if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
  352. // {
  353. // OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  354. // return;
  355. // }
  356. //}
  357. }
  358. SetCollectResult();
  359. }
  360. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  361. }
  362. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  363. }
  364. }
  365. /// <summary>
  366. /// 设置良品或者不良品的采集结果
  367. /// </summary>
  368. private void SetCollectResult()
  369. {
  370. string ErrorMessage = "";
  371. if (GoodProduct.Checked)
  372. {
  373. //如果不是返修的
  374. if (ifrework == "0")
  375. {
  376. 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");
  377. for (int i = 0; i < dt.Rows.Count; i++)
  378. {
  379. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  380. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  381. }
  382. //存在不良记录
  383. if (ErrorMessage != "")
  384. {
  385. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  386. return;
  387. }
  388. else
  389. {
  390. //if (AutoBadCode.Checked)
  391. //{
  392. // string str = BaseUtil.GetDataFromDevice("DEVICES");
  393. // str = str.Replace("LIST OF DEVICES ATTACHED", "").Replace("\n", "");
  394. // if (!(str.Length == 0))
  395. // {
  396. // Console.WriteLine("有链接");
  397. // BaseUtil.GetDataFromDevice("RESET");
  398. // }
  399. // else
  400. // {
  401. // OperateResult.AppendText(">>无设备链接,无法恢复出厂设置,采集失败\n", Color.Red, ms_sncode);
  402. // return;
  403. // }
  404. //}
  405. //良品信息采集
  406. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  407. {
  408. //if (WriteSoftWare.Checked)
  409. //{
  410. // string Message = BaseUtil.GetDataFromDevice("INSTALL", SoftWarePath.Text);
  411. // OperateResult.AppendText(">>" + Message + "\n");
  412. //}
  413. //提示正确返回时传递的信息
  414. if (ErrorMessage.Contains("AFTERSUCCESS"))
  415. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  416. ////恢复出厂设置
  417. //if (AutoBadCode.Checked)
  418. // BaseUtil.GetDataFromDevice("RESET");
  419. LastSncode = ms_sncode.Text;
  420. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
  421. //记录操作日志
  422. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  423. }
  424. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  425. }
  426. }
  427. else
  428. {
  429. if (reworkstatus != "3")
  430. {
  431. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  432. {
  433. //提示正确返回时传递的信息
  434. if (ErrorMessage.Contains("AFTERSUCCESS"))
  435. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  436. LastSncode = ms_sncode.Text;
  437. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
  438. //记录操作日志
  439. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  440. }
  441. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  442. }
  443. else
  444. {
  445. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  446. }
  447. }
  448. }
  449. //加载页面信息
  450. LoadCollectedNum();
  451. LoadCheckQTY();
  452. }
  453. private void 测试采集_SizeChanged(object sender, EventArgs e)
  454. {
  455. asc.controlAutoSize(this);
  456. }
  457. private void LoadCollectedNum()
  458. {
  459. 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");
  460. BaseUtil.SetFormValue(Controls, dt);
  461. }
  462. private void Save_Click(object sender, EventArgs e)
  463. {
  464. if (ms_sncode.Text == "")
  465. {
  466. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  467. return;
  468. }
  469. if (GoodProduct.Checked)
  470. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  471. }
  472. private void LoadCheckQTY()
  473. {
  474. sql.Clear();
  475. string condition = "";
  476. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  477. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  478. if (nowcheckqty + 1 == batchqty && AutoCut)
  479. {
  480. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  481. }
  482. else
  483. {
  484. condition = "and ob_status='ENTERING' ";
  485. }
  486. if (pr_sendchecktype.Text == "SaleCode")
  487. {
  488. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  489. }
  490. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  491. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  492. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  493. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  494. if (dt.Rows.Count > 0)
  495. {
  496. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  497. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  498. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  499. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  500. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  501. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  502. if (nowcheckqty == batchqty)
  503. {
  504. ob_nowcheckqty.ForeColor = Color.Red;
  505. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  506. if (AutoCut)
  507. {
  508. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Blue);
  509. }
  510. }
  511. }
  512. else
  513. {
  514. BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno);
  515. SendCheck.Enabled = false;
  516. }
  517. if (ob_batchqty.Text != "")
  518. {
  519. SendCheck.Enabled = true;
  520. }
  521. else
  522. {
  523. SendCheck.Enabled = false;
  524. }
  525. }
  526. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  527. {
  528. if (GoodProduct.Checked)
  529. {
  530. Save.Visible = false;
  531. }
  532. else
  533. {
  534. Save.Visible = true;
  535. }
  536. if (ms_sncode.Text == "")
  537. {
  538. ms_sncode.Focus();
  539. }
  540. }
  541. private void SendCheck_Click(object sender, EventArgs e)
  542. {
  543. sql.Clear();
  544. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  545. dh.ExecuteSql(sql.GetString(), "select");
  546. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  547. ob_nowcheckqty.Text = "";
  548. ob_batchqty.Text = "";
  549. ob_nowcheckqty.ForeColor = Color.Black;
  550. SendCheck.Enabled = false;
  551. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue);
  552. ms_sncode.Focus();
  553. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  554. //记录操作日志
  555. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  556. ob_checkno.Text = "";
  557. }
  558. private void ob_checkno_TextChanged(object sender, EventArgs e)
  559. {
  560. if (ob_checkno.Text != "")
  561. {
  562. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  563. if (Cut == "" || Cut == "0")
  564. AutoCut = false;
  565. else
  566. AutoCut = true;
  567. SendCheck.Enabled = true;
  568. }
  569. }
  570. /// <summary>
  571. /// 工单变化修改数量
  572. /// </summary>
  573. /// <param name="sender"></param>
  574. /// <param name="e"></param>
  575. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  576. {
  577. if (ma_code.Text.Length > 4)
  578. {
  579. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty);
  580. LoadCollectedNum();
  581. LoadCheckQTY();
  582. }
  583. }
  584. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  585. {
  586. timer1.Stop();
  587. BaseUtil.ClosePrint(lbl);
  588. //if (engine != null)
  589. // engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  590. dh.Dispose();
  591. }
  592. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  593. {
  594. }
  595. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  596. {
  597. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  598. {
  599. if (!LockSn)
  600. {
  601. ControlLockTimer.Start();
  602. LockSn = true;
  603. Lock_label.Visible = true;
  604. }
  605. else
  606. {
  607. ControlLockTimer.Stop();
  608. LockSn = false;
  609. Lock_label.Visible = false;
  610. }
  611. }
  612. }
  613. //创建打印进程
  614. private void NewPrint()
  615. {
  616. try
  617. {
  618. // engine = new BarTender.Application();
  619. lbl = new ApplicationClass();
  620. BaseUtil.WriteLbl();
  621. }
  622. catch (Exception ex)
  623. {
  624. OperateResult.AppendText("未正确安装CodeSoft软件\n" + ex.Message, Color.Red);
  625. }
  626. }
  627. private void normalButton1_Click(object sender, EventArgs e)
  628. {
  629. }
  630. private void StartWatch_Click(object sender, EventArgs e)
  631. {
  632. if (FolderPath.Text == "")
  633. {
  634. OperateResult.AppendText("请选择监控文件夹\n");
  635. return;
  636. }
  637. else
  638. {
  639. if (!Directory.Exists(FolderPath.Text))
  640. {
  641. OperateResult.AppendText("监控文件夹不存在\n");
  642. return;
  643. }
  644. }
  645. if (!mtkche.Checked && !zxche.Checked && !mtkche1.Checked)
  646. {
  647. OperateResult.AppendText(">>选择写号平台\n", Color.Red, ms_sncode);
  648. return;
  649. }
  650. XmlWatcher.Path = FolderPath.Text;
  651. if (mtkche.Checked || mtkche1.Checked)
  652. {
  653. XmlWatcher.Filter = "SN Writer.log";
  654. }
  655. else {
  656. XmlWatcher.Filter = "*.Log";
  657. }
  658. XmlWatcher.EnableRaisingEvents = true;
  659. //设置缓存数据
  660. BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
  661. //设置按钮不可点击
  662. StartWatch.Enabled = false;
  663. ChooseFolder.Enabled = false;
  664. StopWatch.Enabled = true;
  665. OperateResult.AppendText("开始执行监控\n");
  666. }
  667. private void StopWatch_Click(object sender, EventArgs e)
  668. {
  669. XmlWatcher.EnableRaisingEvents = false;
  670. StartWatch.Enabled = true;
  671. ChooseFolder.Enabled = true;
  672. StopWatch.Enabled = false;
  673. OperateResult.AppendText("停止执行监控\n");
  674. }
  675. private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
  676. {
  677. }
  678. private void ChooseFolder_Click(object sender, EventArgs e)
  679. {
  680. FolderBrowserDialog folder = new FolderBrowserDialog();
  681. folder.Description = "选择监控文件夹";
  682. DialogResult result = folder.ShowDialog();
  683. if (result == DialogResult.OK)
  684. {
  685. FolderPath.Text = folder.SelectedPath;
  686. }
  687. }
  688. private void label5_Click(object sender, EventArgs e)
  689. {
  690. }
  691. private void bc_groupcode_label_Click(object sender, EventArgs e)
  692. {
  693. }
  694. private void bc_code_TextChanged(object sender, EventArgs e)
  695. {
  696. }
  697. private void label3_Click(object sender, EventArgs e)
  698. {
  699. }
  700. private void label4_Click(object sender, EventArgs e)
  701. {
  702. }
  703. private void Filter_Load(object sender, EventArgs e)
  704. {
  705. }
  706. private void WaitRejectList_SelectedIndexChanged(object sender, EventArgs e)
  707. {
  708. }
  709. private void ChoosedRejectList_SelectedIndexChanged(object sender, EventArgs e)
  710. {
  711. }
  712. private void button1_Click(object sender, EventArgs e)
  713. {
  714. }
  715. private void XmlWatcher_Changed(object sender, FileSystemEventArgs e)
  716. {
  717. if (!zxche.Checked)
  718. {
  719. Stream stream = null;
  720. while (true)
  721. {
  722. try
  723. {
  724. Thread.Sleep(500);
  725. using (stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
  726. {
  727. if (stream != null)
  728. stream.Close();
  729. break;
  730. }
  731. }
  732. catch (Exception ex)
  733. {
  734. Console.WriteLine(ex.Message);
  735. }
  736. }
  737. Thread.Sleep(500);
  738. StreamReader _Sr = new StreamReader(e.FullPath, Encoding.UTF8);
  739. String[] strData;
  740. string line;
  741. string ssn = "";
  742. string imei = "";
  743. string imei1 = "";
  744. string bt = "";
  745. string mac = "";
  746. Boolean ispass = false;
  747. Boolean havekey = false;
  748. try
  749. {
  750. if (mtkche.Checked)
  751. {
  752. while ((line = _Sr.ReadLine()) != null)
  753. {
  754. //if (line.Contains("Barcode[0]"))
  755. //{
  756. // Regex regex = new Regex("\"[^\"]*\"");
  757. // ssn = regex.Match(line).Value.Replace("\"", "");
  758. //}
  759. if (line.Contains("Prod_Info->ADBSeriaNo"))
  760. {
  761. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  762. Regex regex = new Regex("\\[[^*]+\\]");
  763. ssn = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  764. }
  765. else if (line.Contains("Prod_Info->IMEI[0]"))
  766. {
  767. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  768. Regex regex = new Regex("\\[[^*]+\\]");
  769. imei = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  770. }
  771. else if (line.Contains("Prod_Info->IMEI[1]"))
  772. {
  773. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  774. Regex regex = new Regex("\\[[^*]+\\]");
  775. imei1 = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  776. }
  777. else if (line.Contains("Prod_Info->BtAddress"))
  778. {
  779. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  780. Regex regex = new Regex("\\[[^*]+\\]");
  781. bt = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  782. }
  783. else if (line.Contains("Prod_Info->WiFiAddress"))
  784. {
  785. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  786. Regex regex = new Regex("\\[[^*]+\\]");
  787. mac = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  788. }
  789. else if (line.Contains("Check prod_info data PASS!!"))
  790. {
  791. ispass = true;
  792. }
  793. }
  794. if (ssn != "")
  795. {
  796. if (ispass)
  797. {
  798. ms_sncode.Text = ssn;
  799. ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter));
  800. }
  801. else
  802. {
  803. OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到PASS\n", Color.Red);
  804. }
  805. //if (imei!="")
  806. //{
  807. // dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update");
  808. //}
  809. //if (imei1 != "")
  810. //{
  811. // dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  812. //}
  813. //if (bt != "")
  814. //{
  815. // dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  816. //}
  817. //if (mac != "")
  818. //{
  819. // dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  820. //}
  821. }
  822. }
  823. else if (mtkche1.Checked)
  824. {
  825. while ((line = _Sr.ReadLine()) != null)
  826. {
  827. //if (line.Contains("Barcode[0]"))
  828. //{
  829. // Regex regex = new Regex("\"[^\"]*\"");
  830. // ssn = regex.Match(line).Value.Replace("\"", "");
  831. //}
  832. if (line.Contains("Prod_Info->Barcode"))
  833. {
  834. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  835. Regex regex = new Regex("\\[[^*]+\\]");
  836. ssn = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  837. }
  838. else if (line.Contains("Prod_Info->IMEI[0]"))
  839. {
  840. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  841. Regex regex = new Regex("\\[[^*]+\\]");
  842. imei = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  843. }
  844. else if (line.Contains("Prod_Info->IMEI[1]"))
  845. {
  846. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  847. Regex regex = new Regex("\\[[^*]+\\]");
  848. imei1 = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  849. }
  850. else if (line.Contains("Prod_Info->BtAddress"))
  851. {
  852. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  853. Regex regex = new Regex("\\[[^*]+\\]");
  854. bt = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  855. }
  856. else if (line.Contains("Prod_Info->WiFiAddress"))
  857. {
  858. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  859. Regex regex = new Regex("\\[[^*]+\\]");
  860. mac = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  861. }
  862. else if (line.Contains("Check prod_info data PASS!!"))
  863. {
  864. ispass = true;
  865. }
  866. else if (line.Contains("recycle drmkey ok"))
  867. {
  868. havekey = true;
  869. }
  870. }
  871. if (ssn != "")
  872. {
  873. string qianzhui = dh.getFieldDataByCondition("product", "nvl(pr_ilct,0)", "pr_code = '" + ma_prodcode.Text + "'").ToString();
  874. string houzhui = dh.getFieldDataByCondition("product", "nvl(pr_olct,0)", "pr_code = '" + ma_prodcode.Text + "'").ToString();
  875. ssn = ssn.Remove(0, int.Parse(qianzhui));
  876. ssn = ssn.Substring(0, ssn.Length - int.Parse(houzhui));
  877. if (!havekey)
  878. {
  879. OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到写KEY\n", Color.Red);
  880. }
  881. if (ispass)
  882. {
  883. ms_sncode.Text = ssn;
  884. ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter));
  885. }
  886. else
  887. {
  888. OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到PASS\n", Color.Red);
  889. }
  890. //if (imei!="")
  891. //{
  892. // dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update");
  893. //}
  894. //if (imei1 != "")
  895. //{
  896. // dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  897. //}
  898. //if (bt != "")
  899. //{
  900. // dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  901. //}
  902. //if (mac != "")
  903. //{
  904. // dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  905. //}
  906. }
  907. }
  908. //else if (zxche.Checked)
  909. //{
  910. // while ((line = _Sr.ReadLine()) != null)
  911. // {
  912. // //if (line.Contains("Barcode[0]"))
  913. // //{
  914. // // Regex regex = new Regex("\"[^\"]*\"");
  915. // // ssn = regex.Match(line).Value.Replace("\"", "");
  916. // //}
  917. // if (line.Contains("WriteSN 1:"))
  918. // {
  919. // strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "").Split(']');
  920. // //Regex regex = new Regex("\\[[^*]+\\]");
  921. // //ssn = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  922. // ssn = strData[1].Split(':')[1];
  923. // }
  924. // ispass = true;
  925. // }
  926. // if (ssn != "")
  927. // {
  928. // if (ispass)
  929. // {
  930. // ms_sncode.Text = ssn;
  931. // ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter));
  932. // }
  933. // else
  934. // {
  935. // OperateResult.AppendText(">>" + ssn + " SNWRITE未检测到PASS\n", Color.Red);
  936. // }
  937. // //if (imei!="")
  938. // //{
  939. // // dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update");
  940. // //}
  941. // //if (imei1 != "")
  942. // //{
  943. // // dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  944. // //}
  945. // //if (bt != "")
  946. // //{
  947. // // dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  948. // //}
  949. // //if (mac != "")
  950. // //{
  951. // // dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  952. // //}
  953. // }
  954. //}
  955. }
  956. catch (Exception ex)
  957. {
  958. MessageBox.Show(ex.Message);
  959. _Sr.Close();
  960. }
  961. _Sr.Close();
  962. }
  963. }
  964. private void timer1_Tick(object sender, EventArgs e)
  965. {
  966. if (zxche.Checked)
  967. {
  968. IntPtr maindHwnd = FindWindow(null, "WriteIMEI R19.18.2101"); //获得标题外部运行程序的句柄
  969. // IntPtr maindHwnd = p1.MainWindowHandle;//通过进程获取句柄
  970. if (maindHwnd != IntPtr.Zero)
  971. {
  972. IntPtr imeip = FindWindowEx(maindHwnd, IntPtr.Zero, null, "Simlock Config:");//通过类型获取第一个文本编辑框
  973. //IntPtr sne = FindWindowEx(Secform, snp, "Edit", null);//通过类型获取第二个文本编辑框
  974. IntPtr imeie = GetWindow(imeip, (int)GetWindow_Cmd.GW_HWNDPREV);//通过类型获取第二个文本编辑框
  975. StringBuilder title = new StringBuilder();
  976. // Get the size of the string required to hold the window title.
  977. Int32 size = SendMessage((int)imeie, WM_GETTEXTLENGTH, 0, 0).ToInt32();
  978. // If the return is 0, there is no title.
  979. if (size > 0)
  980. {
  981. title = new StringBuilder(size + 1);
  982. SendMessage(imeie, (int)WM_GETTEXT, title.Capacity, title);
  983. //zxstring;
  984. if (title.ToString().Contains("Secure Provisioning Finished") && title.ToString().Contains(zxstring) && zxstring != "")
  985. {
  986. ms_sncode.Text = zxstring;
  987. zxstring = "";
  988. ms_code_KeyDown("123", new KeyEventArgs(Keys.Enter));
  989. }
  990. }
  991. }
  992. }
  993. }
  994. }
  995. }