Make_TestCollectionOh.cs 46 KB

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