Make_TestCollection.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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.Properties;
  13. using System.IO;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_TestCollection : Form
  17. {
  18. DataHelper dh = null;
  19. DataTable dt = null;
  20. //当前工序的名称
  21. string ErrorMessage = "";
  22. //用于保存是否之前输入的ms_sncode
  23. string LastSncode;
  24. string oMakeCode = "";
  25. string oMSID = "";
  26. string ifrework = "";
  27. string reworkstatus = "";
  28. LogStringBuilder sql = new LogStringBuilder();
  29. AutoSizeFormClass asc = new AutoSizeFormClass();
  30. Boolean startcheck = false;
  31. int getcheck = 0;
  32. Dictionary <string,DateTime> dateTimeDictionary = new Dictionary<string, DateTime>();
  33. /// <summary>
  34. /// 已选的不良
  35. /// </summary>
  36. List<string> ChoosedList = new List<string>();
  37. /// <summary>
  38. /// 待选的不良
  39. /// </summary>
  40. List<string> WaitList = new List<string>();
  41. bool AutoCut = false;
  42. bool LockSn = false;
  43. DataTable Dbfind;
  44. public Make_TestCollection()
  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.GotFocus += text_getfocus;
  53. ms_sncode.Focus();
  54. //设置锁定工单
  55. LockMakeCode.GetMakeCodeCtl(ma_code);
  56. ma_code.SetLockCheckBox(LockMakeCode);
  57. ControlLockTimer.Tick += ControlLockTimer_Tick;
  58. ControlLockTimer.Interval = 100;
  59. SMTBind.Checked = Settings.Default.SMTBIND;
  60. Control.CheckForIllegalCrossThreadCalls = false;
  61. FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
  62. //工单号放大镜配置
  63. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  64. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  65. ma_code.FormName = Name;
  66. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  67. ma_code.Condition = "ma_statuscode='STARTED'";
  68. ma_code.DbChange += Ma_code_DbChange;
  69. dh = SystemInf.dh;
  70. StepCount.StepCode = User.CurrentStepCode;
  71. StepCount.Source = User.UserSourceCode;
  72. StepCount.LineCode = User.UserLineCode;
  73. StepCount.Dh = dh;
  74. StepCount.Start();
  75. }
  76. private void text_getfocus(object sender, EventArgs e)
  77. {
  78. ms_sncode.ImeMode = ImeMode.Close;
  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. ChoosedRejectList.Items.Clear();
  175. WaitList.Clear();
  176. ChoosedList.Clear();
  177. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  178. {
  179. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  180. if (!NoteAlready)
  181. {
  182. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  183. return;
  184. }
  185. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  186. {
  187. //是否提示过工单切换框,检测前后执行
  188. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  189. {
  190. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  191. return;
  192. }
  193. if (ma_code.Text != oMakeCode && oMakeCode != null)
  194. {
  195. 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");
  196. if (dt.Rows.Count > 0)
  197. {
  198. BaseUtil.SetFormValue(this.Controls, dt);
  199. LockMakeCode.Checked = true;
  200. }
  201. }
  202. 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");
  203. string status = dt.Rows[0]["ms_status"].ToString();
  204. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  205. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  206. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  207. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  208. if (sncode != ms_sncode.Text)
  209. {
  210. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  211. return;
  212. }
  213. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  214. if (GoodProduct.Checked)
  215. {
  216. if (ifrework != "0")
  217. {
  218. if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
  219. {
  220. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Black, ms_sncode);
  221. return;
  222. }
  223. }
  224. else
  225. {
  226. if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
  227. {
  228. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Black, ms_sncode);
  229. return;
  230. }
  231. }
  232. }
  233. SetCollectResult();
  234. }
  235. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  236. }
  237. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  238. }
  239. }
  240. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  241. {
  242. LoadBadCodeListView();
  243. }
  244. /// <summary>
  245. /// 填充不良组别信息
  246. /// </summary>
  247. private void LoadBadGroupData()
  248. {
  249. //如果ms_makecode的值修改过再去查询
  250. sql.Clear();
  251. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  252. sql.Append("from product left join productkind on pk_name=pr_kind ");
  253. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  254. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  255. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  256. bc_groupcode.DisplayMember = "bg_name";
  257. bc_groupcode.ValueMember = "bg_code";
  258. bc_groupcode.DataSource = dt;
  259. }
  260. /// <summary>
  261. /// 加载不良代码的ListView的信息
  262. /// </summary>
  263. private void LoadBadCodeListView()
  264. {
  265. object bg_code = bc_groupcode.SelectedValue;
  266. sql.Clear();
  267. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  268. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  269. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  270. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  271. BadInfSource.DataSource = dt;
  272. //往listview中添加数据
  273. WaitRejectList.Items.Clear();
  274. WaitRejectList.BeginUpdate();
  275. for (int i = 0; i < dt.Rows.Count; i++)
  276. {
  277. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  278. {
  279. ListViewItem lvi = new ListViewItem();
  280. //第一列是勾选列,设置列头文本为空
  281. lvi.Text = "";
  282. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  283. for (int j = 0; j < dt.Columns.Count; j++)
  284. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  285. WaitRejectList.Items.Add(lvi);
  286. }
  287. }
  288. WaitRejectList.EndUpdate();
  289. }
  290. /// <summary>
  291. /// 加载已选不良的ListView
  292. /// </summary>
  293. private void LoadChoosedBadListView()
  294. {
  295. sql.Clear();
  296. 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 ");
  297. sql.Append("left join badgroup on mb_bgcode=bg_code left join badcode on mb_badcode=bc_code ");
  298. sql.Append(" where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0");
  299. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  300. ChoosedRejectList.Items.Clear();
  301. ChoosedRejectList.BeginUpdate();
  302. for (int i = 0; i < dt.Rows.Count; i++)
  303. {
  304. ListViewItem lvi = new ListViewItem();
  305. //第一列是勾选列,设置列头文本为空
  306. lvi.Text = "";
  307. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  308. for (int j = 0; j < dt.Columns.Count; j++)
  309. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  310. ChoosedRejectList.Items.Add(lvi);
  311. }
  312. ChoosedRejectList.EndUpdate();
  313. }
  314. /// <summary>
  315. /// 设置良品或者不良品的采集结果
  316. /// </summary>
  317. private void SetCollectResult()
  318. {
  319. string ErrorMessage = "";
  320. //如果勾选的是不良品
  321. if (Reject.Checked)
  322. {
  323. LoadBadCodeListView();
  324. LoadChoosedBadListView();
  325. OperateResult.AppendText(">>请采集不良代码\n", Color.Green);
  326. bc_code.Focus();
  327. ////勾选了自动产生代码
  328. //if (AutoBadCode.Checked)
  329. // Save_Click(new object(), new EventArgs());
  330. if (ms_sncode.Text == "")
  331. {
  332. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  333. return;
  334. }
  335. if (GoodProduct.Checked)
  336. ms_code_KeyDown_one(this, new KeyEventArgs(Keys.Enter));
  337. else if (Reject.Checked)
  338. {
  339. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  340. {
  341. //判断界面工单是否为空时的序列号是否自动归属工单
  342. string oStatus = "";
  343. if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
  344. {
  345. if (ma_code.Text == "")
  346. {
  347. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  348. return;
  349. }
  350. }
  351. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  352. {
  353. 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");
  354. if (dt.Rows.Count > 0)
  355. {
  356. BaseUtil.SetFormValue(this.Controls, dt);
  357. LockMakeCode.Checked = true;
  358. }
  359. }
  360. else
  361. {
  362. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  363. return;
  364. }
  365. }
  366. else
  367. {
  368. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  369. return;
  370. }
  371. int RejectCount = ChoosedRejectList.Items.Count;
  372. string[] bccode = new string[RejectCount];
  373. string[] bcremark = new string[RejectCount];
  374. string[] bgcode = new string[RejectCount];
  375. string[] bgname = new string[RejectCount];
  376. string[] bcname = new string[RejectCount];
  377. if (AutoBadCode.Checked)
  378. {
  379. string defaultvalue = Properties.Settings.Default.DefaultCollectionValue;
  380. bccode = new string[] { defaultvalue };
  381. bcremark = new string[] { defaultvalue };
  382. bgcode = new string[] { defaultvalue };
  383. bgname = new string[] { defaultvalue };
  384. bcname = new string[] { defaultvalue };
  385. }
  386. else
  387. {
  388. if (ChoosedRejectList.Items.Count == 0)
  389. {
  390. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  391. return;
  392. }
  393. else
  394. {
  395. for (int i = 0; i < RejectCount; i++)
  396. {
  397. //获取不良代码组
  398. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  399. //获取不良代码组名称
  400. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  401. //获取所有的不良代码
  402. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  403. //获取不良名称
  404. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  405. //获取所有的不良备注
  406. bcremark[i] = bc_remark.Text;
  407. }
  408. }
  409. }
  410. //如果之前是良品的
  411. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  412. if (dt.Rows.Count > 0)
  413. {
  414. string status = dt.Rows[0]["ms_status"].ToString();
  415. if (status == "1" || status == "2")
  416. {
  417. 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 + "')");
  418. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  419. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  420. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
  421. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
  422. }
  423. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  424. //存在抽检批次更新为空
  425. if (checkno != "")
  426. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  427. }
  428. else
  429. {
  430. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
  431. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
  432. }
  433. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  434. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  435. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", out ErrorMessage))
  436. {
  437. ////存在的不良代码和
  438. //dt = (DataTable)dh.ExecuteSql("select sr_badcode from STEPRETURN where sr_stepcode='" + User.CurrentStepCode + "'", "select");
  439. //if (dt.Rows.Count > 0)
  440. //{
  441. // int BadCodeInStep = 0;
  442. // string badname = "";
  443. // for (int i = 0; i < dt.Rows.Count; i++)
  444. // {
  445. // for (int j = 0; j < bccode.Length; j++)
  446. // {
  447. // if (dt.Rows[i]["sr_badcode"].ToString() == bccode[j])
  448. // {
  449. // badname += "[" + bcname[j] + "]";
  450. // BadCodeInStep += 1;
  451. // }
  452. // }
  453. // }
  454. // //选中的不良代码必须全在工序默认的不良代码中才通过判断
  455. // if (BadCodeInStep == bccode.Length)
  456. // {
  457. // dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_stepcode='" + User.CurrentStepCode + "'");
  458. // dh.UpdateByCondition("makeserial", "ms_stepcode='',ms_status=1,ms_nextstepcode='" + User.CurrentStepCode + "'", "ms_id='" + oMSID + "'");
  459. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修成功", "快速维修", "", ob_checkno.Text);
  460. // OperateResult.AppendText(">>本次采集不良代码" + badname + "存在于本工序" + User.CurrentStepCode + "中,请解除故障后重新测试本站\n", Color.Black);
  461. // }
  462. // else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  463. //}
  464. //else
  465. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  466. LastSncode = ms_sncode.Text;
  467. //采集完不良,聚焦序列号
  468. ms_sncode.Focus();
  469. //记录操作日志
  470. ms_sncode.Text = "";
  471. //清除不良信息
  472. bc_code.Text = "";
  473. ChoosedRejectList.Items.Clear();
  474. LoadCollectedNum();
  475. WaitList.Clear();
  476. ChoosedList.Clear();
  477. }
  478. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  479. }
  480. }
  481. else if (GoodProduct.Checked)
  482. {
  483. //如果不是返修的
  484. if (ifrework == "0")
  485. {
  486. 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");
  487. for (int i = 0; i < dt.Rows.Count; i++)
  488. {
  489. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  490. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  491. }
  492. //存在不良记录
  493. if (ErrorMessage != "")
  494. {
  495. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  496. return;
  497. }
  498. else
  499. {
  500. //良品信息采集
  501. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  502. {
  503. LastSncode = ms_sncode.Text;
  504. //提示正确返回时传递的信息
  505. if (ErrorMessage.Contains("AFTERSUCCESS"))
  506. {
  507. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功 " + ErrorMessage + "\n", Color.Blue, ms_sncode);
  508. getcheck++;
  509. }
  510. else
  511. {
  512. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
  513. getcheck++;
  514. }
  515. //记录操作日志
  516. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  517. if (!startcheck)
  518. {
  519. startcheck = true;
  520. Thread thread = new Thread(NewPrint); ;
  521. thread.Start();
  522. }
  523. }
  524. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  525. }
  526. }
  527. else
  528. {
  529. if (reworkstatus != "3")
  530. {
  531. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  532. {
  533. //提示正确返回时传递的信息
  534. if (ErrorMessage.Contains("AFTERSUCCESS"))
  535. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  536. LastSncode = ms_sncode.Text;
  537. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
  538. //记录操作日志
  539. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  540. }
  541. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  542. }
  543. else
  544. {
  545. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  546. }
  547. }
  548. }
  549. //加载页面信息
  550. LoadCollectedNum();
  551. LoadCheckQTY();
  552. }
  553. private void NewPrint()
  554. {
  555. Thread.Sleep(9000);
  556. oneget.Text = getcheck.ToString();
  557. getcheck = 0;
  558. startcheck = false;
  559. }
  560. private void 测试采集_SizeChanged(object sender, EventArgs e)
  561. {
  562. asc.controlAutoSize(this);
  563. }
  564. private void LoadCollectedNum()
  565. {
  566. dt = (DataTable)dh.ExecuteSql("select mcd_detno,mcd_stepcode,mcd_stepname,nvl(count(distinct A.ms_sncode),0) n,nvl(count(distinct B.ms_sncode),0) bn,(select nvl(count(distinct sp_sncode),0) from STEPPASSED where SP_MAKECODE = mcd_macode AND SP_STEPCODE = mcd_stepcode) mcd_inqty,(select nvl(count(distinct sp_sncode),0) from STEPPASSED where SP_MAKECODE = mcd_macode AND SP_STEPCODE = mcd_stepcode)-nvl(count(distinct B.ms_sncode),0) mcd_remainqty from MAKECRAFTdetail left join makeserial A on mcd_macode = A.ms_makecode and mcd_stepcode = A.ms_nextstepcode AND A.MS_STATUS = 1 LEFT JOIN MAKESERIAL B ON mcd_macode = B.ms_makecode AND MCD_STEPCODE = B.MS_STEPCODE AND B.MS_STATUS = 3 where mcd_macode = '"+ ma_code.Text + "' and mcd_stepcode = '"+ User.CurrentStepCode + "' group by mcd_macode,mcd_detno, mcd_stepcode, mcd_stepname order by mcd_detno asc", "select");
  567. BaseUtil.SetFormValue(Controls, dt);
  568. }
  569. private void Save_Click(object sender, EventArgs e)
  570. {
  571. if (ms_sncode.Text == "")
  572. {
  573. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  574. return;
  575. }
  576. if (GoodProduct.Checked)
  577. ms_code_KeyDown_one(sender, new KeyEventArgs(Keys.Enter));
  578. else if (Reject.Checked)
  579. {
  580. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  581. {
  582. //判断界面工单是否为空时的序列号是否自动归属工单
  583. string oStatus = "";
  584. if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
  585. {
  586. if (ma_code.Text == "")
  587. {
  588. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  589. return;
  590. }
  591. }
  592. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  593. {
  594. 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");
  595. if (dt.Rows.Count > 0)
  596. {
  597. BaseUtil.SetFormValue(this.Controls, dt);
  598. LockMakeCode.Checked = true;
  599. }
  600. }
  601. else
  602. {
  603. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  604. return;
  605. }
  606. }
  607. else
  608. {
  609. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  610. return;
  611. }
  612. int RejectCount = ChoosedRejectList.Items.Count;
  613. string[] bccode = new string[RejectCount];
  614. string[] bcremark = new string[RejectCount];
  615. string[] bgcode = new string[RejectCount];
  616. string[] bgname = new string[RejectCount];
  617. string[] bcname = new string[RejectCount];
  618. if (AutoBadCode.Checked)
  619. {
  620. string defaultvalue = Properties.Settings.Default.DefaultCollectionValue;
  621. bccode = new string[] { defaultvalue };
  622. bcremark = new string[] { defaultvalue };
  623. bgcode = new string[] { defaultvalue };
  624. bgname = new string[] { defaultvalue };
  625. bcname = new string[] { defaultvalue };
  626. }
  627. else
  628. {
  629. if (ChoosedRejectList.Items.Count == 0)
  630. {
  631. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  632. return;
  633. }
  634. else
  635. {
  636. for (int i = 0; i < RejectCount; i++)
  637. {
  638. //获取不良代码组
  639. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  640. //获取不良代码组名称
  641. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  642. //获取所有的不良代码
  643. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  644. //获取不良名称
  645. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  646. //获取所有的不良备注
  647. bcremark[i] = bc_remark.Text;
  648. }
  649. }
  650. }
  651. //如果之前是良品的
  652. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  653. if (dt.Rows.Count > 0)
  654. {
  655. string status = dt.Rows[0]["ms_status"].ToString();
  656. if (status == "1" || status == "2")
  657. {
  658. 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 + "')");
  659. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  660. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  661. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
  662. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
  663. }
  664. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  665. //存在抽检批次更新为空
  666. if (checkno != "")
  667. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  668. }
  669. else
  670. {
  671. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
  672. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
  673. }
  674. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  675. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  676. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
  677. {
  678. //存在的不良代码和
  679. dt = (DataTable)dh.ExecuteSql("select sr_badcode from STEPRETURN where sr_stepcode='" + User.CurrentStepCode + "'", "select");
  680. if (dt.Rows.Count > 0)
  681. {
  682. int BadCodeInStep = 0;
  683. string badname = "";
  684. for (int i = 0; i < dt.Rows.Count; i++)
  685. {
  686. for (int j = 0; j < bccode.Length; j++)
  687. {
  688. if (dt.Rows[i]["sr_badcode"].ToString() == bccode[j])
  689. {
  690. badname += "[" + bcname[j] + "]";
  691. BadCodeInStep += 1;
  692. }
  693. }
  694. }
  695. //选中的不良代码必须全在工序默认的不良代码中才通过判断
  696. if (BadCodeInStep == bccode.Length)
  697. {
  698. dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_stepcode='" + User.CurrentStepCode + "'");
  699. dh.UpdateByCondition("makeserial", "ms_stepcode='',ms_status=1,ms_nextstepcode='" + User.CurrentStepCode + "'", "ms_id='" + oMSID + "'");
  700. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修成功", "快速维修", "", ob_checkno.Text);
  701. OperateResult.AppendText(">>本次采集不良代码" + badname + "存在于本工序" + User.CurrentStepCode + "中,请解除故障后重新测试本站\n", Color.Black);
  702. }
  703. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  704. }
  705. else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  706. LastSncode = ms_sncode.Text;
  707. //采集完不良,聚焦序列号
  708. ms_sncode.Focus();
  709. //记录操作日志
  710. ms_sncode.Text = "";
  711. //清除不良信息
  712. bc_code.Text = "";
  713. ChoosedRejectList.Items.Clear();
  714. LoadCollectedNum();
  715. WaitList.Clear();
  716. ChoosedList.Clear();
  717. }
  718. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  719. }
  720. }
  721. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  722. {
  723. if (e.KeyCode == Keys.Enter)
  724. {
  725. sql.Clear();
  726. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
  727. 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 ");
  728. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  729. if (dt.Rows.Count > 0)
  730. {
  731. for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  732. {
  733. if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
  734. {
  735. OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
  736. return;
  737. }
  738. }
  739. ListViewItem lvi = new ListViewItem();
  740. lvi.Text = "";
  741. for (int j = 0; j < dt.Columns.Count; j++)
  742. lvi.SubItems.Add(dt.Rows[0][j].ToString());
  743. ChoosedRejectList.Items.Add(lvi);
  744. bc_code.Clear();
  745. }
  746. else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
  747. }
  748. }
  749. private void LoadCheckQTY()
  750. {
  751. sql.Clear();
  752. string condition = "";
  753. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  754. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  755. if (nowcheckqty + 1 == batchqty && AutoCut)
  756. {
  757. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  758. }
  759. else
  760. {
  761. condition = "and ob_status='ENTERING' ";
  762. }
  763. if (pr_sendchecktype.Text == "SaleCode")
  764. {
  765. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  766. }
  767. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  768. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  769. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  770. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  771. if (dt.Rows.Count > 0)
  772. {
  773. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  774. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  775. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  776. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  777. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  778. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  779. if (nowcheckqty == batchqty)
  780. {
  781. ob_nowcheckqty.ForeColor = Color.Red;
  782. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  783. if (AutoCut)
  784. {
  785. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Blue);
  786. }
  787. }
  788. }
  789. else
  790. {
  791. BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno);
  792. SendCheck.Enabled = false;
  793. }
  794. if (ob_batchqty.Text != "")
  795. {
  796. SendCheck.Enabled = true;
  797. }
  798. else
  799. {
  800. SendCheck.Enabled = false;
  801. }
  802. }
  803. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  804. {
  805. if (GoodProduct.Checked)
  806. {
  807. bc_code.Enabled = false;
  808. WaitReject.Enabled = false;
  809. ChooseedReject.Enabled = false;
  810. Save.Visible = false;
  811. }
  812. else
  813. {
  814. bc_code.Enabled = true;
  815. WaitReject.Enabled = true;
  816. ChooseedReject.Enabled = true;
  817. Save.Visible = true;
  818. }
  819. if (ms_sncode.Text == "")
  820. {
  821. ms_sncode.Focus();
  822. }
  823. }
  824. private void SendCheck_Click(object sender, EventArgs e)
  825. {
  826. sql.Clear();
  827. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  828. dh.ExecuteSql(sql.GetString(), "select");
  829. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  830. ob_nowcheckqty.Text = "";
  831. ob_batchqty.Text = "";
  832. ob_nowcheckqty.ForeColor = Color.Black;
  833. SendCheck.Enabled = false;
  834. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue);
  835. ms_sncode.Focus();
  836. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  837. //记录操作日志
  838. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  839. ob_checkno.Text = "";
  840. }
  841. private void ob_checkno_TextChanged(object sender, EventArgs e)
  842. {
  843. if (ob_checkno.Text != "")
  844. {
  845. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  846. if (Cut == "" || Cut == "0")
  847. AutoCut = false;
  848. else
  849. AutoCut = true;
  850. SendCheck.Enabled = true;
  851. }
  852. }
  853. /// <summary>
  854. /// 工单变化修改数量
  855. /// </summary>
  856. /// <param name="sender"></param>
  857. /// <param name="e"></param>
  858. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  859. {
  860. if (ma_code.Text.Length > 4)
  861. {
  862. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty);
  863. LoadCollectedNum();
  864. LoadCheckQTY();
  865. }
  866. }
  867. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  868. {
  869. dh.Dispose();
  870. }
  871. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  872. {
  873. LoadBadGroupData();
  874. }
  875. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  876. {
  877. try
  878. {
  879. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  880. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  881. for (int i = 0; i < dr.Length; i++)
  882. {
  883. dt.Rows.Add(dr[i].ItemArray);
  884. }
  885. WaitRejectList.Items.Clear();
  886. WaitRejectList.BeginUpdate();
  887. for (int i = 0; i < dt.Rows.Count; i++)
  888. {
  889. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  890. {
  891. ListViewItem lvi = new ListViewItem();
  892. //第一列是勾选列,设置列头文本为空
  893. lvi.Text = "";
  894. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  895. for (int j = 0; j < dt.Columns.Count; j++)
  896. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  897. WaitRejectList.Items.Add(lvi);
  898. }
  899. }
  900. WaitRejectList.EndUpdate();
  901. }
  902. catch (Exception)
  903. {
  904. }
  905. }
  906. private void WaitRejectList_DoubleClick(object sender, EventArgs e)
  907. {
  908. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  909. {
  910. if (WaitRejectList.Items[i].Checked)
  911. {
  912. //双击右移
  913. ChooseedReject.PerformClick();
  914. }
  915. }
  916. }
  917. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  918. {
  919. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  920. {
  921. if (!LockSn)
  922. {
  923. ControlLockTimer.Start();
  924. LockSn = true;
  925. Lock_label.Visible = true;
  926. }
  927. else
  928. {
  929. ControlLockTimer.Stop();
  930. LockSn = false;
  931. Lock_label.Visible = false;
  932. }
  933. }
  934. }
  935. private void ms_code_KeyDown_one(object sender, KeyEventArgs e)
  936. {
  937. if (e.KeyCode == Keys.Enter)
  938. {
  939. if (SMTBind.Checked&& GoodProduct.Checked)
  940. {
  941. DataTable dt = (DataTable)dh.ExecuteSql("select A.SB_BARCODE from smtbind A LEFT JOIN SMTBIND B ON A.SB_MAINCODE = B.SB_MAINCODE WHERE B.SB_BARCODE = '" + ms_sncode.Text + "'", "select");
  942. if (dt.Rows.Count > 0)
  943. {
  944. for (int i = 0; i < dt.Rows.Count; i++)
  945. {
  946. ms_sncode.Text = dt.Rows[i]["sb_barcode"].ToString();
  947. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  948. }
  949. }
  950. else
  951. {
  952. OperateResult.AppendText(">>SN" + ms_sncode.Text + "未进行分板绑定\n", Color.Red, ms_sncode);
  953. }
  954. }
  955. else
  956. {
  957. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  958. }
  959. }
  960. }
  961. private void SMTBind_CheckedChanged(object sender, EventArgs e)
  962. {
  963. Settings.Default.SMTBIND = SMTBind.Checked;
  964. Settings.Default.Save();
  965. }
  966. private void StartWatch_Click(object sender, EventArgs e)
  967. {
  968. if (FolderPath.Text == "")
  969. {
  970. OperateResult.AppendText("请选择监控文件夹\n");
  971. return;
  972. }
  973. else
  974. {
  975. if (!Directory.Exists(FolderPath.Text))
  976. {
  977. OperateResult.AppendText("监控文件夹不存在\n");
  978. return;
  979. }
  980. }
  981. XmlWatcher.Path = FolderPath.Text;
  982. XmlWatcher.Filter = "*.csv";
  983. XmlWatcher.EnableRaisingEvents = true;
  984. //设置缓存数据
  985. BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
  986. //设置按钮不可点击
  987. StartWatch.Enabled = false;
  988. ChooseFolder.Enabled = false;
  989. StopWatch.Enabled = true;
  990. OperateResult.AppendText("开始执行监控\n");
  991. }
  992. private void StopWatch_Click(object sender, EventArgs e)
  993. {
  994. XmlWatcher.EnableRaisingEvents = false;
  995. StartWatch.Enabled = true;
  996. ChooseFolder.Enabled = true;
  997. StopWatch.Enabled = false;
  998. OperateResult.AppendText("停止执行监控\n");
  999. }
  1000. private void ChooseFolder_Click(object sender, EventArgs e)
  1001. {
  1002. FolderBrowserDialog folder = new FolderBrowserDialog();
  1003. folder.Description = "选择监控文件夹";
  1004. DialogResult result = folder.ShowDialog();
  1005. if (result == DialogResult.OK)
  1006. {
  1007. FolderPath.Text = folder.SelectedPath;
  1008. }
  1009. }
  1010. private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
  1011. {
  1012. //while (true)
  1013. //{
  1014. // try
  1015. // {
  1016. // using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
  1017. // {
  1018. // if (stream != null)
  1019. // break;
  1020. // }
  1021. // }
  1022. // catch (Exception ex)
  1023. // {
  1024. // Console.WriteLine(ex.Message);
  1025. // }
  1026. //}
  1027. //StreamReader _Sr = new StreamReader(FolderPath.Text + @"\" + e.Name, Encoding.UTF8);
  1028. //String[] strData;
  1029. //string line;
  1030. //while ((line = _Sr.ReadLine()) != null)
  1031. //{
  1032. // strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split(',');
  1033. // if (strData.Length > 5 && strData[0] == "ArrayID")
  1034. // {
  1035. // if (strData[5] != ""&& strData[5] != "NOREAD")
  1036. // {
  1037. // if (strData[3] == "Good"|| strData[3] == "Pass")
  1038. // {
  1039. // ms_sncode.Text = strData[5];
  1040. // ms_code_KeyDown(this, new KeyEventArgs(Keys.Enter));
  1041. // }
  1042. // else {
  1043. // OperateResult.AppendText(">>解析数据" + strData[5] + "非良品,无法采集\n", Color.Red, ms_sncode);
  1044. // }
  1045. // }
  1046. // }
  1047. //}
  1048. //_Sr.Close();
  1049. }
  1050. private void XmlWatcher_Changed(object sender, FileSystemEventArgs e)
  1051. {
  1052. if (e.ChangeType == WatcherChangeTypes.Changed || e.ChangeType == WatcherChangeTypes.Created)
  1053. {
  1054. Stream stream = null;
  1055. while (true)
  1056. {
  1057. try
  1058. {
  1059. using (stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
  1060. {
  1061. if (stream != null)
  1062. stream.Close();
  1063. break;
  1064. }
  1065. }
  1066. catch (Exception ex)
  1067. {
  1068. Console.WriteLine(ex.Message);
  1069. }
  1070. }
  1071. FileInfo fileInfo = new FileInfo(e.FullPath);
  1072. if (dateTimeDictionary.ContainsKey(e.FullPath))
  1073. {
  1074. if ((DateTime.Now - dateTimeDictionary[e.FullPath]).Seconds < 8)
  1075. {
  1076. return;
  1077. }
  1078. else
  1079. {
  1080. dateTimeDictionary.Remove(e.FullPath);
  1081. dateTimeDictionary.Add(e.FullPath, DateTime.Now);
  1082. }
  1083. }
  1084. else
  1085. {
  1086. dateTimeDictionary.Add(e.FullPath, DateTime.Now);
  1087. }
  1088. StreamReader _Sr = new StreamReader(e.FullPath, Encoding.UTF8);
  1089. String[] strData;
  1090. string line;
  1091. while ((line = _Sr.ReadLine()) != null)
  1092. {
  1093. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split(',');
  1094. if (strData.Length > 5 && strData[0] == "ArrayID")
  1095. {
  1096. if (strData[5] != "" && strData[5] != "NOREAD")
  1097. {
  1098. if (strData[3] == "Good" || strData[3] == "Pass")
  1099. {
  1100. ms_sncode.Text = strData[5];
  1101. ms_code_KeyDown(this, new KeyEventArgs(Keys.Enter));
  1102. }
  1103. else
  1104. {
  1105. OperateResult.AppendText(">>解析数据" + strData[5] + "非良品,无法采集\n", Color.Red, ms_sncode);
  1106. }
  1107. }
  1108. }
  1109. }
  1110. _Sr.Close();
  1111. }
  1112. }
  1113. private void normalButton2_Click(object sender, EventArgs e)
  1114. {
  1115. Make_NewDev badcode = new Make_NewDev(ma_code.Text, User.UserLineCode);
  1116. BaseUtil.SetFormCenter(badcode);
  1117. badcode.ShowDialog();
  1118. }
  1119. }
  1120. }