Make_TestCollection.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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. namespace UAS_MES_NEW.Make
  17. {
  18. public partial class Make_TestCollection : Form
  19. {
  20. DataHelper dh = null;
  21. DataTable dt = null;
  22. //当前工序的名称
  23. string ErrorMessage = "";
  24. //用于保存是否之前输入的ms_sncode
  25. string LastSncode;
  26. string oMakeCode = "";
  27. string oMSID = "";
  28. string ifrework = "";
  29. string reworkstatus = "";
  30. LogStringBuilder sql = new LogStringBuilder();
  31. AutoSizeFormClass asc = new AutoSizeFormClass();
  32. /// <summary>
  33. /// 已选的不良
  34. /// </summary>
  35. List<string> ChoosedList = new List<string>();
  36. /// <summary>
  37. /// 待选的不良
  38. /// </summary>
  39. List<string> WaitList = new List<string>();
  40. bool AutoCut = false;
  41. bool LockSn = false;
  42. string labelname;
  43. DataTable Dbfind;
  44. ApplicationClass lbl;
  45. Thread thread;
  46. // Document doc;
  47. public Make_TestCollection()
  48. {
  49. InitializeComponent();
  50. }
  51. private void TestCollection_Load(object sender, EventArgs e)
  52. {
  53. GoodProduct.Checked = true;
  54. asc.controllInitializeSize(this);
  55. ms_sncode.Focus();
  56. //设置锁定工单
  57. LockMakeCode.GetMakeCodeCtl(ma_code);
  58. ma_code.SetLockCheckBox(LockMakeCode);
  59. ControlLockTimer.Tick += ControlLockTimer_Tick;
  60. ControlLockTimer.Interval = 100;
  61. labelname = System.Windows.Forms.Application.StartupPath + @"\badsn.lab";
  62. //thread = new Thread(NewPrint);
  63. // SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  64. //BaseUtil.SetFormCenter(stw);
  65. // stw.ShowDialog();
  66. //工单号放大镜配置
  67. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  68. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量, pr_orispeccode # 型号, ma_wccode # 车间,ma_inqty # 投入数,pr_spec # 产品规格,ma_endremark # 客户代码";
  69. ma_code.FormName = Name;
  70. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_orispeccode pr_spec", "ma_endremark" };
  71. ma_code.Condition = "ma_statuscode='STARTED' order by ma_date desc";
  72. ma_code.DbChange += Ma_code_DbChange;
  73. dh = SystemInf.dh;
  74. StepCount.StepCode = User.CurrentStepCode;
  75. StepCount.Source = User.UserSourceCode;
  76. StepCount.LineCode = User.UserLineCode;
  77. StepCount.Dh = dh;
  78. StepCount.Start();
  79. }
  80. private void ControlLockTimer_Tick(object sender, EventArgs e)
  81. {
  82. this.Activate();
  83. ms_sncode.Focus();
  84. }
  85. private void Ma_code_DbChange(object sender, EventArgs e)
  86. {
  87. Dbfind = ma_code.ReturnData;
  88. BaseUtil.SetFormValue(this.Controls, Dbfind);
  89. LoadBadGroupData();
  90. LoadCollectedNum();
  91. LoadCheckQTY();
  92. }
  93. /// <summary>
  94. /// 将已选不良移动到待选不良
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void WaitReject_Click(object sender, EventArgs e)
  99. {
  100. int CheckedNum = 0;
  101. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  102. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  103. {
  104. if (ChoosedRejectList.Items[i].Checked)
  105. {
  106. ChoosedRejectList.Items[i].Checked = false;
  107. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  108. ChoosedRejectList.Items[i].Remove();
  109. CheckedNum++;
  110. }
  111. }
  112. if (CheckedNum == 0)
  113. {
  114. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  115. {
  116. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  117. ChoosedRejectList.Items[i].Remove();
  118. }
  119. }
  120. }
  121. /// <summary>
  122. /// 将不良信息移动到已选不良
  123. /// </summary>
  124. /// <param name="sender"></param>
  125. /// <param name="e"></param>
  126. private void ChooseedReject_Click(object sender, EventArgs e)
  127. {
  128. if (ms_sncode.Text == "")
  129. {
  130. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  131. ms_sncode.Focus();
  132. return;
  133. }
  134. int CheckedNum = 0;
  135. //是否已经添加到不良
  136. bool AddToReject = false;
  137. if (ChoosedRejectList.Items.Count > 0)
  138. {
  139. OperateResult.AppendText(">>只可采集一个不良现象\n", Color.Red);
  140. return;
  141. }
  142. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  143. {
  144. if (WaitRejectList.Items[i].Checked)
  145. {
  146. AddToReject = false;
  147. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  148. {
  149. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  150. {
  151. AddToReject = true;
  152. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  153. break;
  154. }
  155. }
  156. //未添加则进行添加
  157. if (!AddToReject)
  158. {
  159. WaitRejectList.Items[i].Checked = false;
  160. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  161. WaitRejectList.Items[i].Remove();
  162. CheckedNum++;
  163. break;
  164. }
  165. }
  166. }
  167. if (CheckedNum == 0)
  168. {
  169. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  170. }
  171. }
  172. private void CleanInfo_Click(object sender, EventArgs e)
  173. {
  174. OperateResult.Clear();
  175. }
  176. private void ms_code_KeyDown(object sender, KeyEventArgs e)
  177. {
  178. if (e.KeyCode == Keys.Enter)
  179. {
  180. if (ms_sncode.Text.Contains("EMPLOYEE:"))
  181. {
  182. biduisn.Text = ms_sncode.Text.Split(':')[1];
  183. OperateResult.AppendText(">>采集人员编号"+ biduisn.Text+"\n", Color.Green, ms_sncode);
  184. return;
  185. }
  186. if (ms_sncode.Text.Contains("CHANGE:"))
  187. {
  188. GoodProduct.Checked = !GoodProduct.Checked;
  189. Reject.Checked = !GoodProduct.Checked;
  190. OperateResult.AppendText(">>切换良品不良采集\n", Color.Black, ms_sncode);
  191. return;
  192. }
  193. if (bidui.Checked && biduisn.Text =="")
  194. {
  195. OperateResult.AppendText(">>勾选人员采集需先采集人员\n", Color.Red, ms_sncode);
  196. return;
  197. }
  198. ChoosedRejectList.Items.Clear();
  199. WaitList.Clear();
  200. ChoosedList.Clear();
  201. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  202. {
  203. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  204. if (!NoteAlready)
  205. {
  206. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  207. return;
  208. }
  209. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  210. {
  211. //是否提示过工单切换框,检测前后执行
  212. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  213. {
  214. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  215. return;
  216. }
  217. if (ma_code.Text != oMakeCode && oMakeCode != null)
  218. {
  219. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_orispeccode pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty,ma_endremark from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  220. if (dt.Rows.Count > 0)
  221. {
  222. BaseUtil.SetFormValue(this.Controls, dt);
  223. LockMakeCode.Checked = true;
  224. }
  225. }
  226. 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");
  227. string status = dt.Rows[0]["ms_status"].ToString();
  228. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  229. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  230. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  231. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  232. if (sncode != ms_sncode.Text)
  233. {
  234. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  235. return;
  236. }
  237. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  238. if (GoodProduct.Checked)
  239. {
  240. if (ifrework != "0")
  241. {
  242. if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
  243. {
  244. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  245. return;
  246. }
  247. }
  248. else
  249. {
  250. if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
  251. {
  252. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  253. return;
  254. }
  255. }
  256. }
  257. SetCollectResult();
  258. }
  259. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode, oth);
  260. }
  261. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode, oth);
  262. }
  263. }
  264. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  265. {
  266. LoadBadCodeListView();
  267. }
  268. /// <summary>
  269. /// 填充不良组别信息
  270. /// </summary>
  271. private void LoadBadGroupData()
  272. {
  273. //如果ms_makecode的值修改过再去查询
  274. sql.Clear();
  275. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  276. sql.Append("from product left join productkind on pk_name=pr_kind ");
  277. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  278. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  279. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  280. bc_groupcode.DisplayMember = "bg_name";
  281. bc_groupcode.ValueMember = "bg_code";
  282. bc_groupcode.DataSource = dt;
  283. }
  284. /// <summary>
  285. /// 加载不良代码的ListView的信息
  286. /// </summary>
  287. private void LoadBadCodeListView()
  288. {
  289. object bg_code = bc_groupcode.SelectedValue;
  290. sql.Clear();
  291. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  292. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  293. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  294. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  295. BadInfSource.DataSource = dt;
  296. //往listview中添加数据
  297. WaitRejectList.Items.Clear();
  298. WaitRejectList.BeginUpdate();
  299. for (int i = 0; i < dt.Rows.Count; i++)
  300. {
  301. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  302. {
  303. ListViewItem lvi = new ListViewItem();
  304. //第一列是勾选列,设置列头文本为空
  305. lvi.Text = "";
  306. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  307. for (int j = 0; j < dt.Columns.Count; j++)
  308. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  309. WaitRejectList.Items.Add(lvi);
  310. }
  311. }
  312. WaitRejectList.EndUpdate();
  313. }
  314. /// <summary>
  315. /// 加载已选不良的ListView
  316. /// </summary>
  317. private void LoadChoosedBadListView()
  318. {
  319. sql.Clear();
  320. sql.Append("select nvl(bg_code,mb_bgcode)||':'||nvl(bg_name,mb_badcode) bg_code,nvl(mb_badcode,bc_code) bc_code,bc_name,mb_badremark from makebad ");
  321. sql.Append("left join badgroup on mb_bgcode=bg_code left join badcode on mb_badcode=bc_code ");
  322. sql.Append(" where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0");
  323. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  324. ChoosedRejectList.Items.Clear();
  325. ChoosedRejectList.BeginUpdate();
  326. for (int i = 0; i < dt.Rows.Count; i++)
  327. {
  328. ListViewItem lvi = new ListViewItem();
  329. //第一列是勾选列,设置列头文本为空
  330. lvi.Text = "";
  331. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  332. for (int j = 0; j < dt.Columns.Count; j++)
  333. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  334. ChoosedRejectList.Items.Add(lvi);
  335. }
  336. if (!dh.CheckExist("makebad", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "'")&&(User.CurrentStepCode== "JIFMA"|| User.CurrentStepCode == "MOFMA"))
  337. {
  338. sql.Clear();
  339. sql.Append("select as_bgname||':'||as_bgcode bg_code,as_badcode bc_code,as_badname bc_name,'' mb_badremark from RETURNSNBD join AFSALES on rsb_oldsn = as_sn where rsb_newsn = '" + ms_sncode.Text + "' ");
  340. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  341. if (dt.Rows.Count > 0)
  342. {
  343. for (int i = 0; i < dt.Rows.Count; i++)
  344. {
  345. ListViewItem lvi = new ListViewItem();
  346. //第一列是勾选列,设置列头文本为空
  347. lvi.Text = "";
  348. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  349. for (int j = 0; j < dt.Columns.Count; j++)
  350. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  351. ChoosedRejectList.Items.Add(lvi);
  352. }
  353. }
  354. ChoosedRejectList.EndUpdate();
  355. }
  356. else
  357. {
  358. ChoosedRejectList.EndUpdate();
  359. }
  360. }
  361. /// <summary>
  362. /// 设置良品或者不良品的采集结果
  363. /// </summary>
  364. private void SetCollectResult()
  365. {
  366. string ErrorMessage = "";
  367. //如果勾选的是不良品
  368. if (Reject.Checked)
  369. {
  370. LoadBadCodeListView();
  371. LoadChoosedBadListView();
  372. OperateResult.AppendText(">>请采集不良代码\n", Color.Black);
  373. bc_code.Focus();
  374. }
  375. else if (GoodProduct.Checked)
  376. {
  377. //如果不是返修的
  378. if (ifrework == "0")
  379. {
  380. 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");
  381. for (int i = 0; i < dt.Rows.Count; i++)
  382. {
  383. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  384. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  385. }
  386. //存在不良记录
  387. if (ErrorMessage != "")
  388. {
  389. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  390. return;
  391. }
  392. else
  393. {
  394. //if (AutoBadCode.Checked)
  395. //{
  396. // string str = BaseUtil.GetDataFromDevice("DEVICES");
  397. // str = str.Replace("LIST OF DEVICES ATTACHED", "").Replace("\n", "");
  398. // if (!(str.Length == 0))
  399. // {
  400. // Console.WriteLine("有链接");
  401. // BaseUtil.GetDataFromDevice("RESET");
  402. // }
  403. // else
  404. // {
  405. // OperateResult.AppendText(">>无设备链接,无法恢复出厂设置,采集失败\n", Color.Red, ms_sncode);
  406. // return;
  407. // }
  408. //}
  409. if (khcheck.Checked)
  410. {
  411. String priex = dh.getFieldDataByCondition("product", "pr_usetype", "pr_code = '" + ma_prodcode.Text + "'").ToString();
  412. if (priex == "")
  413. {
  414. OperateResult.AppendText(">>产品编号" + ma_prodcode.Text + "未维护客户码防呆要求\n", Color.Red, ms_sncode);
  415. return;
  416. }
  417. string[] pres = priex.Split('|');
  418. bool f = false;
  419. for (int i = 0; i < pres.Length; i++)
  420. {
  421. if (pres[i] == "" ? true : oth.Text.Contains(pres[i]))
  422. {
  423. //满足其中一条即可
  424. f = true;
  425. break;
  426. }
  427. }
  428. if (!f)
  429. {
  430. OperateResult.AppendText(">>客户码" + oth.Text + "不符合防呆要求\n", Color.Red, oth);
  431. oth.Focus();
  432. oth.SelectAll();
  433. return;
  434. }
  435. }
  436. else
  437. {
  438. if (oth.Text != "")
  439. {
  440. OperateResult.AppendText(">>客户码" + oth.Text + "不需要采集\n", Color.Black, oth);
  441. }
  442. }
  443. //良品信息采集
  444. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", biduisn.Text==""?User.UserCode: biduisn.Text, out ErrorMessage))
  445. {
  446. //if (WriteSoftWare.Checked)
  447. //{
  448. // string Message = BaseUtil.GetDataFromDevice("INSTALL", SoftWarePath.Text);
  449. // OperateResult.AppendText(">>" + Message + "\n");
  450. //}
  451. //提示正确返回时传递的信息
  452. if (ErrorMessage.Contains("AFTERSUCCESS"))
  453. OperateResult.AppendText(">>" + ErrorMessage + "\n",Color.Red);
  454. ////恢复出厂设置
  455. //if (AutoBadCode.Checked)
  456. // BaseUtil.GetDataFromDevice("RESET");
  457. if (oth.Text != "")
  458. {
  459. dh.ExecuteSql(" update makeserial set MS_OTHCODE1 = '"+oth.Text+"' where ms_sncode = '"+ms_sncode.Text+"' ", "update");
  460. }
  461. LastSncode = ms_sncode.Text;
  462. LogicHandler.DoCommandLog(Tag.ToString(), biduisn.Text == "" ? User.UserCode : biduisn.Text, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  463. lastsn.Text = ms_sncode.Text;
  464. lastresult.Text = "OK";
  465. lastresult.BackColor = Color.Green;
  466. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode, oth);
  467. if (khcheck.Checked)
  468. {
  469. oth.Focus();
  470. }
  471. //记录操作日志
  472. }
  473. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode, oth);
  474. }
  475. }
  476. else
  477. {
  478. if (reworkstatus != "3")
  479. {
  480. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  481. {
  482. //提示正确返回时传递的信息
  483. if (ErrorMessage.Contains("AFTERSUCCESS"))
  484. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  485. LastSncode = ms_sncode.Text;
  486. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode, oth);
  487. //记录操作日志
  488. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  489. }
  490. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode, oth);
  491. }
  492. else
  493. {
  494. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  495. }
  496. }
  497. }
  498. //加载页面信息
  499. LoadCollectedNum();
  500. LoadCheckQTY();
  501. }
  502. private void 测试采集_SizeChanged(object sender, EventArgs e)
  503. {
  504. asc.controlAutoSize(this);
  505. }
  506. private void LoadCollectedNum()
  507. {
  508. 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");
  509. BaseUtil.SetFormValue(Controls, dt);
  510. }
  511. private void Save_Click(object sender, EventArgs e)
  512. {
  513. if (ms_sncode.Text == "")
  514. {
  515. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  516. return;
  517. }
  518. if (GoodProduct.Checked)
  519. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  520. else if (Reject.Checked)
  521. {
  522. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  523. {
  524. //判断界面工单是否为空时的序列号是否自动归属工单
  525. string oStatus = "";
  526. if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
  527. {
  528. if (ma_code.Text == "")
  529. {
  530. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  531. return;
  532. }
  533. }
  534. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  535. {
  536. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,pr_orispeccode pr_spec,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  537. if (dt.Rows.Count > 0)
  538. {
  539. BaseUtil.SetFormValue(this.Controls, dt);
  540. LockMakeCode.Checked = true;
  541. }
  542. }
  543. else
  544. {
  545. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  546. return;
  547. }
  548. }
  549. else
  550. {
  551. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  552. return;
  553. }
  554. int RejectCount = ChoosedRejectList.Items.Count;
  555. string[] bccode = new string[RejectCount];
  556. string[] bcremark = new string[RejectCount];
  557. string[] bgcode = new string[RejectCount];
  558. string[] bgname = new string[RejectCount];
  559. string[] bcname = new string[RejectCount];
  560. if (ChoosedRejectList.Items.Count == 0)
  561. {
  562. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  563. return;
  564. }
  565. else
  566. {
  567. for (int i = 0; i < RejectCount; i++)
  568. {
  569. //获取不良代码组
  570. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  571. //获取不良代码组名称
  572. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  573. //获取所有的不良代码
  574. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  575. //获取不良名称
  576. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  577. //获取所有的不良备注
  578. bcremark[i] = bc_remark.Text;
  579. }
  580. }
  581. //如果之前是良品的
  582. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno", "ms_outboxcode" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  583. if (dt.Rows.Count > 0)
  584. {
  585. string status = dt.Rows[0]["ms_status"].ToString();
  586. string outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  587. if (outboxcode != "")
  588. {
  589. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + "已装箱,请先进行拆箱\n", Color.Red);
  590. BaseUtil.CleanForm(this);
  591. return;
  592. }
  593. if (status == "1" || status == "2")
  594. {
  595. dh.UpdateByCondition("steppassed", "sp_result='不良品',sp_date = sysdate,sp_ifng=-1,sp_ymd=to_char(sysdate,'yyyymmdd'),sp_hm=to_char(sysdate,'hh24miss')", "sp_id=(select max(sp_id) from steppassed where sp_sncode='" + ms_sncode.Text + "')");
  596. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  597. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  598. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", biduisn.Text == "" ? User.UserCode : biduisn.Text);
  599. LogicHandler.DoCommandLog(Tag.ToString(), biduisn.Text == "" ? User.UserCode : biduisn.Text, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
  600. }
  601. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  602. //存在抽检批次更新为空
  603. if (checkno != "")
  604. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  605. }
  606. else
  607. {
  608. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", biduisn.Text == "" ? User.UserCode : biduisn.Text);
  609. LogicHandler.DoCommandLog(Tag.ToString(), biduisn.Text == "" ? User.UserCode : biduisn.Text, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
  610. }
  611. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  612. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  613. //normalButton1_Click(this, e);
  614. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, biduisn.Text == "" ? User.UserCode : biduisn.Text, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
  615. {
  616. for (int i = 0; i < bccode.Length; i++)
  617. {
  618. if (dh.CheckExist("badgroupdetail left join badgroup on bgd_bgid = bg_id", "bgd_badcode = '" + bccode[i] + "' and bg_code = '" + bgcode[i] + "' and bgd_brcode is not null and bgd_dutycode is not null and bgd_solutioncode is not null "))
  619. {
  620. string makebadid = dh.getFieldDataByCondition("makebad", "mb_id", "mb_sncode = '" + ms_sncode.Text + "' and mb_makecode = '" + ma_code.Text + "' and mb_badcode = '" + bccode[i] + "' order by mb_id desc").ToString();
  621. DataTable temp = dh.getFieldsDatasByCondition(" badgroupdetail left join badgroup on bgd_bgid = bg_id left join QUA_NGReason on nr_code = bgd_brcode left join QUA_NGReasonGroup on nrg_code = bgd_brgcode left join NGDuty on nd_code = bgd_dutycode left join solution on so_code = bgd_solutioncode", new string[] { "bgd_brgcode", "bgd_dutycode", "bgd_solutioncode", "bgd_brcode", "nrg_name", "nr_name", "nd_name", "so_name" }, "bgd_badcode= '" + bccode[i] + "' and bg_code = '" + bgcode[i] + "'");
  622. string bgd_brgcode = temp.Rows[0]["bgd_brgcode"].ToString();
  623. string bgd_brcode = temp.Rows[0]["bgd_brcode"].ToString();
  624. string bgd_dutycode = temp.Rows[0]["bgd_dutycode"].ToString();
  625. string bgd_solutioncode = temp.Rows[0]["bgd_solutioncode"].ToString();
  626. string mbr_id = dh.GetSEQ("makebadreason_seq");
  627. string bgd_brgname = temp.Rows[0]["nrg_name"].ToString();
  628. string bgd_brname = temp.Rows[0]["nr_name"].ToString();
  629. string bgd_dutyname = temp.Rows[0]["nd_name"].ToString();
  630. string bgd_solutionname = temp.Rows[0]["so_name"].ToString();
  631. sql.Clear();
  632. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  633. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  634. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname) select '" + makebadid + "','" + mbr_id + "','" + bgd_brcode + "',");
  635. sql.Append("'" + bgd_solutioncode + "','" + bgd_dutycode + "','" + bgd_brgcode + "','" + bccode[i] + "',");
  636. sql.Append("'" + ms_sncode.Text + "','" + ma_code.Text + "',sysdate,'" + User.UserCode + "','" + bgd_brname + "','" + bgd_solutionname + "','" + bcname[i] + "','" + bgd_brgname + "','" + bgd_dutyname + "' from dual");
  637. dh.ExecuteSql(sql.GetString(), "insert");
  638. }
  639. }
  640. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.OrangeRed);
  641. lastsn.Text = ms_sncode.Text;
  642. lastresult.Text = "FAILED";
  643. lastresult.BackColor = Color.Red;
  644. LastSncode = ms_sncode.Text;
  645. //采集完不良,聚焦序列号
  646. ms_sncode.Focus();
  647. //记录操作日志
  648. ms_sncode.Text = "";
  649. //清除不良信息
  650. bc_code.Text = "";
  651. biduisn.Text = "";
  652. oth.Text = "";
  653. ChoosedRejectList.Items.Clear();
  654. LoadCollectedNum();
  655. WaitList.Clear();
  656. ChoosedList.Clear();
  657. }
  658. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  659. }
  660. }
  661. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  662. {
  663. if (e.KeyCode == Keys.Enter)
  664. {
  665. sql.Clear();
  666. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
  667. sql.Append("badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode = bc_code where bc_code='" + bc_code.Text + "' and rownum=1 ");
  668. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  669. if (dt.Rows.Count > 0)
  670. {
  671. for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  672. {
  673. if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
  674. {
  675. OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
  676. return;
  677. }
  678. }
  679. ListViewItem lvi = new ListViewItem();
  680. lvi.Text = "";
  681. for (int j = 0; j < dt.Columns.Count; j++)
  682. lvi.SubItems.Add(dt.Rows[0][j].ToString());
  683. ChoosedRejectList.Items.Add(lvi);
  684. bc_code.Clear();
  685. }
  686. else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
  687. }
  688. }
  689. private void LoadCheckQTY()
  690. {
  691. sql.Clear();
  692. string condition = "";
  693. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  694. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  695. if (nowcheckqty + 1 == batchqty && AutoCut)
  696. {
  697. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  698. }
  699. else
  700. {
  701. condition = "and ob_status='ENTERING' ";
  702. }
  703. if (pr_sendchecktype.Text == "SaleCode")
  704. {
  705. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  706. }
  707. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  708. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_inman = '"+User.UserCode+"' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  709. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  710. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  711. if (dt.Rows.Count > 0)
  712. {
  713. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatchdetail left join oqcbatch on obd_checkno = ob_checkno", "count(obd_sncode)", "obd_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  714. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  715. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  716. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  717. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  718. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  719. if (nowcheckqty == batchqty)
  720. {
  721. //ob_nowcheckqty.ForeColor = Color.Red;
  722. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Black);
  723. if (AutoCut)
  724. {
  725. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动送检成功\n", Color.Blue);
  726. }
  727. }
  728. }
  729. else
  730. {
  731. BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno);
  732. SendCheck.Enabled = false;
  733. }
  734. if (ob_batchqty.Text != "")
  735. {
  736. SendCheck.Enabled = true;
  737. }
  738. else
  739. {
  740. SendCheck.Enabled = false;
  741. }
  742. }
  743. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  744. {
  745. if (GoodProduct.Checked)
  746. {
  747. bc_code.Enabled = false;
  748. WaitReject.Enabled = false;
  749. ChooseedReject.Enabled = false;
  750. Save.Visible = false;
  751. }
  752. else
  753. {
  754. bc_code.Enabled = true;
  755. WaitReject.Enabled = true;
  756. ChooseedReject.Enabled = true;
  757. Save.Visible = true;
  758. }
  759. if (ms_sncode.Text == "")
  760. {
  761. ms_sncode.Focus();
  762. }
  763. if (khcheck.Checked&& GoodProduct.Checked)
  764. {
  765. oth.Focus();
  766. }
  767. }
  768. private void SendCheck_Click(object sender, EventArgs e)
  769. {
  770. sql.Clear();
  771. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  772. dh.ExecuteSql(sql.GetString(), "select");
  773. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatchdetail left join oqcbatch on obd_checkno = ob_checkno", "count(obd_sncode)", "obd_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  774. ob_nowcheckqty.Text = "";
  775. ob_batchqty.Text = "";
  776. ob_nowcheckqty.ForeColor = Color.Black;
  777. SendCheck.Enabled = false;
  778. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue);
  779. ms_sncode.Focus();
  780. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  781. //记录操作日志
  782. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  783. ob_checkno.Text = "";
  784. }
  785. private void ob_checkno_TextChanged(object sender, EventArgs e)
  786. {
  787. if (ob_checkno.Text != "")
  788. {
  789. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  790. if (Cut == "" || Cut == "0")
  791. AutoCut = false;
  792. else
  793. AutoCut = true;
  794. SendCheck.Enabled = true;
  795. }
  796. }
  797. /// <summary>
  798. /// 工单变化修改数量
  799. /// </summary>
  800. /// <param name="sender"></param>
  801. /// <param name="e"></param>
  802. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  803. {
  804. if (ma_code.Text.Length > 4)
  805. {
  806. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty);
  807. LoadCollectedNum();
  808. LoadCheckQTY();
  809. }
  810. }
  811. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  812. {
  813. //BaseUtil.ClosePrint(lbl);
  814. //if (engine != null)
  815. // engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  816. dh.Dispose();
  817. }
  818. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  819. {
  820. LoadBadGroupData();
  821. if (dh.CheckExist("product", "pr_code = '" + ma_prodcode.Text + "' and pr_trydays = -1")&&dh.CheckExist("step","st_code = '"+User.CurrentStepCode+ "' and st_ifspc = -1"))
  822. {
  823. khcheck.Checked = true;
  824. }else
  825. {
  826. khcheck.Checked = false;
  827. }
  828. }
  829. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  830. {
  831. try
  832. {
  833. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  834. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  835. for (int i = 0; i < dr.Length; i++)
  836. {
  837. dt.Rows.Add(dr[i].ItemArray);
  838. }
  839. WaitRejectList.Items.Clear();
  840. WaitRejectList.BeginUpdate();
  841. for (int i = 0; i < dt.Rows.Count; i++)
  842. {
  843. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  844. {
  845. ListViewItem lvi = new ListViewItem();
  846. //第一列是勾选列,设置列头文本为空
  847. lvi.Text = "";
  848. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  849. for (int j = 0; j < dt.Columns.Count; j++)
  850. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  851. WaitRejectList.Items.Add(lvi);
  852. }
  853. }
  854. WaitRejectList.EndUpdate();
  855. }
  856. catch (Exception)
  857. {
  858. }
  859. }
  860. private void WaitRejectList_DoubleClick(object sender, EventArgs e)
  861. {
  862. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  863. {
  864. if (WaitRejectList.Items[i].Checked)
  865. {
  866. //双击右移
  867. ChooseedReject.PerformClick();
  868. }
  869. }
  870. }
  871. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  872. {
  873. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  874. {
  875. if (!LockSn)
  876. {
  877. ControlLockTimer.Start();
  878. LockSn = true;
  879. Lock_label.Visible = true;
  880. }
  881. else
  882. {
  883. ControlLockTimer.Stop();
  884. LockSn = false;
  885. Lock_label.Visible = false;
  886. }
  887. }
  888. }
  889. //创建打印进程
  890. private void NewPrint()
  891. {
  892. try
  893. {
  894. // engine = new BarTender.Application();
  895. lbl = new ApplicationClass();
  896. BaseUtil.WriteLbl();
  897. }
  898. catch (Exception ex)
  899. {
  900. OperateResult.AppendText("未正确安装CodeSoft软件\n" + ex.Message, Color.Red);
  901. }
  902. }
  903. private void normalButton1_Click(object sender, EventArgs e)
  904. {
  905. //if (ChoosedRejectList.Items.Count == 0 || ms_sncode.Text == "")
  906. //{
  907. // MessageBox.Show("未录入不良或SN为空");
  908. //}
  909. //string BADINFO = "";
  910. //for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  911. //{
  912. // BADINFO = BADINFO + ChoosedRejectList.Items[i].ListView.Items[i].SubItems[3].Text + " ";
  913. //}
  914. //BADINFO = BADINFO.Substring(0, BADINFO.Length - 1);
  915. //FileInfo PrintFile = new FileInfo(labelname);
  916. //if (!PrintFile.Exists)
  917. //{
  918. // MessageBox.Show("打印文件不存在");
  919. // return ;
  920. //}
  921. //doc = lbl.Documents.Open(labelname, true);
  922. //if (doc == null)
  923. //{
  924. // MessageBox.Show("标签文件打开失败");
  925. // return ;
  926. //}
  927. //for (int j = 1; j < doc.Variables.FormVariables.Count+1; j++)
  928. //{
  929. // switch (doc.Variables.FormVariables.Item(j).Name)
  930. // {
  931. // case "SN":
  932. // doc.Variables.FormVariables.Item(j).Value = ms_sncode.Text;
  933. // break;
  934. // case "BAD":
  935. // doc.Variables.FormVariables.Item(j).Value = BADINFO;
  936. // break;
  937. // }
  938. // // doc.Variables.FormVariables.Item(1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (i).ToString()));
  939. //}
  940. ////保存本次赋值进行打印
  941. //doc.Printer.SwitchTo(PrintList.Text);
  942. //doc.PrintDocument(1);
  943. }
  944. private void StartWatch_Click(object sender, EventArgs e)
  945. {
  946. if (FolderPath.Text == "")
  947. {
  948. OperateResult.AppendText("请选择监控文件夹\n");
  949. return;
  950. }
  951. else
  952. {
  953. if (!Directory.Exists(FolderPath.Text))
  954. {
  955. OperateResult.AppendText("监控文件夹不存在\n");
  956. return;
  957. }
  958. }
  959. XmlWatcher.Path = FolderPath.Text;
  960. XmlWatcher.Filter = "SN Writer.log";
  961. XmlWatcher.EnableRaisingEvents = true;
  962. //设置缓存数据
  963. BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
  964. //设置按钮不可点击
  965. StartWatch.Enabled = false;
  966. ChooseFolder.Enabled = false;
  967. StopWatch.Enabled = true;
  968. OperateResult.AppendText("开始执行监控\n");
  969. }
  970. private void StopWatch_Click(object sender, EventArgs e)
  971. {
  972. XmlWatcher.EnableRaisingEvents = false;
  973. StartWatch.Enabled = true;
  974. ChooseFolder.Enabled = true;
  975. StopWatch.Enabled = false;
  976. OperateResult.AppendText("停止执行监控\n");
  977. }
  978. private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
  979. {
  980. while (true)
  981. {
  982. try
  983. {
  984. using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
  985. {
  986. if (stream != null)
  987. break;
  988. }
  989. }
  990. catch (Exception ex)
  991. {
  992. Console.WriteLine(ex.Message);
  993. }
  994. }
  995. StreamReader _Sr = new StreamReader(FolderPath.Text + @"\" + e.Name, Encoding.UTF8);
  996. String[] strData;
  997. string line;
  998. string ssn = "";
  999. string imei = "";
  1000. string imei1 = "";
  1001. string bt = "";
  1002. string mac = "";
  1003. try
  1004. {
  1005. while ((line = _Sr.ReadLine()) != null)
  1006. {
  1007. if (line.Contains("Barcode[0]"))
  1008. {
  1009. Regex regex = new Regex("\"[^\"]*\"");
  1010. ssn = regex.Match(line).Value.Replace("\"", "");
  1011. }
  1012. else if (line.Contains("Prod_Info->IMEI[0]"))
  1013. {
  1014. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  1015. Regex regex = new Regex("\\[[^*]+\\]");
  1016. imei = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  1017. }
  1018. else if (line.Contains("Prod_Info->IMEI[1]"))
  1019. {
  1020. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  1021. Regex regex = new Regex("\\[[^*]+\\]");
  1022. imei1 = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  1023. }
  1024. else if (line.Contains("Prod_Info->BtAddress"))
  1025. {
  1026. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  1027. Regex regex = new Regex("\\[[^*]+\\]");
  1028. bt = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  1029. }
  1030. else if (line.Contains("Prod_Info->WiFiAddress"))
  1031. {
  1032. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  1033. Regex regex = new Regex("\\[[^*]+\\]");
  1034. mac = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  1035. }
  1036. }
  1037. if (ssn != "")
  1038. {
  1039. ms_sncode.Text = ssn;
  1040. ms_code_KeyDown(this, new KeyEventArgs(Keys.Enter));
  1041. if (imei!="")
  1042. {
  1043. dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update");
  1044. }
  1045. if (imei1 != "")
  1046. {
  1047. dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  1048. }
  1049. if (bt != "")
  1050. {
  1051. dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  1052. }
  1053. if (mac != "")
  1054. {
  1055. dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  1056. }
  1057. }
  1058. }
  1059. catch (Exception ex)
  1060. {
  1061. MessageBox.Show(ex.Message);
  1062. _Sr.Close();
  1063. }
  1064. _Sr.Close();
  1065. }
  1066. private void ChooseFolder_Click(object sender, EventArgs e)
  1067. {
  1068. FolderBrowserDialog folder = new FolderBrowserDialog();
  1069. folder.Description = "选择监控文件夹";
  1070. DialogResult result = folder.ShowDialog();
  1071. if (result == DialogResult.OK)
  1072. {
  1073. FolderPath.Text = folder.SelectedPath;
  1074. }
  1075. }
  1076. private void biduisn_KeyDown(object sender, KeyEventArgs e)
  1077. {
  1078. if (e.KeyCode == Keys.Enter)
  1079. {
  1080. if (bidui.Checked&&biduisn.Text!="")
  1081. {
  1082. ms_sncode.Focus();
  1083. ms_sncode.SelectAll();
  1084. }
  1085. }
  1086. }
  1087. private void bc_code_KeyUp(object sender, KeyEventArgs e)
  1088. {
  1089. if (e.KeyCode == Keys.Add && Save.Visible)
  1090. {
  1091. Save_Click(sender, e);
  1092. bc_code.Clear();
  1093. }
  1094. }
  1095. private void oth_KeyDown(object sender, KeyEventArgs e)
  1096. {
  1097. if (e.KeyCode == Keys.Enter)
  1098. {
  1099. if (oth.Text != "")
  1100. {
  1101. ms_sncode.Focus();
  1102. ms_sncode.SelectAll();
  1103. }
  1104. }
  1105. }
  1106. }
  1107. }