Make_TestCollection.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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.DataOperate;
  8. using UAS_MES.Entity;
  9. using UAS_MES.PublicMethod;
  10. using System.Collections.Generic;
  11. using UAS_MES.CustomControl.PowerControlForm;
  12. namespace UAS_MES.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_detail # 产品名称,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  56. ma_code.FormName = Name;
  57. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_detail", "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. //是否提示过工单切换框,检测前执行
  167. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  168. if (!NoteAlready)
  169. {
  170. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  171. return;
  172. }
  173. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  174. {
  175. //是否提示过工单切换框,检测前后执行
  176. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text,oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  177. {
  178. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  179. return;
  180. }
  181. if (ma_code.Text != oMakeCode && oMakeCode != null)
  182. {
  183. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_detail,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  184. if (dt.Rows.Count > 0)
  185. {
  186. BaseUtil.SetFormValue(this.Controls, dt);
  187. LockMakeCode.Checked = true;
  188. }
  189. }
  190. //if (dh.CheckExist("makeserial LEFT JOIN craft ON ms_craftcode = cr_code and ms_prodcode = cr_prodcode LEFT JOIN craftdetail ON cr_id = cd_crid LEFT JOIN STEP ON CD_NEXTSTEPCODE = ST_CODE ", "ms_id = '"+ oMSID + "' AND CD_STEPCODE = '" + User.CurrentStepCode + "' AND ST_IFOQC = -1 "))
  191. //{
  192. // OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号即将送检,此序列号经过维修,提示\n", Color.Purple);
  193. //}
  194. string mscode = dh.getFieldDataByCondition("makeserial LEFT JOIN craft ON ms_craftcode = cr_code and ms_prodcode = cr_prodcode LEFT JOIN craftdetail ON cr_id = cd_crid LEFT JOIN STEP ON CD_NEXTSTEPCODE = ST_CODE", "ms_code", "ms_id = '" + oMSID + "' AND CD_STEPCODE = '" + User.CurrentStepCode + "' AND ST_IFOQC = -1").ToString();
  195. if (mscode != "" && (dh.CheckExist("makeserial", "ms_id = '" + oMSID + "' and NVL(MS_BADTIMES,0)>0 ") || dh.CheckExist("makeserial", "ms_sncode = '" + mscode + "' and NVL(MS_BADTIMES,0)>0 ")))
  196. {
  197. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号即将送检,此序列号经过维修,提示\n", Color.Purple);
  198. }
  199. 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");
  200. string status = dt.Rows[0]["ms_status"].ToString();
  201. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  202. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  203. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  204. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  205. if (sncode != ms_sncode.Text)
  206. {
  207. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  208. return;
  209. }
  210. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  211. if (GoodProduct.Checked)
  212. {
  213. if (ifrework != "0")
  214. {
  215. if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
  216. {
  217. OperateResult.AppendText(">>" + ms_sncode.Text + "序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  218. return;
  219. }
  220. }
  221. else
  222. {
  223. if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
  224. {
  225. OperateResult.AppendText(">>" + ms_sncode.Text + "序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  226. return;
  227. }
  228. }
  229. }
  230. SetCollectResult();
  231. }
  232. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  233. }
  234. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  235. }
  236. }
  237. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  238. {
  239. LoadBadCodeListView();
  240. }
  241. /// <summary>
  242. /// 填充不良组别信息
  243. /// </summary>
  244. private void LoadBadGroupData()
  245. {
  246. //如果ms_makecode的值修改过再去查询
  247. sql.Clear();
  248. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  249. sql.Append("from product left join productkind on pk_name=pr_kind ");
  250. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  251. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  252. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  253. bc_groupcode.DisplayMember = "bg_name";
  254. bc_groupcode.ValueMember = "bg_code";
  255. bc_groupcode.DataSource = dt;
  256. }
  257. /// <summary>
  258. /// 加载不良代码的ListView的信息
  259. /// </summary>
  260. private void LoadBadCodeListView()
  261. {
  262. object bg_code = bc_groupcode.SelectedValue;
  263. sql.Clear();
  264. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  265. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  266. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  267. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  268. BadInfSource.DataSource = dt;
  269. //往listview中添加数据
  270. WaitRejectList.Items.Clear();
  271. WaitRejectList.BeginUpdate();
  272. for (int i = 0; i < dt.Rows.Count; i++)
  273. {
  274. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  275. {
  276. ListViewItem lvi = new ListViewItem();
  277. //第一列是勾选列,设置列头文本为空
  278. lvi.Text = "";
  279. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  280. for (int j = 0; j < dt.Columns.Count; j++)
  281. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  282. WaitRejectList.Items.Add(lvi);
  283. }
  284. }
  285. WaitRejectList.EndUpdate();
  286. }
  287. /// <summary>
  288. /// 加载已选不良的ListView
  289. /// </summary>
  290. private void LoadChoosedBadListView()
  291. {
  292. sql.Clear();
  293. 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 ");
  294. sql.Append("left join badgroup on mb_bgcode=bg_code left join badcode on mb_badcode=bc_code ");
  295. sql.Append(" where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0");
  296. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  297. ChoosedRejectList.Items.Clear();
  298. ChoosedRejectList.BeginUpdate();
  299. for (int i = 0; i < dt.Rows.Count; i++)
  300. {
  301. ListViewItem lvi = new ListViewItem();
  302. //第一列是勾选列,设置列头文本为空
  303. lvi.Text = "";
  304. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  305. for (int j = 0; j < dt.Columns.Count; j++)
  306. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  307. ChoosedRejectList.Items.Add(lvi);
  308. }
  309. ChoosedRejectList.EndUpdate();
  310. }
  311. /// <summary>
  312. /// 设置良品或者不良品的采集结果
  313. /// </summary>
  314. private void SetCollectResult()
  315. {
  316. string ErrorMessage = "";
  317. //如果勾选的是不良品
  318. if (Reject.Checked)
  319. {
  320. LoadBadCodeListView();
  321. LoadChoosedBadListView();
  322. OperateResult.AppendText(">>请采集不良代码\n", Color.Green);
  323. bc_code.Focus();
  324. //勾选了自动产生代码
  325. if (AutoBadCode.Checked)
  326. Save_Click(new object(), new EventArgs());
  327. }
  328. else if (GoodProduct.Checked)
  329. {
  330. //如果不是返修的
  331. if (ifrework == "0")
  332. {
  333. 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");
  334. for (int i = 0; i < dt.Rows.Count; i++)
  335. {
  336. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  337. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  338. }
  339. //存在不良记录
  340. if (ErrorMessage != "")
  341. {
  342. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  343. return;
  344. }
  345. else
  346. {
  347. //良品信息采集
  348. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  349. {
  350. //提示正确返回时传递的信息
  351. if (ErrorMessage.Contains("AFTERSUCCESS"))
  352. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  353. LastSncode = ms_sncode.Text;
  354. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
  355. //记录操作日志
  356. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  357. }
  358. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  359. }
  360. }
  361. else
  362. {
  363. if (reworkstatus != "3")
  364. {
  365. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  366. {
  367. //提示正确返回时传递的信息
  368. if (ErrorMessage.Contains("AFTERSUCCESS"))
  369. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  370. LastSncode = ms_sncode.Text;
  371. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
  372. //记录操作日志
  373. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  374. }
  375. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  376. }
  377. else
  378. {
  379. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  380. }
  381. }
  382. }
  383. //加载页面信息
  384. LoadCollectedNum();
  385. LoadCheckQTY();
  386. }
  387. private void 测试采集_SizeChanged(object sender, EventArgs e)
  388. {
  389. asc.controlAutoSize(this);
  390. }
  391. private void LoadCollectedNum()
  392. {
  393. 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");
  394. BaseUtil.SetFormValue(Controls, dt);
  395. }
  396. private void Save_Click(object sender, EventArgs e)
  397. {
  398. if (ms_sncode.Text == "")
  399. {
  400. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  401. return;
  402. }
  403. if (GoodProduct.Checked)
  404. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  405. else if (Reject.Checked)
  406. {
  407. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  408. {
  409. //判断界面工单是否为空时的序列号是否自动归属工单
  410. string oStatus = "";
  411. if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
  412. {
  413. if (ma_code.Text == "")
  414. {
  415. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  416. return;
  417. }
  418. }
  419. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  420. {
  421. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,pr_detail,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  422. if (dt.Rows.Count > 0)
  423. {
  424. BaseUtil.SetFormValue(this.Controls, dt);
  425. LockMakeCode.Checked = true;
  426. }
  427. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno", "ms_outboxcode" }, "ms_id='" + oMSID + "' ");
  428. if (dt.Rows.Count > 0)
  429. {
  430. string ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  431. if (ms_outboxcode != "")
  432. {
  433. OperateResult.AppendText(">>SN已装箱" + ms_outboxcode + ",采集不良请先解除装箱\n", Color.Red);
  434. return;
  435. }
  436. }
  437. }
  438. else
  439. {
  440. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  441. return;
  442. }
  443. }
  444. else
  445. {
  446. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  447. return;
  448. }
  449. int RejectCount = ChoosedRejectList.Items.Count;
  450. string[] bccode = new string[RejectCount];
  451. string[] bcremark = new string[RejectCount];
  452. string[] bgcode = new string[RejectCount];
  453. string[] bgname = new string[RejectCount];
  454. string[] bcname = new string[RejectCount];
  455. if (AutoBadCode.Checked)
  456. {
  457. string defaultvalue = Properties.Settings.Default.DefaultCollectionValue;
  458. bccode = new string[] { defaultvalue };
  459. bcremark = new string[] { defaultvalue };
  460. bgcode = new string[] { defaultvalue };
  461. bgname = new string[] { defaultvalue };
  462. bcname = new string[] { defaultvalue };
  463. }
  464. else
  465. {
  466. if (ChoosedRejectList.Items.Count == 0)
  467. {
  468. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  469. return;
  470. }
  471. else
  472. {
  473. for (int i = 0; i < RejectCount; i++)
  474. {
  475. //获取不良代码组
  476. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  477. //获取不良代码组名称
  478. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  479. //获取所有的不良代码
  480. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  481. //获取不良名称
  482. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  483. //获取所有的不良备注
  484. bcremark[i] = bc_remark.Text;
  485. }
  486. }
  487. }
  488. //如果之前是良品的
  489. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno","ms_outboxcode" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  490. if (dt.Rows.Count > 0)
  491. {
  492. string ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  493. if (ms_outboxcode != "")
  494. {
  495. OperateResult.AppendText(">>SN已装箱"+ms_outboxcode+",采集不良请先解除装箱\n",Color.Red);
  496. return;
  497. }
  498. string status = dt.Rows[0]["ms_status"].ToString();
  499. if (status == "1" || status == "2")
  500. {
  501. dh.UpdateByCondition("steppassed", "sp_result='不良品',sp_ifng=-1,sp_ymd=to_char(sysdate,'yyyymmdd'),sp_hm=to_char(sysdate,'hh24miss'),sp_linecode = '"+User.UserLineCode+"',sp_sccode = '"+User.UserSourceCode+"'", "sp_id=(select max(sp_id) from steppassed where sp_sncode='" + ms_sncode.Text + "')");
  502. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  503. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  504. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
  505. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
  506. }
  507. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  508. //存在抽检批次更新为空
  509. if (checkno != "")
  510. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  511. }
  512. else {
  513. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
  514. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
  515. }
  516. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  517. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  518. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
  519. {
  520. //存在的不良代码和
  521. dt = (DataTable)dh.ExecuteSql("select sr_badcode from STEPRETURN where sr_stepcode='" + User.CurrentStepCode + "'", "select");
  522. if (dt.Rows.Count > 0)
  523. {
  524. int BadCodeInStep = 0;
  525. string badname = "";
  526. for (int i = 0; i < dt.Rows.Count; i++)
  527. {
  528. for (int j = 0; j < bccode.Length; j++)
  529. {
  530. if (dt.Rows[i]["sr_badcode"].ToString() == bccode[j])
  531. {
  532. badname += "[" + bcname[j] + "]";
  533. BadCodeInStep += 1;
  534. }
  535. }
  536. }
  537. //选中的不良代码必须全在工序默认的不良代码中才通过判断
  538. if (BadCodeInStep == bccode.Length)
  539. {
  540. dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_stepcode='" + User.CurrentStepCode + "'");
  541. dh.UpdateByCondition("makeserial", "ms_stepcode='',ms_status=1,ms_nextstepcode='" + User.CurrentStepCode + "'", "ms_id='" + oMSID + "'");
  542. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修成功", "快速维修", "", ob_checkno.Text);
  543. OperateResult.AppendText(">>本次采集不良代码" + badname + "存在于本工序" + User.CurrentStepCode + "中,请解除故障后重新测试本站\n", Color.Black);
  544. }
  545. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  546. }
  547. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  548. LastSncode = ms_sncode.Text;
  549. //采集完不良,聚焦序列号
  550. ms_sncode.Focus();
  551. //记录操作日志
  552. ms_sncode.Text = "";
  553. //清除不良信息
  554. bc_code.Text = "";
  555. ChoosedRejectList.Items.Clear();
  556. LoadCollectedNum();
  557. WaitList.Clear();
  558. ChoosedList.Clear();
  559. }
  560. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  561. }
  562. }
  563. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  564. {
  565. if (e.KeyCode == Keys.Enter)
  566. {
  567. sql.Clear();
  568. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
  569. 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 ");
  570. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  571. if (dt.Rows.Count > 0)
  572. {
  573. for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  574. {
  575. if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
  576. {
  577. OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
  578. return;
  579. }
  580. }
  581. ListViewItem lvi = new ListViewItem();
  582. lvi.Text = "";
  583. for (int j = 0; j < dt.Columns.Count; j++)
  584. lvi.SubItems.Add(dt.Rows[0][j].ToString());
  585. ChoosedRejectList.Items.Add(lvi);
  586. bc_code.Clear();
  587. }
  588. else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
  589. }
  590. }
  591. private void LoadCheckQTY()
  592. {
  593. sql.Clear();
  594. string condition = "";
  595. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  596. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  597. if (nowcheckqty + 1 == batchqty && AutoCut)
  598. {
  599. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  600. }
  601. else
  602. {
  603. condition = "and ob_status='ENTERING' ";
  604. }
  605. if (pr_sendchecktype.Text == "SaleCode")
  606. {
  607. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  608. }
  609. else if (pr_sendchecktype.Text == "MakeCode")
  610. {
  611. condition += " and ob_makecode='" + ma_code.Text + "'";
  612. }
  613. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  614. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  615. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  616. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  617. if (dt.Rows.Count > 0)
  618. {
  619. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  620. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  621. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  622. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  623. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  624. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  625. if (nowcheckqty == batchqty)
  626. {
  627. ob_nowcheckqty.ForeColor = Color.Red;
  628. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  629. if (AutoCut)
  630. {
  631. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  632. }
  633. }
  634. }
  635. else
  636. {
  637. ob_batchqty.Text = "";
  638. ob_nowcheckqty.Text = "";
  639. ob_checkno.Text = "";
  640. SendCheck.Enabled = false;
  641. }
  642. if (ob_batchqty.Text != "")
  643. {
  644. SendCheck.Enabled = true;
  645. }
  646. else
  647. {
  648. SendCheck.Enabled = false;
  649. }
  650. }
  651. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  652. {
  653. if (GoodProduct.Checked)
  654. {
  655. bc_code.Enabled = false;
  656. WaitReject.Enabled = false;
  657. ChooseedReject.Enabled = false;
  658. Save.Visible = false;
  659. }
  660. else
  661. {
  662. bc_code.Enabled = true;
  663. WaitReject.Enabled = true;
  664. ChooseedReject.Enabled = true;
  665. Save.Visible = true;
  666. }
  667. if (ms_sncode.Text == "")
  668. {
  669. ms_sncode.Focus();
  670. }
  671. }
  672. private void SendCheck_Click(object sender, EventArgs e)
  673. {
  674. sql.Clear();
  675. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  676. dh.ExecuteSql(sql.GetString(), "select");
  677. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  678. ob_nowcheckqty.Text = "";
  679. ob_batchqty.Text = "";
  680. ob_nowcheckqty.ForeColor = Color.Black;
  681. SendCheck.Enabled = false;
  682. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  683. ms_sncode.Focus();
  684. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  685. //记录操作日志
  686. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  687. ob_checkno.Text = "";
  688. }
  689. private void ob_checkno_TextChanged(object sender, EventArgs e)
  690. {
  691. if (ob_checkno.Text != "")
  692. {
  693. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  694. if (Cut == "" || Cut == "0")
  695. AutoCut = false;
  696. else
  697. AutoCut = true;
  698. SendCheck.Enabled = true;
  699. }
  700. }
  701. /// <summary>
  702. /// 工单变化修改数量
  703. /// </summary>
  704. /// <param name="sender"></param>
  705. /// <param name="e"></param>
  706. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  707. {
  708. if (ma_code.Text.Length > 4)
  709. {
  710. mcd_inqty.Text = "";
  711. mcd_remainqty.Text = "";
  712. ob_batchqty.Text = "";
  713. ob_nowcheckqty.Text = "";
  714. ob_sendqty.Text = "";
  715. LoadCollectedNum();
  716. LoadCheckQTY();
  717. }
  718. }
  719. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  720. {
  721. dh.Dispose();
  722. }
  723. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  724. {
  725. LoadBadGroupData();
  726. }
  727. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  728. {
  729. try
  730. {
  731. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  732. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  733. for (int i = 0; i < dr.Length; i++)
  734. {
  735. dt.Rows.Add(dr[i].ItemArray);
  736. }
  737. WaitRejectList.Items.Clear();
  738. WaitRejectList.BeginUpdate();
  739. for (int i = 0; i < dt.Rows.Count; i++)
  740. {
  741. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  742. {
  743. ListViewItem lvi = new ListViewItem();
  744. //第一列是勾选列,设置列头文本为空
  745. lvi.Text = "";
  746. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  747. for (int j = 0; j < dt.Columns.Count; j++)
  748. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  749. WaitRejectList.Items.Add(lvi);
  750. }
  751. }
  752. WaitRejectList.EndUpdate();
  753. }
  754. catch (Exception)
  755. {
  756. }
  757. }
  758. private void WaitRejectList_DoubleClick(object sender, EventArgs e)
  759. {
  760. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  761. {
  762. if (WaitRejectList.Items[i].Checked)
  763. {
  764. //双击右移
  765. ChooseedReject.PerformClick();
  766. }
  767. }
  768. }
  769. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  770. {
  771. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  772. {
  773. if (!LockSn)
  774. {
  775. ControlLockTimer.Start();
  776. LockSn = true;
  777. Lock_label.Visible = true;
  778. }
  779. else
  780. {
  781. ControlLockTimer.Stop();
  782. LockSn = false;
  783. Lock_label.Visible = false;
  784. }
  785. }
  786. }
  787. }
  788. }