Make_TestCollection.cs 38 KB

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