Make_TestCollection.cs 43 KB

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