Make_TestCollectionModule.cs 46 KB

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