Make_TestCollection.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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,ma_softversion,ma_salecode,substr(pr_spec,0,50)pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  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.SetStepResult(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.SetStepResult(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_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");
  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,ma_softversion,substr(pr_spec,0,50)pr_spec,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "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. //如果之前是良品的
  486. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  487. if (dt.Rows.Count > 0)
  488. {
  489. string status = dt.Rows[0]["ms_status"].ToString();
  490. if (status == "1" || status == "2")
  491. {
  492. 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 + "')");
  493. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  494. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  495. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
  496. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
  497. }
  498. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  499. //存在抽检批次更新为空
  500. if (checkno != "")
  501. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  502. }
  503. else
  504. {
  505. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
  506. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
  507. }
  508. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  509. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  510. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
  511. {
  512. //存在的不良代码和
  513. dt = (DataTable)dh.ExecuteSql("select sr_badcode from STEPRETURN where sr_stepcode='" + User.CurrentStepCode + "'", "select");
  514. if (dt.Rows.Count > 0)
  515. {
  516. int BadCodeInStep = 0;
  517. string badname = "";
  518. for (int i = 0; i < dt.Rows.Count; i++)
  519. {
  520. for (int j = 0; j < bccode.Length; j++)
  521. {
  522. if (dt.Rows[i]["sr_badcode"].ToString() == bccode[j])
  523. {
  524. badname += "[" + bcname[j] + "]";
  525. BadCodeInStep += 1;
  526. }
  527. }
  528. }
  529. //选中的不良代码必须全在工序默认的不良代码中才通过判断
  530. if (BadCodeInStep == bccode.Length)
  531. {
  532. dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_stepcode='" + User.CurrentStepCode + "'");
  533. dh.UpdateByCondition("makeserial", "ms_stepcode='',ms_status=1,ms_nextstepcode='" + User.CurrentStepCode + "'", "ms_id='" + oMSID + "'");
  534. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修成功", "快速维修", "", ob_checkno.Text);
  535. OperateResult.AppendText(">>本次采集不良代码" + badname + "存在于本工序" + User.CurrentStepCode + "中,请解除故障后重新测试本站\n", Color.Black);
  536. }
  537. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  538. }
  539. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  540. if (IfTest.Checked)
  541. {
  542. dh.ExecuteSql("update makeserial set ms_iftest=-1 where ms_id='" + oMSID + "'", "update");
  543. }
  544. //打印不良代码贴纸
  545. if (EnablePrint && AutoPrintBad.Checked)
  546. {
  547. RePrintCode.Clear();
  548. for (int i = 0; i < bcname.Length; i++)
  549. {
  550. RePrintCode.Add(bcname[i]);
  551. format.SubStrings["SN1"].Value = bcname[i];
  552. format.PrintSetup.PrinterName = Printer.Text;
  553. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  554. format.Print();
  555. }
  556. }
  557. LastSncode = ms_sncode.Text;
  558. //采集完不良,聚焦序列号
  559. ms_sncode.Focus();
  560. //记录操作日志
  561. ms_sncode.Text = "";
  562. //清除不良信息
  563. bc_code.Text = "";
  564. ChoosedRejectList.Items.Clear();
  565. LoadCollectedNum();
  566. WaitList.Clear();
  567. ChoosedList.Clear();
  568. }
  569. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  570. }
  571. }
  572. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  573. {
  574. if (e.KeyCode == Keys.Enter)
  575. {
  576. sql.Clear();
  577. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
  578. 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 ");
  579. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  580. if (dt.Rows.Count > 0)
  581. {
  582. for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  583. {
  584. if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
  585. {
  586. OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
  587. return;
  588. }
  589. }
  590. ListViewItem lvi = new ListViewItem();
  591. lvi.Text = "";
  592. for (int j = 0; j < dt.Columns.Count; j++)
  593. lvi.SubItems.Add(dt.Rows[0][j].ToString());
  594. ChoosedRejectList.Items.Add(lvi);
  595. bc_code.Clear();
  596. }
  597. else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
  598. }
  599. }
  600. private void LoadCheckQTY()
  601. {
  602. sql.Clear();
  603. string condition = "";
  604. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  605. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  606. if (nowcheckqty + 1 == batchqty && AutoCut)
  607. {
  608. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  609. }
  610. else
  611. {
  612. condition = "and ob_status='ENTERING' ";
  613. }
  614. if (pr_sendchecktype.Text == "SaleCode")
  615. {
  616. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  617. }
  618. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  619. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  620. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  621. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  622. if (dt.Rows.Count > 0)
  623. {
  624. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  625. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  626. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  627. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  628. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  629. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  630. if (nowcheckqty == batchqty)
  631. {
  632. ob_nowcheckqty.ForeColor = Color.Red;
  633. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  634. if (AutoCut)
  635. {
  636. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Blue);
  637. }
  638. }
  639. }
  640. else
  641. {
  642. BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno);
  643. SendCheck.Enabled = false;
  644. }
  645. if (ob_batchqty.Text != "")
  646. {
  647. SendCheck.Enabled = true;
  648. }
  649. else
  650. {
  651. SendCheck.Enabled = false;
  652. }
  653. }
  654. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  655. {
  656. if (GoodProduct.Checked)
  657. {
  658. bc_code.Enabled = false;
  659. WaitReject.Enabled = false;
  660. ChooseedReject.Enabled = false;
  661. Save.Visible = false;
  662. ReleaseSN.Enabled = false;
  663. }
  664. else
  665. {
  666. ReleaseSN.Enabled = true;
  667. bc_code.Enabled = true;
  668. WaitReject.Enabled = true;
  669. ChooseedReject.Enabled = true;
  670. Save.Visible = true;
  671. }
  672. if (ms_sncode.Text == "")
  673. {
  674. ms_sncode.Focus();
  675. }
  676. }
  677. private void SendCheck_Click(object sender, EventArgs e)
  678. {
  679. sql.Clear();
  680. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  681. dh.ExecuteSql(sql.GetString(), "select");
  682. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  683. ob_nowcheckqty.Text = "";
  684. ob_batchqty.Text = "";
  685. ob_nowcheckqty.ForeColor = Color.Black;
  686. SendCheck.Enabled = false;
  687. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue);
  688. ms_sncode.Focus();
  689. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  690. //记录操作日志
  691. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  692. ob_checkno.Text = "";
  693. }
  694. private void ob_checkno_TextChanged(object sender, EventArgs e)
  695. {
  696. if (ob_checkno.Text != "")
  697. {
  698. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  699. if (Cut == "" || Cut == "0")
  700. AutoCut = false;
  701. else
  702. AutoCut = true;
  703. SendCheck.Enabled = true;
  704. }
  705. }
  706. /// <summary>
  707. /// 工单变化修改数量
  708. /// </summary>
  709. /// <param name="sender"></param>
  710. /// <param name="e"></param>
  711. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  712. {
  713. if (ma_code.Text.Length > 4)
  714. {
  715. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty);
  716. LoadCollectedNum();
  717. LoadCheckQTY();
  718. }
  719. }
  720. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  721. {
  722. dh.Dispose();
  723. }
  724. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  725. {
  726. LoadBadGroupData();
  727. }
  728. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  729. {
  730. try
  731. {
  732. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  733. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  734. for (int i = 0; i < dr.Length; i++)
  735. {
  736. dt.Rows.Add(dr[i].ItemArray);
  737. }
  738. WaitRejectList.Items.Clear();
  739. WaitRejectList.BeginUpdate();
  740. for (int i = 0; i < dt.Rows.Count; i++)
  741. {
  742. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  743. {
  744. ListViewItem lvi = new ListViewItem();
  745. //第一列是勾选列,设置列头文本为空
  746. lvi.Text = "";
  747. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  748. for (int j = 0; j < dt.Columns.Count; j++)
  749. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  750. WaitRejectList.Items.Add(lvi);
  751. }
  752. }
  753. WaitRejectList.EndUpdate();
  754. }
  755. catch (Exception)
  756. {
  757. }
  758. }
  759. private void WaitRejectList_DoubleClick(object sender, EventArgs e)
  760. {
  761. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  762. {
  763. if (WaitRejectList.Items[i].Checked)
  764. {
  765. //双击右移
  766. ChooseedReject.PerformClick();
  767. }
  768. }
  769. }
  770. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  771. {
  772. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  773. {
  774. if (!LockSn)
  775. {
  776. ControlLockTimer.Start();
  777. LockSn = true;
  778. Lock_label.Visible = true;
  779. }
  780. else
  781. {
  782. ControlLockTimer.Stop();
  783. LockSn = false;
  784. Lock_label.Visible = false;
  785. }
  786. }
  787. }
  788. private void RePrint_Click(object sender, EventArgs e)
  789. {
  790. if (EnablePrint && AutoPrintBad.Checked)
  791. {
  792. string[] bcname = RePrintCode.ToArray();
  793. for (int i = 0; i < bcname.Length; i++)
  794. {
  795. RePrintCode.Add(bcname[i]);
  796. format.SubStrings["SN1"].Value = bcname[i];
  797. format.PrintSetup.PrinterName = Printer.Text;
  798. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  799. format.Print();
  800. }
  801. }
  802. }
  803. private void WriteSoftWare_CheckedChanged(object sender, EventArgs e)
  804. {
  805. }
  806. private void ReleaseSN_Click(object sender, EventArgs e)
  807. {
  808. Save_Click(sender, e);
  809. DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode from makeserial where ms_id='" + oMSID + "'", "select");
  810. if (dt.Rows.Count > 0)
  811. {
  812. string ms_sncode = dt.Rows[0]["ms_sncode"].ToString();
  813. string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  814. dh.ExecuteSql("delete from sninfo where si_sn='" + ms_sncode + "'", "delete");
  815. dh.ExecuteSql("delete from makesnrelation where sn='" + ms_sncode + "' and makecode='" + ms_makecode + "'", "delete");
  816. 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");
  817. OperateResult.AppendText(">>" + ms_sncode + "解绑成功\n", Color.Green);
  818. }
  819. else
  820. {
  821. OperateResult.AppendText(">>" + ms_sncode.Text + "没有需要解绑的内容\n", Color.Red);
  822. }
  823. }
  824. }
  825. }