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