Make_TestCollection.cs 60 KB

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