Make_TestCollection.cs 42 KB

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