Make_TestCollectionCL.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. using System.Collections.Generic;
  11. using UAS_MES_NEW.CustomControl.PowerControlForm;
  12. using UAS_MES_NEW.PublicForm;
  13. using LabelManager2;
  14. using System.IO;
  15. using System.Text.RegularExpressions;
  16. using DevExpress.XtraSpellChecker;
  17. namespace UAS_MES_NEW.Make
  18. {
  19. public partial class Make_TestCollectionCL : Form
  20. {
  21. DataHelper dh = null;
  22. DataTable dt = null;
  23. //当前工序的名称
  24. string ErrorMessage = "";
  25. //用于保存是否之前输入的ms_sncode
  26. string LastSncode;
  27. string oMakeCode = "";
  28. string oMSID = "";
  29. string ifrework = "";
  30. string reworkstatus = "";
  31. LogStringBuilder sql = new LogStringBuilder();
  32. AutoSizeFormClass asc = new AutoSizeFormClass();
  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. string labelname;
  44. DataTable Dbfind;
  45. ApplicationClass lbl;
  46. Thread thread;
  47. // Document doc;
  48. public Make_TestCollectionCL()
  49. {
  50. InitializeComponent();
  51. }
  52. private void TestCollection_Load(object sender, EventArgs e)
  53. {
  54. GoodProduct.Checked = true;
  55. asc.controllInitializeSize(this);
  56. ms_sncode.Focus();
  57. //设置锁定工单
  58. LockMakeCode.GetMakeCodeCtl(ma_code);
  59. ma_code.SetLockCheckBox(LockMakeCode);
  60. ControlLockTimer.Tick += ControlLockTimer_Tick;
  61. ControlLockTimer.Interval = 100;
  62. labelname = System.Windows.Forms.Application.StartupPath + @"\badsn.lab";
  63. //thread = new Thread(NewPrint);
  64. // SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  65. //BaseUtil.SetFormCenter(stw);
  66. // stw.ShowDialog();
  67. //工单号放大镜配置
  68. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  69. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量, pr_orispeccode # 型号, ma_wccode # 车间,ma_inqty # 投入数,pr_spec # 产品规格";
  70. ma_code.FormName = Name;
  71. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_orispeccode pr_spec"};
  72. ma_code.Condition = "ma_statuscode='STARTED' order by ma_date desc";
  73. ma_code.DbChange += Ma_code_DbChange;
  74. dh = SystemInf.dh;
  75. mm_prodcode.TableName = "MakeMaterial left join make on mm_maid=ma_id left join Product on mm_prodcode=pr_code";
  76. mm_prodcode.SelectField = "mm_prodcode # 材料编号,pr_detail # 材料名称,pr_orispeccode # 材料型号";
  77. mm_prodcode.FormName = Name;
  78. mm_prodcode.Condition = " 1= 2";
  79. mm_prodcode.SetValueField = new string[] { "mm_prodcode", "pr_detail mmpr_detail", "pr_orispeccode mm_prorispeccode" };
  80. mm_prodcode.DbChange += Ma_code_DbChange1;
  81. }
  82. private void ControlLockTimer_Tick(object sender, EventArgs e)
  83. {
  84. this.Activate();
  85. ms_sncode.Focus();
  86. }
  87. private void Ma_code_DbChange(object sender, EventArgs e)
  88. {
  89. Dbfind = ma_code.ReturnData;
  90. BaseUtil.SetFormValue(this.Controls, Dbfind);
  91. LoadBadGroupData();
  92. //LoadCollectedNum();
  93. }
  94. private void Ma_code_DbChange1(object sender, EventArgs e)
  95. {
  96. Dbfind = mm_prodcode.ReturnData;
  97. BaseUtil.SetFormValue(this.Controls, Dbfind);
  98. //LoadBadGroupData();
  99. LoadCollectedNum();
  100. }
  101. /// <summary>
  102. /// 将已选不良移动到待选不良
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. private void WaitReject_Click(object sender, EventArgs e)
  107. {
  108. int CheckedNum = 0;
  109. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  110. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  111. {
  112. if (ChoosedRejectList.Items[i].Checked)
  113. {
  114. ChoosedRejectList.Items[i].Checked = false;
  115. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  116. ChoosedRejectList.Items[i].Remove();
  117. CheckedNum++;
  118. }
  119. }
  120. if (CheckedNum == 0)
  121. {
  122. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  123. {
  124. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  125. ChoosedRejectList.Items[i].Remove();
  126. }
  127. }
  128. }
  129. /// <summary>
  130. /// 将不良信息移动到已选不良
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. private void ChooseedReject_Click(object sender, EventArgs e)
  135. {
  136. if (ms_sncode.Text == "")
  137. {
  138. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  139. ms_sncode.Focus();
  140. return;
  141. }
  142. int CheckedNum = 0;
  143. //是否已经添加到不良
  144. bool AddToReject = false;
  145. if (ChoosedRejectList.Items.Count > 0)
  146. {
  147. OperateResult.AppendText(">>只可采集一个不良现象\n", Color.Red);
  148. return;
  149. }
  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. break;
  172. }
  173. }
  174. }
  175. if (CheckedNum == 0)
  176. {
  177. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  178. }
  179. }
  180. private void CleanInfo_Click(object sender, EventArgs e)
  181. {
  182. OperateResult.Clear();
  183. }
  184. private void ms_code_KeyDown(object sender, KeyEventArgs e)
  185. {
  186. if (e.KeyCode == Keys.Enter)
  187. {
  188. //if (ms_sncode.Text.Contains("EMPLOYEE:"))
  189. //{
  190. // biduisn.Text = ms_sncode.Text.Split(':')[1];
  191. // OperateResult.AppendText(">>采集人员编号"+ biduisn.Text+"\n", Color.Green, ms_sncode);
  192. // return;
  193. //}
  194. if (ms_sncode.Text.Contains("CHANGE:"))
  195. {
  196. GoodProduct.Checked = !GoodProduct.Checked;
  197. Reject.Checked = !GoodProduct.Checked;
  198. OperateResult.AppendText(">>切换良品不良采集\n", Color.Black, ms_sncode);
  199. return;
  200. }
  201. //if (bidui.Checked && biduisn.Text =="")
  202. //{
  203. // OperateResult.AppendText(">>勾选人员采集需先采集人员\n", Color.Red, ms_sncode);
  204. // return;
  205. //}
  206. if (ma_code.Text == "" || mm_prodcode.Text == "")
  207. {
  208. OperateResult.AppendText(">>工单号材料号不可为空\n", Color.Red, ms_sncode);
  209. return;
  210. }
  211. String priex = dh.getFieldDataByCondition("product", "pr_oriname", "pr_code = '"+mm_prodcode.Text+"'").ToString();
  212. if (priex == "")
  213. {
  214. OperateResult.AppendText(">>材料编号" + mm_prodcode.Text + "未维护防呆要求\n", Color.Red, ms_sncode);
  215. return;
  216. }
  217. string[] pres = priex.Split('|');
  218. bool f = false;
  219. for (int i = 0; i < pres.Length; i++)
  220. {
  221. if (pres[i] == "" ? true : ms_sncode.Text.Contains(pres[i]))
  222. {
  223. //满足其中一条即可
  224. f = true;
  225. break;
  226. }
  227. }
  228. if (!f)
  229. {
  230. OperateResult.AppendText(">>原材料号"+ms_sncode.Text+"不符合防呆要求\n", Color.Red, ms_sncode);
  231. return;
  232. }
  233. ChoosedRejectList.Items.Clear();
  234. WaitList.Clear();
  235. ChoosedList.Clear();
  236. if (dh.CheckExist("lcdcheck", "lc_sncode = '" + ms_sncode.Text + "' and LC_VALI = 0"))
  237. {
  238. string lcstatus = dh.getFieldDataByCondition("lcdcheck", "lc_status", "lc_sncode = '" + ms_sncode.Text + "' and LC_VALI = 0").ToString();
  239. if (lcstatus.Equals("0") != GoodProduct.Checked)
  240. {
  241. string ChangeMakeCode = System.Windows.Forms.MessageBox.Show("原材料" + ms_sncode.Text + "已存在不同采集记录,是否更新?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  242. //如果选择不切换赋值当前界面工单
  243. if (ChangeMakeCode != "Yes")
  244. {
  245. ms_sncode.Clear();
  246. return;
  247. }
  248. }
  249. else
  250. {
  251. OperateResult.AppendText(">>原材料号" + ms_sncode.Text + "已存在相同采集记录\n", Color.Red, ms_sncode);
  252. return;
  253. }
  254. }
  255. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_orispeccode pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  256. if (dt.Rows.Count > 0)
  257. {
  258. BaseUtil.SetFormValue(this.Controls, dt);
  259. LockMakeCode.Checked = true;
  260. }
  261. SetCollectResult();
  262. }
  263. }
  264. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  265. {
  266. LoadBadCodeListView();
  267. }
  268. /// <summary>
  269. /// 填充不良组别信息
  270. /// </summary>
  271. private void LoadBadGroupData()
  272. {
  273. //如果ms_makecode的值修改过再去查询
  274. sql.Clear();
  275. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  276. sql.Append("from product left join productkind on pk_name=pr_kind ");
  277. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  278. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  279. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  280. bc_groupcode.DisplayMember = "bg_name";
  281. bc_groupcode.ValueMember = "bg_code";
  282. bc_groupcode.DataSource = dt;
  283. }
  284. /// <summary>
  285. /// 加载不良代码的ListView的信息
  286. /// </summary>
  287. private void LoadBadCodeListView()
  288. {
  289. object bg_code = bc_groupcode.SelectedValue;
  290. sql.Clear();
  291. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  292. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  293. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  294. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  295. BadInfSource.DataSource = dt;
  296. //往listview中添加数据
  297. WaitRejectList.Items.Clear();
  298. WaitRejectList.BeginUpdate();
  299. for (int i = 0; i < dt.Rows.Count; i++)
  300. {
  301. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  302. {
  303. ListViewItem lvi = new ListViewItem();
  304. //第一列是勾选列,设置列头文本为空
  305. lvi.Text = "";
  306. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  307. for (int j = 0; j < dt.Columns.Count; j++)
  308. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  309. WaitRejectList.Items.Add(lvi);
  310. }
  311. }
  312. WaitRejectList.EndUpdate();
  313. }
  314. /// <summary>
  315. /// 加载已选不良的ListView
  316. /// </summary>
  317. private void LoadChoosedBadListView()
  318. {
  319. sql.Clear();
  320. 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 ");
  321. sql.Append("left join badgroup on mb_bgcode=bg_code left join badcode on mb_badcode=bc_code ");
  322. sql.Append(" where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0");
  323. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  324. ChoosedRejectList.Items.Clear();
  325. ChoosedRejectList.BeginUpdate();
  326. for (int i = 0; i < dt.Rows.Count; i++)
  327. {
  328. ListViewItem lvi = new ListViewItem();
  329. //第一列是勾选列,设置列头文本为空
  330. lvi.Text = "";
  331. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  332. for (int j = 0; j < dt.Columns.Count; j++)
  333. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  334. ChoosedRejectList.Items.Add(lvi);
  335. }
  336. if (!dh.CheckExist("makebad", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "'")&&(User.CurrentStepCode== "JIFMA"|| User.CurrentStepCode == "MOFMA"))
  337. {
  338. sql.Clear();
  339. sql.Append("select as_bgname||':'||as_bgcode bg_code,as_badcode bc_code,as_badname bc_name,'' mb_badremark from RETURNSNBD join AFSALES on rsb_oldsn = as_sn where rsb_newsn = '" + ms_sncode.Text + "' ");
  340. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  341. if (dt.Rows.Count > 0)
  342. {
  343. for (int i = 0; i < dt.Rows.Count; i++)
  344. {
  345. ListViewItem lvi = new ListViewItem();
  346. //第一列是勾选列,设置列头文本为空
  347. lvi.Text = "";
  348. ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
  349. for (int j = 0; j < dt.Columns.Count; j++)
  350. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  351. ChoosedRejectList.Items.Add(lvi);
  352. }
  353. }
  354. ChoosedRejectList.EndUpdate();
  355. }
  356. else
  357. {
  358. ChoosedRejectList.EndUpdate();
  359. }
  360. }
  361. /// <summary>
  362. /// 设置良品或者不良品的采集结果
  363. /// </summary>
  364. private void SetCollectResult()
  365. {
  366. string ErrorMessage = "";
  367. //如果勾选的是不良品
  368. if (Reject.Checked)
  369. {
  370. LoadBadCodeListView();
  371. LoadChoosedBadListView();
  372. OperateResult.AppendText(">>请采集不良代码\n", Color.Black);
  373. bc_code.Focus();
  374. }
  375. else if (GoodProduct.Checked)
  376. {
  377. LastSncode = ms_sncode.Text;
  378. lastsn.Text = ms_sncode.Text;
  379. lastresult.Text = "OK";
  380. lastresult.BackColor = Color.Green;
  381. dh.ExecuteSql(" update lcdcheck set LC_VALI = -1 where lc_sncode = '" + ms_sncode.Text + "' ", "update");
  382. dh.ExecuteSql(" insert into lcdcheck (lc_id,lc_sncode,lc_status,lc_indate,lc_inman,lc_makecode,lc_prodcode,LC_SOURCECODE) " +
  383. " values (lcdcheck_seq.nextval,'"+ms_sncode.Text+"',0,sysdate,'"+User.UserCode+"','"+ma_code.Text+"','"+ mm_prodcode.Text + "','"+User.UserSourceCode+"') ", "insert");
  384. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "原材料检验", "原材料检验良品", ms_sncode.Text, "");
  385. OperateResult.AppendText(">>SN:" + ms_sncode.Text + "原材料检验良品\n", Color.Green, ms_sncode);
  386. }
  387. //加载页面信息
  388. LoadCollectedNum();
  389. }
  390. private void 测试采集_SizeChanged(object sender, EventArgs e)
  391. {
  392. asc.controlAutoSize(this);
  393. }
  394. private void LoadCollectedNum()
  395. {
  396. //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");
  397. dt = (DataTable)dh.ExecuteSql(" select count(1) mcd_inqty,sum(case when lc_status = 0 then 1 else 0 end) mcd_okqty,sum(case when lc_status = -1 then 1 else 0 end) mcd_ngqty from lcdcheck " +
  398. "where lc_makecode = '"+ma_code.Text+"' and lc_prodcode = '"+mm_prodcode.Text+ "' and LC_VALI = 0 ", "select");
  399. BaseUtil.SetFormValue(Controls, dt);
  400. }
  401. private void Save_Click(object sender, EventArgs e)
  402. {
  403. if (ms_sncode.Text == "")
  404. {
  405. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  406. return;
  407. }
  408. if (GoodProduct.Checked)
  409. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  410. else if (Reject.Checked)
  411. {
  412. //判断界面工单是否为空时的序列号是否自动归属工单
  413. string oStatus = "";
  414. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,pr_orispeccode pr_spec,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  415. if (dt.Rows.Count > 0)
  416. {
  417. BaseUtil.SetFormValue(this.Controls, dt);
  418. LockMakeCode.Checked = true;
  419. }
  420. int RejectCount = ChoosedRejectList.Items.Count;
  421. string[] bccode = new string[RejectCount];
  422. string[] bcremark = new string[RejectCount];
  423. string[] bgcode = new string[RejectCount];
  424. string[] bgname = new string[RejectCount];
  425. string[] bcname = new string[RejectCount];
  426. if (ChoosedRejectList.Items.Count == 0)
  427. {
  428. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  429. return;
  430. }
  431. else
  432. {
  433. for (int i = 0; i < RejectCount; i++)
  434. {
  435. //获取不良代码组
  436. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  437. //获取不良代码组名称
  438. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  439. //获取所有的不良代码
  440. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  441. //获取不良名称
  442. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  443. //获取所有的不良备注
  444. bcremark[i] = bc_remark.Text;
  445. }
  446. }
  447. dh.ExecuteSql(" update lcdcheck set LC_VALI = -1 where lc_sncode = '" + ms_sncode.Text + "' ", "update");
  448. dh.ExecuteSql(" insert into lcdcheck (lc_id,lc_sncode,lc_status,lc_indate,lc_inman,lc_makecode,lc_prodcode,lc_badcode,lc_badname,lc_bgcode,lc_bgname,LC_SOURCECODE) " +
  449. " values (lcdcheck_seq.nextval,'" + ms_sncode.Text + "',-1,sysdate,'" + User.UserCode + "','" + ma_code.Text + "','" + mm_prodcode.Text + "','" + bccode[0] + "','" + bcname[0] + "','" + bgcode[0] + "','" + bgname[0] +"','"+User.UserSourceCode+"') ", "insert");
  450. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "原材料检验", "原材料检验不良", ms_sncode.Text, "");
  451. lastsn.Text = ms_sncode.Text;
  452. lastresult.Text = "FAILED";
  453. lastresult.BackColor = Color.Red;
  454. LastSncode = ms_sncode.Text;
  455. OperateResult.AppendText(">>SN:" + ms_sncode.Text + "原材料检验不良\n", Color.OrangeRed, ms_sncode);
  456. //normalButton1_Click(this, e);
  457. //if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, biduisn.Text == "" ? User.UserCode : biduisn.Text, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
  458. //{
  459. // for (int i = 0; i < bccode.Length; i++)
  460. // {
  461. // if (dh.CheckExist("badgroupdetail left join badgroup on bgd_bgid = bg_id", "bgd_badcode = '" + bccode[i] + "' and bg_code = '" + bgcode[i] + "' and bgd_brcode is not null and bgd_dutycode is not null and bgd_solutioncode is not null "))
  462. // {
  463. // string makebadid = dh.getFieldDataByCondition("makebad", "mb_id", "mb_sncode = '" + ms_sncode.Text + "' and mb_makecode = '" + ma_code.Text + "' and mb_badcode = '" + bccode[i] + "' order by mb_id desc").ToString();
  464. // DataTable temp = dh.getFieldsDatasByCondition(" badgroupdetail left join badgroup on bgd_bgid = bg_id left join QUA_NGReason on nr_code = bgd_brcode left join QUA_NGReasonGroup on nrg_code = bgd_brgcode left join NGDuty on nd_code = bgd_dutycode left join solution on so_code = bgd_solutioncode", new string[] { "bgd_brgcode", "bgd_dutycode", "bgd_solutioncode", "bgd_brcode", "nrg_name", "nr_name", "nd_name", "so_name" }, "bgd_badcode= '" + bccode[i] + "' and bg_code = '" + bgcode[i] + "'");
  465. // string bgd_brgcode = temp.Rows[0]["bgd_brgcode"].ToString();
  466. // string bgd_brcode = temp.Rows[0]["bgd_brcode"].ToString();
  467. // string bgd_dutycode = temp.Rows[0]["bgd_dutycode"].ToString();
  468. // string bgd_solutioncode = temp.Rows[0]["bgd_solutioncode"].ToString();
  469. // string mbr_id = dh.GetSEQ("makebadreason_seq");
  470. // string bgd_brgname = temp.Rows[0]["nrg_name"].ToString();
  471. // string bgd_brname = temp.Rows[0]["nr_name"].ToString();
  472. // string bgd_dutyname = temp.Rows[0]["nd_name"].ToString();
  473. // string bgd_solutionname = temp.Rows[0]["so_name"].ToString();
  474. // sql.Clear();
  475. // sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  476. // sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  477. // sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname) select '" + makebadid + "','" + mbr_id + "','" + bgd_brcode + "',");
  478. // sql.Append("'" + bgd_solutioncode + "','" + bgd_dutycode + "','" + bgd_brgcode + "','" + bccode[i] + "',");
  479. // sql.Append("'" + ms_sncode.Text + "','" + ma_code.Text + "',sysdate,'" + User.UserCode + "','" + bgd_brname + "','" + bgd_solutionname + "','" + bcname[i] + "','" + bgd_brgname + "','" + bgd_dutyname + "' from dual");
  480. // dh.ExecuteSql(sql.GetString(), "insert");
  481. // }
  482. //}
  483. //OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.OrangeRed);
  484. //采集完不良,聚焦序列号
  485. ms_sncode.Focus();
  486. //记录操作日志
  487. ms_sncode.Text = "";
  488. //清除不良信息
  489. bc_code.Text = "";
  490. biduisn.Text = "";
  491. if (bidui.Checked)
  492. {
  493. biduisn.Focus();
  494. }
  495. ChoosedRejectList.Items.Clear();
  496. LoadCollectedNum();
  497. WaitList.Clear();
  498. ChoosedList.Clear();
  499. //}
  500. //else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  501. }
  502. }
  503. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  504. {
  505. if (e.KeyCode == Keys.Enter)
  506. {
  507. sql.Clear();
  508. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
  509. 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 ");
  510. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  511. if (dt.Rows.Count > 0)
  512. {
  513. for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  514. {
  515. if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
  516. {
  517. OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
  518. return;
  519. }
  520. }
  521. ListViewItem lvi = new ListViewItem();
  522. lvi.Text = "";
  523. for (int j = 0; j < dt.Columns.Count; j++)
  524. lvi.SubItems.Add(dt.Rows[0][j].ToString());
  525. ChoosedRejectList.Items.Add(lvi);
  526. bc_code.Clear();
  527. }
  528. else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
  529. }
  530. }
  531. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  532. {
  533. if (GoodProduct.Checked)
  534. {
  535. bc_code.Enabled = false;
  536. WaitReject.Enabled = false;
  537. ChooseedReject.Enabled = false;
  538. Save.Visible = false;
  539. }
  540. else
  541. {
  542. bc_code.Enabled = true;
  543. WaitReject.Enabled = true;
  544. ChooseedReject.Enabled = true;
  545. Save.Visible = true;
  546. }
  547. if (ms_sncode.Text == "")
  548. {
  549. ms_sncode.Focus();
  550. }
  551. }
  552. private void ob_checkno_TextChanged(object sender, EventArgs e)
  553. {
  554. }
  555. /// <summary>
  556. /// 工单变化修改数量
  557. /// </summary>
  558. /// <param name="sender"></param>
  559. /// <param name="e"></param>
  560. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  561. {
  562. if (ma_code.Text.Length > 4)
  563. {
  564. BaseUtil.CleanControlsText(mcd_inqty, mcd_ngqty,mcd_okqty, mm_prodcode,mmpr_detail,mm_prorispeccode);
  565. mm_prodcode.Condition = "mm_code = '" + ma_code.Text + "' order by mm_prodcode desc";
  566. LoadCollectedNum();
  567. }
  568. }
  569. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  570. {
  571. //BaseUtil.ClosePrint(lbl);
  572. //if (engine != null)
  573. // engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  574. dh.Dispose();
  575. }
  576. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  577. {
  578. LoadBadGroupData();
  579. }
  580. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  581. {
  582. try
  583. {
  584. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  585. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  586. for (int i = 0; i < dr.Length; i++)
  587. {
  588. dt.Rows.Add(dr[i].ItemArray);
  589. }
  590. WaitRejectList.Items.Clear();
  591. WaitRejectList.BeginUpdate();
  592. for (int i = 0; i < dt.Rows.Count; i++)
  593. {
  594. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  595. {
  596. ListViewItem lvi = new ListViewItem();
  597. //第一列是勾选列,设置列头文本为空
  598. lvi.Text = "";
  599. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  600. for (int j = 0; j < dt.Columns.Count; j++)
  601. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  602. WaitRejectList.Items.Add(lvi);
  603. }
  604. }
  605. WaitRejectList.EndUpdate();
  606. }
  607. catch (Exception)
  608. {
  609. }
  610. }
  611. private void WaitRejectList_DoubleClick(object sender, EventArgs e)
  612. {
  613. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  614. {
  615. if (WaitRejectList.Items[i].Checked)
  616. {
  617. //双击右移
  618. ChooseedReject.PerformClick();
  619. }
  620. }
  621. }
  622. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  623. {
  624. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  625. {
  626. if (!LockSn)
  627. {
  628. ControlLockTimer.Start();
  629. LockSn = true;
  630. Lock_label.Visible = true;
  631. }
  632. else
  633. {
  634. ControlLockTimer.Stop();
  635. LockSn = false;
  636. Lock_label.Visible = false;
  637. }
  638. }
  639. }
  640. //创建打印进程
  641. private void NewPrint()
  642. {
  643. try
  644. {
  645. // engine = new BarTender.Application();
  646. lbl = new ApplicationClass();
  647. BaseUtil.WriteLbl();
  648. }
  649. catch (Exception ex)
  650. {
  651. OperateResult.AppendText("未正确安装CodeSoft软件\n" + ex.Message, Color.Red);
  652. }
  653. }
  654. private void normalButton1_Click(object sender, EventArgs e)
  655. {
  656. //if (ChoosedRejectList.Items.Count == 0 || ms_sncode.Text == "")
  657. //{
  658. // MessageBox.Show("未录入不良或SN为空");
  659. //}
  660. //string BADINFO = "";
  661. //for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
  662. //{
  663. // BADINFO = BADINFO + ChoosedRejectList.Items[i].ListView.Items[i].SubItems[3].Text + " ";
  664. //}
  665. //BADINFO = BADINFO.Substring(0, BADINFO.Length - 1);
  666. //FileInfo PrintFile = new FileInfo(labelname);
  667. //if (!PrintFile.Exists)
  668. //{
  669. // MessageBox.Show("打印文件不存在");
  670. // return ;
  671. //}
  672. //doc = lbl.Documents.Open(labelname, true);
  673. //if (doc == null)
  674. //{
  675. // MessageBox.Show("标签文件打开失败");
  676. // return ;
  677. //}
  678. //for (int j = 1; j < doc.Variables.FormVariables.Count+1; j++)
  679. //{
  680. // switch (doc.Variables.FormVariables.Item(j).Name)
  681. // {
  682. // case "SN":
  683. // doc.Variables.FormVariables.Item(j).Value = ms_sncode.Text;
  684. // break;
  685. // case "BAD":
  686. // doc.Variables.FormVariables.Item(j).Value = BADINFO;
  687. // break;
  688. // }
  689. // // doc.Variables.FormVariables.Item(1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (i).ToString()));
  690. //}
  691. ////保存本次赋值进行打印
  692. //doc.Printer.SwitchTo(PrintList.Text);
  693. //doc.PrintDocument(1);
  694. }
  695. private void StartWatch_Click(object sender, EventArgs e)
  696. {
  697. if (FolderPath.Text == "")
  698. {
  699. OperateResult.AppendText("请选择监控文件夹\n");
  700. return;
  701. }
  702. else
  703. {
  704. if (!Directory.Exists(FolderPath.Text))
  705. {
  706. OperateResult.AppendText("监控文件夹不存在\n");
  707. return;
  708. }
  709. }
  710. XmlWatcher.Path = FolderPath.Text;
  711. XmlWatcher.Filter = "SN Writer.log";
  712. XmlWatcher.EnableRaisingEvents = true;
  713. //设置缓存数据
  714. BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
  715. //设置按钮不可点击
  716. StartWatch.Enabled = false;
  717. ChooseFolder.Enabled = false;
  718. StopWatch.Enabled = true;
  719. OperateResult.AppendText("开始执行监控\n");
  720. }
  721. private void StopWatch_Click(object sender, EventArgs e)
  722. {
  723. XmlWatcher.EnableRaisingEvents = false;
  724. StartWatch.Enabled = true;
  725. ChooseFolder.Enabled = true;
  726. StopWatch.Enabled = false;
  727. OperateResult.AppendText("停止执行监控\n");
  728. }
  729. private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
  730. {
  731. while (true)
  732. {
  733. try
  734. {
  735. using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
  736. {
  737. if (stream != null)
  738. break;
  739. }
  740. }
  741. catch (Exception ex)
  742. {
  743. Console.WriteLine(ex.Message);
  744. }
  745. }
  746. StreamReader _Sr = new StreamReader(FolderPath.Text + @"\" + e.Name, Encoding.UTF8);
  747. String[] strData;
  748. string line;
  749. string ssn = "";
  750. string imei = "";
  751. string imei1 = "";
  752. string bt = "";
  753. string mac = "";
  754. try
  755. {
  756. while ((line = _Sr.ReadLine()) != null)
  757. {
  758. if (line.Contains("Barcode[0]"))
  759. {
  760. Regex regex = new Regex("\"[^\"]*\"");
  761. ssn = regex.Match(line).Value.Replace("\"", "");
  762. }
  763. else if (line.Contains("Prod_Info->IMEI[0]"))
  764. {
  765. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  766. Regex regex = new Regex("\\[[^*]+\\]");
  767. imei = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  768. }
  769. else if (line.Contains("Prod_Info->IMEI[1]"))
  770. {
  771. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  772. Regex regex = new Regex("\\[[^*]+\\]");
  773. imei1 = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  774. }
  775. else if (line.Contains("Prod_Info->BtAddress"))
  776. {
  777. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  778. Regex regex = new Regex("\\[[^*]+\\]");
  779. bt = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  780. }
  781. else if (line.Contains("Prod_Info->WiFiAddress"))
  782. {
  783. strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split('=');
  784. Regex regex = new Regex("\\[[^*]+\\]");
  785. mac = regex.Match(strData[1]).Value.Replace("[", "").Replace("]", "");
  786. }
  787. }
  788. if (ssn != "")
  789. {
  790. ms_sncode.Text = ssn;
  791. ms_code_KeyDown(this, new KeyEventArgs(Keys.Enter));
  792. if (imei!="")
  793. {
  794. dh.ExecuteSql("update makeserial set ms_imei = '"+imei+"' where ms_sncode = '"+ ssn + "' and ms_makecode = '"+ma_code.Text+"'", "update");
  795. }
  796. if (imei1 != "")
  797. {
  798. dh.ExecuteSql("update makeserial set ms_imei1 = '" + imei1 + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  799. }
  800. if (bt != "")
  801. {
  802. dh.ExecuteSql("update makeserial set ms_bt = '" + bt + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  803. }
  804. if (mac != "")
  805. {
  806. dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "' where ms_sncode = '" + ssn + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  807. }
  808. }
  809. }
  810. catch (Exception ex)
  811. {
  812. MessageBox.Show(ex.Message);
  813. _Sr.Close();
  814. }
  815. _Sr.Close();
  816. }
  817. private void ChooseFolder_Click(object sender, EventArgs e)
  818. {
  819. FolderBrowserDialog folder = new FolderBrowserDialog();
  820. folder.Description = "选择监控文件夹";
  821. DialogResult result = folder.ShowDialog();
  822. if (result == DialogResult.OK)
  823. {
  824. FolderPath.Text = folder.SelectedPath;
  825. }
  826. }
  827. private void biduisn_KeyDown(object sender, KeyEventArgs e)
  828. {
  829. if (e.KeyCode == Keys.Enter)
  830. {
  831. if (bidui.Checked&&biduisn.Text!="")
  832. {
  833. ms_sncode.Focus();
  834. ms_sncode.SelectAll();
  835. }
  836. }
  837. }
  838. private void bc_code_KeyUp(object sender, KeyEventArgs e)
  839. {
  840. if (e.KeyCode == Keys.Add && Save.Visible)
  841. {
  842. Save_Click(sender, e);
  843. bc_code.Clear();
  844. }
  845. }
  846. private void mm_prodcode_UserControlTextChanged(object sender, EventArgs e)
  847. {
  848. }
  849. }
  850. }