Make_TestCollectionBad.cs 41 KB

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