Make_TestCollectionOnlyBad.cs 42 KB

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