Make_TestCollection_DCW.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 System.IO.Ports;
  13. using System.IO;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_TestCollection_DCW : Form
  17. {
  18. DataHelper dh = null;
  19. DataTable dt = null;
  20. //当前工序的名称
  21. string ErrorMessage = "";
  22. //用于保存是否之前输入的ms_sncode
  23. string LastSncode;
  24. string oMakeCode = "";
  25. string oMSID = "";
  26. string ifrework = "";
  27. string reworkstatus = "";
  28. LogStringBuilder sql = new LogStringBuilder();
  29. AutoSizeFormClass asc = new AutoSizeFormClass();
  30. /// <summary>
  31. /// 已选的不良
  32. /// </summary>
  33. List<string> ChoosedList = new List<string>();
  34. /// <summary>
  35. /// 待选的不良
  36. /// </summary>
  37. List<string> WaitList = new List<string>();
  38. bool AutoCut = false;
  39. bool LockSn = false;
  40. SerialPort serialPort1 = new SerialPort();
  41. bool ReadData = true;
  42. Thread thread;
  43. DataTable Dbfind;
  44. public Make_TestCollection_DCW()
  45. {
  46. InitializeComponent();
  47. }
  48. private void TestCollection_Load(object sender, EventArgs e)
  49. {
  50. GoodProduct.Checked = true;
  51. asc.controllInitializeSize(this);
  52. ms_sncode.Focus();
  53. //设置锁定工单
  54. LockMakeCode.GetMakeCodeCtl(ma_code);
  55. ma_code.SetLockCheckBox(LockMakeCode);
  56. ControlLockTimer.Tick += ControlLockTimer_Tick;
  57. ControlLockTimer.Interval = 100;
  58. //工单号放大镜配置
  59. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  60. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  61. ma_code.FormName = Name;
  62. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  63. ma_code.Condition = "ma_statuscode='STARTED'";
  64. ma_code.DbChange += Ma_code_DbChange;
  65. dh = SystemInf.dh;
  66. StepCount.StepCode = User.CurrentStepCode;
  67. StepCount.Source = User.UserSourceCode;
  68. StepCount.LineCode = User.UserLineCode;
  69. StepCount.Dh = dh;
  70. StepCount.Start();
  71. }
  72. private void ControlLockTimer_Tick(object sender, EventArgs e)
  73. {
  74. this.Activate();
  75. ms_sncode.Focus();
  76. }
  77. private void Ma_code_DbChange(object sender, EventArgs e)
  78. {
  79. Dbfind = ma_code.ReturnData;
  80. BaseUtil.SetFormValue(this.Controls, Dbfind);
  81. LoadBadGroupData();
  82. LoadCollectedNum();
  83. }
  84. /// <summary>
  85. /// 将已选不良移动到待选不良
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. private void WaitReject_Click(object sender, EventArgs e)
  90. {
  91. int CheckedNum = 0;
  92. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  93. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  94. {
  95. if (ChoosedRejectList.Items[i].Checked)
  96. {
  97. ChoosedRejectList.Items[i].Checked = false;
  98. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  99. ChoosedRejectList.Items[i].Remove();
  100. CheckedNum++;
  101. }
  102. }
  103. if (CheckedNum == 0)
  104. {
  105. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  106. {
  107. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  108. ChoosedRejectList.Items[i].Remove();
  109. }
  110. }
  111. }
  112. /// <summary>
  113. /// 将不良信息移动到已选不良
  114. /// </summary>
  115. /// <param name="sender"></param>
  116. /// <param name="e"></param>
  117. private void ChooseedReject_Click(object sender, EventArgs e)
  118. {
  119. if (ms_sncode.Text == "")
  120. {
  121. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  122. ms_sncode.Focus();
  123. return;
  124. }
  125. int CheckedNum = 0;
  126. //是否已经添加到不良
  127. bool AddToReject = false;
  128. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  129. {
  130. if (WaitRejectList.Items[i].Checked)
  131. {
  132. AddToReject = false;
  133. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  134. {
  135. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  136. {
  137. AddToReject = true;
  138. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  139. break;
  140. }
  141. }
  142. //未添加则进行添加
  143. if (!AddToReject)
  144. {
  145. WaitRejectList.Items[i].Checked = false;
  146. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  147. WaitRejectList.Items[i].Remove();
  148. CheckedNum++;
  149. }
  150. }
  151. }
  152. if (CheckedNum == 0)
  153. {
  154. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  155. }
  156. }
  157. private void CleanInfo_Click(object sender, EventArgs e)
  158. {
  159. OperateResult.Clear();
  160. }
  161. private void ms_code_KeyDown(object sender, KeyEventArgs e)
  162. {
  163. if (e.KeyCode == Keys.Enter)
  164. {
  165. ChoosedRejectList.Items.Clear();
  166. WaitList.Clear();
  167. ChoosedList.Clear();
  168. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  169. {
  170. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  171. if (!NoteAlready)
  172. {
  173. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  174. return;
  175. }
  176. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  177. {
  178. //是否提示过工单切换框,检测前后执行
  179. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  180. {
  181. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  182. return;
  183. }
  184. if (ma_code.Text != oMakeCode && oMakeCode != null)
  185. {
  186. 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");
  187. if (dt.Rows.Count > 0)
  188. {
  189. BaseUtil.SetFormValue(this.Controls, dt);
  190. LockMakeCode.Checked = true;
  191. }
  192. }
  193. 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");
  194. string status = dt.Rows[0]["ms_status"].ToString();
  195. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  196. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  197. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  198. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  199. if (sncode != ms_sncode.Text)
  200. {
  201. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  202. return;
  203. }
  204. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  205. if (GoodProduct.Checked)
  206. {
  207. if (ifrework != "0")
  208. {
  209. if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
  210. {
  211. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  212. return;
  213. }
  214. }
  215. else
  216. {
  217. if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
  218. {
  219. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  220. return;
  221. }
  222. }
  223. }
  224. SetCollectResult();
  225. }
  226. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  227. }
  228. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  229. }
  230. }
  231. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  232. {
  233. LoadBadCodeListView();
  234. }
  235. /// <summary>
  236. /// 填充不良组别信息
  237. /// </summary>
  238. private void LoadBadGroupData()
  239. {
  240. //如果ms_makecode的值修改过再去查询
  241. sql.Clear();
  242. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  243. sql.Append("from product left join productkind on pk_name=pr_kind ");
  244. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  245. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  246. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  247. bc_groupcode.DisplayMember = "bg_name";
  248. bc_groupcode.ValueMember = "bg_code";
  249. bc_groupcode.DataSource = dt;
  250. }
  251. /// <summary>
  252. /// 加载不良代码的ListView的信息
  253. /// </summary>
  254. private void LoadBadCodeListView()
  255. {
  256. object bg_code = bc_groupcode.SelectedValue;
  257. sql.Clear();
  258. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  259. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  260. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  261. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  262. BadInfSource.DataSource = dt;
  263. //往listview中添加数据
  264. WaitRejectList.Items.Clear();
  265. WaitRejectList.BeginUpdate();
  266. for (int i = 0; i < dt.Rows.Count; i++)
  267. {
  268. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  269. {
  270. ListViewItem lvi = new ListViewItem();
  271. //第一列是勾选列,设置列头文本为空
  272. lvi.Text = "";
  273. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  274. for (int j = 0; j < dt.Columns.Count; j++)
  275. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  276. WaitRejectList.Items.Add(lvi);
  277. }
  278. }
  279. WaitRejectList.EndUpdate();
  280. }
  281. /// <summary>
  282. /// 加载已选不良的ListView
  283. /// </summary>
  284. private void LoadChoosedBadListView()
  285. {
  286. sql.Clear();
  287. 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 ");
  288. sql.Append("left join badgroup on mb_bgcode=bg_code left join badcode on mb_badcode=bc_code ");
  289. sql.Append(" where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0");
  290. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  291. ChoosedRejectList.Items.Clear();
  292. ChoosedRejectList.BeginUpdate();
  293. for (int i = 0; i < dt.Rows.Count; i++)
  294. {
  295. ListViewItem lvi = new ListViewItem();
  296. //第一列是勾选列,设置列头文本为空
  297. lvi.Text = "";
  298. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  299. for (int j = 0; j < dt.Columns.Count; j++)
  300. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  301. ChoosedRejectList.Items.Add(lvi);
  302. }
  303. ChoosedRejectList.EndUpdate();
  304. }
  305. /// <summary>
  306. /// 设置良品或者不良品的采集结果
  307. /// </summary>
  308. private void SetCollectResult()
  309. {
  310. string ErrorMessage = "";
  311. //如果勾选的是不良品
  312. if (Reject.Checked)
  313. {
  314. LoadBadCodeListView();
  315. LoadChoosedBadListView();
  316. OperateResult.AppendText(">>请采集不良代码\n", Color.Green);
  317. bc_code.Focus();
  318. //勾选了自动产生代码
  319. if (AutoBadCode.Checked)
  320. Save_Click(new object(), new EventArgs());
  321. }
  322. else if (GoodProduct.Checked)
  323. {
  324. //如果不是返修的
  325. if (ifrework == "0")
  326. {
  327. 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");
  328. for (int i = 0; i < dt.Rows.Count; i++)
  329. {
  330. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  331. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  332. }
  333. //存在不良记录
  334. if (ErrorMessage != "")
  335. {
  336. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  337. return;
  338. }
  339. else
  340. {
  341. //良品信息采集
  342. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  343. {
  344. //提示正确返回时传递的信息
  345. if (ErrorMessage.Contains("AFTERSUCCESS"))
  346. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  347. LastSncode = ms_sncode.Text;
  348. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
  349. //记录操作日志
  350. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, "");
  351. }
  352. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  353. }
  354. }
  355. else
  356. {
  357. if (reworkstatus != "3")
  358. {
  359. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  360. {
  361. //提示正确返回时传递的信息
  362. if (ErrorMessage.Contains("AFTERSUCCESS"))
  363. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  364. LastSncode = ms_sncode.Text;
  365. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
  366. //记录操作日志
  367. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, "");
  368. }
  369. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  370. }
  371. else
  372. {
  373. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  374. }
  375. }
  376. }
  377. //加载页面信息
  378. LoadCollectedNum();
  379. }
  380. private void 测试采集_SizeChanged(object sender, EventArgs e)
  381. {
  382. asc.controlAutoSize(this);
  383. }
  384. private void LoadCollectedNum()
  385. {
  386. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  387. BaseUtil.SetFormValue(Controls, dt);
  388. }
  389. private void Save_Click(object sender, EventArgs e)
  390. {
  391. if (ms_sncode.Text == "")
  392. {
  393. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  394. return;
  395. }
  396. if (GoodProduct.Checked)
  397. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  398. else if (Reject.Checked)
  399. {
  400. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  401. {
  402. //判断界面工单是否为空时的序列号是否自动归属工单
  403. string oStatus = "";
  404. if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
  405. {
  406. if (ma_code.Text == "")
  407. {
  408. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  409. return;
  410. }
  411. }
  412. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  413. {
  414. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,pr_spec,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  415. if (dt.Rows.Count > 0)
  416. {
  417. BaseUtil.SetFormValue(this.Controls, dt);
  418. LockMakeCode.Checked = true;
  419. }
  420. }
  421. else
  422. {
  423. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  424. return;
  425. }
  426. }
  427. else
  428. {
  429. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  430. return;
  431. }
  432. int RejectCount = ChoosedRejectList.Items.Count;
  433. string[] bccode = new string[RejectCount];
  434. string[] bcremark = new string[RejectCount];
  435. string[] bgcode = new string[RejectCount];
  436. string[] bgname = new string[RejectCount];
  437. string[] bcname = new string[RejectCount];
  438. if (AutoBadCode.Checked)
  439. {
  440. string defaultvalue = Properties.Settings.Default.DefaultCollectionValue;
  441. bccode = new string[] { defaultvalue };
  442. bcremark = new string[] { defaultvalue };
  443. bgcode = new string[] { defaultvalue };
  444. bgname = new string[] { defaultvalue };
  445. bcname = new string[] { defaultvalue };
  446. }
  447. else
  448. {
  449. if (ChoosedRejectList.Items.Count == 0)
  450. {
  451. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  452. return;
  453. }
  454. else
  455. {
  456. for (int i = 0; i < RejectCount; i++)
  457. {
  458. //获取不良代码组
  459. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  460. //获取不良代码组名称
  461. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  462. //获取所有的不良代码
  463. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  464. //获取不良名称
  465. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  466. //获取所有的不良备注
  467. bcremark[i] = bc_remark.Text;
  468. }
  469. }
  470. }
  471. //如果之前是良品的
  472. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  473. if (dt.Rows.Count > 0)
  474. {
  475. string status = dt.Rows[0]["ms_status"].ToString();
  476. if (status == "1" || status == "2")
  477. {
  478. dh.UpdateByCondition("steppassed", "sp_result='不良品',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 + "')");
  479. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  480. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  481. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
  482. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, "");
  483. }
  484. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  485. //存在抽检批次更新为空
  486. if (checkno != "")
  487. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  488. }
  489. else
  490. {
  491. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
  492. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, "");
  493. }
  494. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  495. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  496. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
  497. {
  498. //存在的不良代码和
  499. dt = (DataTable)dh.ExecuteSql("select sr_badcode from STEPRETURN where sr_stepcode='" + User.CurrentStepCode + "'", "select");
  500. if (dt.Rows.Count > 0)
  501. {
  502. int BadCodeInStep = 0;
  503. string badname = "";
  504. for (int i = 0; i < dt.Rows.Count; i++)
  505. {
  506. for (int j = 0; j < bccode.Length; j++)
  507. {
  508. if (dt.Rows[i]["sr_badcode"].ToString() == bccode[j])
  509. {
  510. badname += "[" + bcname[j] + "]";
  511. BadCodeInStep += 1;
  512. }
  513. }
  514. }
  515. //选中的不良代码必须全在工序默认的不良代码中才通过判断
  516. if (BadCodeInStep == bccode.Length)
  517. {
  518. dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_stepcode='" + User.CurrentStepCode + "'");
  519. dh.UpdateByCondition("makeserial", "ms_stepcode='',ms_status=1,ms_nextstepcode='" + User.CurrentStepCode + "'", "ms_id='" + oMSID + "'");
  520. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修成功", "快速维修", "", "");
  521. OperateResult.AppendText(">>本次采集不良代码" + badname + "存在于本工序" + User.CurrentStepCode + "中,请解除故障后重新测试本站\n", Color.Black);
  522. }
  523. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  524. }
  525. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  526. LastSncode = ms_sncode.Text;
  527. //采集完不良,聚焦序列号
  528. ms_sncode.Focus();
  529. //记录操作日志
  530. ms_sncode.Text = "";
  531. //清除不良信息
  532. bc_code.Text = "";
  533. ChoosedRejectList.Items.Clear();
  534. LoadCollectedNum();
  535. WaitList.Clear();
  536. ChoosedList.Clear();
  537. }
  538. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  539. }
  540. }
  541. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  542. {
  543. if (e.KeyCode == Keys.Enter)
  544. {
  545. sql.Clear();
  546. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
  547. 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 ");
  548. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  549. if (dt.Rows.Count > 0)
  550. {
  551. for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  552. {
  553. if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
  554. {
  555. OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
  556. return;
  557. }
  558. }
  559. ListViewItem lvi = new ListViewItem();
  560. lvi.Text = "";
  561. for (int j = 0; j < dt.Columns.Count; j++)
  562. lvi.SubItems.Add(dt.Rows[0][j].ToString());
  563. ChoosedRejectList.Items.Add(lvi);
  564. bc_code.Clear();
  565. }
  566. else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
  567. }
  568. }
  569. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  570. {
  571. if (GoodProduct.Checked)
  572. {
  573. bc_code.Enabled = false;
  574. WaitReject.Enabled = false;
  575. ChooseedReject.Enabled = false;
  576. Save.Visible = false;
  577. }
  578. else
  579. {
  580. bc_code.Enabled = true;
  581. WaitReject.Enabled = true;
  582. ChooseedReject.Enabled = true;
  583. Save.Visible = true;
  584. }
  585. if (ms_sncode.Text == "")
  586. {
  587. ms_sncode.Focus();
  588. }
  589. }
  590. /// <summary>
  591. /// 工单变化修改数量
  592. /// </summary>
  593. /// <param name="sender"></param>
  594. /// <param name="e"></param>
  595. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  596. {
  597. if (ma_code.Text.Length > 4)
  598. {
  599. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty);
  600. LoadCollectedNum();
  601. }
  602. }
  603. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  604. {
  605. dh.Dispose();
  606. }
  607. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  608. {
  609. LoadBadGroupData();
  610. }
  611. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  612. {
  613. try
  614. {
  615. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  616. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  617. for (int i = 0; i < dr.Length; i++)
  618. {
  619. dt.Rows.Add(dr[i].ItemArray);
  620. }
  621. WaitRejectList.Items.Clear();
  622. WaitRejectList.BeginUpdate();
  623. for (int i = 0; i < dt.Rows.Count; i++)
  624. {
  625. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  626. {
  627. ListViewItem lvi = new ListViewItem();
  628. //第一列是勾选列,设置列头文本为空
  629. lvi.Text = "";
  630. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  631. for (int j = 0; j < dt.Columns.Count; j++)
  632. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  633. WaitRejectList.Items.Add(lvi);
  634. }
  635. }
  636. WaitRejectList.EndUpdate();
  637. }
  638. catch (Exception)
  639. {
  640. }
  641. }
  642. private void WaitRejectList_DoubleClick(object sender, EventArgs e)
  643. {
  644. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  645. {
  646. if (WaitRejectList.Items[i].Checked)
  647. {
  648. //双击右移
  649. ChooseedReject.PerformClick();
  650. }
  651. }
  652. }
  653. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  654. {
  655. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  656. {
  657. if (!LockSn)
  658. {
  659. ControlLockTimer.Start();
  660. LockSn = true;
  661. Lock_label.Visible = true;
  662. }
  663. else
  664. {
  665. ControlLockTimer.Stop();
  666. LockSn = false;
  667. Lock_label.Visible = false;
  668. }
  669. }
  670. }
  671. private void StartTest_Click(object sender, EventArgs e)
  672. {
  673. if (this.ComList.Text == "")
  674. {
  675. MessageBox.Show("端口号不可为空");
  676. return;
  677. }
  678. if (this.BaudRate.Text == "")
  679. {
  680. MessageBox.Show("波特率不可为空");
  681. return;
  682. }
  683. thread = new Thread(GetSerialData);
  684. try
  685. {
  686. ReadData = true;
  687. serialPort1.PortName = this.ComList.Text;
  688. serialPort1.BaudRate = int.Parse(BaudRate.Text);
  689. BaseUtil.SetCacheData("PortName", this.ComList.Text);
  690. BaseUtil.SetCacheData("BaudRate", BaudRate.Text);
  691. serialPort1.Open();
  692. thread.Start();
  693. }
  694. catch (Exception mes) { MessageBox.Show(mes.Message); }
  695. }
  696. private void GetSerialData()
  697. {
  698. if (serialPort1.IsOpen)
  699. {
  700. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  701. {
  702. SystemInf.OpenPort.Add(serialPort1.PortName);
  703. try
  704. {
  705. while (ReadData)
  706. {
  707. try
  708. {
  709. string resulttext = serialPort1.ReadLine().Trim();
  710. //需要拆分字符串
  711. if (resulttext.IndexOf(";") > 0)
  712. {
  713. string[] sncode = resulttext.Split(';');
  714. for (int i = 0; i < sncode.Length; i++)
  715. {
  716. ms_sncode.Text = sncode[i];
  717. ms_code_KeyDown(ms_sncode, new KeyEventArgs(Keys.Enter));
  718. }
  719. }
  720. else
  721. {
  722. ms_sncode.Text = resulttext;
  723. ms_code_KeyDown(ms_sncode, new KeyEventArgs(Keys.Enter));
  724. }
  725. }
  726. catch (Exception)
  727. {
  728. ReadData = false;
  729. }
  730. }
  731. }
  732. catch (IOException ex) { MessageBox.Show(ex.Message); }
  733. }
  734. else
  735. MessageBox.Show("端口已被占用,请关闭其他窗口");
  736. }
  737. }
  738. }
  739. }