Make_TestCollection.cs 41 KB

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