Make_SpiTestCollection.cs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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.DataOperate;
  8. using UAS_MES.Entity;
  9. using UAS_MES.PublicMethod;
  10. using System.Collections.Generic;
  11. using UAS_MES.CustomControl.PowerControlForm;
  12. namespace UAS_MES.Make
  13. {
  14. public partial class Make_SpiTestCollection : Form
  15. {
  16. DataHelper dh = null;
  17. DataTable dt = null;
  18. //当前工序的名称
  19. string ErrorMessage = "";
  20. //用于保存是否之前输入的ms_sncode
  21. string LastSncode;
  22. string oMakeCode = "";
  23. string oMSID = "";
  24. string ifrework = "";
  25. string reworkstatus = "";
  26. string status = "";
  27. LogStringBuilder sql = new LogStringBuilder();
  28. AutoSizeFormClass asc = new AutoSizeFormClass();
  29. /// <summary>
  30. /// 已选的不良
  31. /// </summary>
  32. List<string> ChoosedList = new List<string>();
  33. /// <summary>
  34. /// 待选的不良
  35. /// </summary>
  36. List<string> WaitList = new List<string>();
  37. //当前工序对应版面
  38. string st_table = "";
  39. bool AutoCut = false;
  40. bool LockSn = false;
  41. string ms_nextstepcode;
  42. DataTable Dbfind;
  43. public Make_SpiTestCollection()
  44. {
  45. InitializeComponent();
  46. }
  47. private void TestCollection_Load(object sender, EventArgs e)
  48. {
  49. GoodProduct.Checked = true;
  50. asc.controllInitializeSize(this);
  51. ms_sncode.Focus();
  52. //设置锁定工单
  53. LockMakeCode.GetMakeCodeCtl(ma_code);
  54. ma_code.SetLockCheckBox(LockMakeCode);
  55. ControlLockTimer.Tick += ControlLockTimer_Tick;
  56. ControlLockTimer.Interval = 100;
  57. bd_soncode.FormName = Name;
  58. bd_soncode.TableName = "(with temp1 as (select bd_fsoncode,bd_soncode,bd_location,pr_spec,pr_detail from bomdetail innner join bom on bo_id=bd_bomid left join product on bd_soncode = pr_code start with bo_mothercode = '" + ma_prodcode.Text + "' connect by bo_mothercode = prior bd_soncode)select* from temp1)";
  59. bd_soncode.SetValueField = new string[] { "bd_soncode" };
  60. bd_soncode.SelectField = "bd_fsoncode # 首选料号,bd_soncode # 子件编号,pr_detail # 物料名称,pr_spec # 物料规格,bd_location # 位号";
  61. bd_soncode.DBTitle = "不良零件";
  62. bd_soncode.DbChange += Prodcode_DbChange;
  63. //工单号放大镜配置
  64. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  65. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  66. ma_code.FormName = Name;
  67. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_detail", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  68. ma_code.Condition = "ma_statuscode='STARTED' and ma_wccode = 'SMT'";
  69. ma_code.DbChange += Ma_code_DbChange;
  70. dh = SystemInf.dh;
  71. StepCount.StepCode = User.CurrentStepCode;
  72. StepCount.Source = User.UserSourceCode;
  73. StepCount.LineCode = User.UserLineCode;
  74. StepCount.Dh = dh;
  75. StepCount.Start();
  76. st_table = dh.getFieldDataByCondition("step", "st_table", "st_code = '" + User.CurrentStepCode + "'").ToString();
  77. }
  78. private void ControlLockTimer_Tick(object sender, EventArgs e)
  79. {
  80. this.Activate();
  81. ms_sncode.Focus();
  82. }
  83. private void Ma_code_DbChange(object sender, EventArgs e)
  84. {
  85. Dbfind = ma_code.ReturnData;
  86. BaseUtil.SetFormValue(this.Controls, Dbfind);
  87. LoadCollectedNum();
  88. LoadCheckQTY();
  89. }
  90. /// <summary>
  91. /// 将已选不良移动到待选不良
  92. /// </summary>
  93. /// <param name="sender"></param>
  94. /// <param name="e"></param>
  95. private void WaitReject_Click(object sender, EventArgs e)
  96. {
  97. Boolean HaveReject = false;
  98. for (int i = MakeBadView.Rows.Count - 1; i >= 0; i--)
  99. {
  100. if (MakeBadView.Rows[i].Cells["choose1"].Value != null)
  101. {
  102. if ((Boolean)MakeBadView.Rows[i].Cells["choose1"].Value == true)
  103. {
  104. HaveReject = true;
  105. break;
  106. }
  107. }
  108. }
  109. if (HaveReject)
  110. {
  111. string confirm = MessageBox.Show(this.ParentForm, "确认删除勾选的不良(已保存的不良代码也会删除)", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk).ToString();
  112. if (confirm == "Yes")
  113. {
  114. for (int i = MakeBadView.Rows.Count - 1; i >= 0; i--)
  115. {
  116. if (MakeBadView.Rows[i].Cells["choose1"].Value != null)
  117. {
  118. if ((Boolean)MakeBadView.Rows[i].Cells["choose1"].Value == true)
  119. {
  120. if (MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString() != "")
  121. {
  122. List<string> SQLS = new List<string>();
  123. SQLS.Add("delete makebad where mb_id = '" + MakeBadView.Rows[i].Cells["mb_id"].Value.ToString() + "'");
  124. SQLS.Add("delete makebadreason where mbr_id = '" + MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString() + "'");
  125. SQLS.Add("delete makebadrscom where mbc_mbrid = '" + MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString() + "'");
  126. SQLS.Add("delete makebadrspart where mbp_mbrid = '" + MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString() + "'");
  127. SQLS.Add("delete makebadrsloc where mbl_mbrid = '" + MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString() + "'");
  128. dh.ExecuteSQLTran(SQLS.ToArray());
  129. }
  130. MakeBadView.Rows.RemoveAt(i);
  131. }
  132. }
  133. }
  134. (MakeBadView.DataSource as DataTable).AcceptChanges();
  135. }
  136. }
  137. HaveReject = false;
  138. }
  139. /// <summary>
  140. /// 将不良信息移动到已选不良
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void ChooseedReject_Click(object sender, EventArgs e)
  145. {
  146. if (ms_sncode.Text == "")
  147. {
  148. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  149. ms_sncode.Focus();
  150. return;
  151. }
  152. LoadChoosedBadListView();
  153. DataTable choose = (MakeBadView.DataSource as DataTable);
  154. List<string> Chooseed = new List<string>();
  155. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  156. {
  157. Chooseed.Add(MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString());
  158. }
  159. if (WaitChooseDGV.Rows.Count > 0)
  160. {
  161. for (int i = 0; i < WaitChooseDGV.Rows.Count; i++)
  162. {
  163. if (WaitChooseDGV.Rows[i].Cells["ChooseAll"].Value != null)
  164. {
  165. if ((Boolean)WaitChooseDGV.Rows[i].Cells["ChooseAll"].Value == true)
  166. {
  167. if (!Chooseed.Contains(WaitChooseDGV.Rows[i].Cells["bc_code"].Value.ToString()))
  168. {
  169. DataRow dr1 = choose.NewRow();
  170. dr1["mb_badcode"] = WaitChooseDGV.Rows[i].Cells["bc_code"].Value.ToString();
  171. dr1["mb_badname"] = WaitChooseDGV.Rows[i].Cells["bc_name"].Value.ToString();
  172. dr1["mb_bgname"] = WaitChooseDGV.Rows[i].Cells["bg_name"].Value.ToString();
  173. dr1["mb_bgcode"] = WaitChooseDGV.Rows[i].Cells["bg_code"].Value.ToString();
  174. choose.Rows.Add(dr1);
  175. }
  176. else
  177. {
  178. OperateResult.AppendText(">>不良代码" + WaitChooseDGV.Rows[i].Cells["bc_code"].Value.ToString() + "已存在\n", Color.Red);
  179. }
  180. }
  181. }
  182. }
  183. for (int i = 0; i < WaitChooseDGV.Rows.Count; i++)
  184. {
  185. WaitChooseDGV.Rows[i].Cells["ChooseAll"].Value = false;
  186. }
  187. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  188. {
  189. if (MakeBadView.Rows[i].Cells["mb_id"].Value.ToString() == "")
  190. {
  191. MakeBadView.Rows[i].Cells["choose1"].Value = true;
  192. }
  193. }
  194. }
  195. else OperateResult.AppendText(">>请勾选不良明细\n", Color.Red);
  196. }
  197. private void CleanInfo_Click(object sender, EventArgs e)
  198. {
  199. OperateResult.Clear();
  200. }
  201. private void ms_code_KeyDown(object sender, KeyEventArgs e)
  202. {
  203. if (e.KeyCode == Keys.Enter)
  204. {
  205. BaseUtil.CleanDGVData(MakeBadView);
  206. WaitList.Clear();
  207. ChoosedList.Clear();
  208. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  209. {
  210. //是否提示过工单切换框,检测前执行
  211. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  212. if (!NoteAlready)
  213. {
  214. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  215. return;
  216. }
  217. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  218. {
  219. //是否提示过工单切换框,检测前后执行
  220. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  221. {
  222. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  223. return;
  224. }
  225. if (ma_code.Text != oMakeCode && oMakeCode != null)
  226. {
  227. 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");
  228. if (dt.Rows.Count > 0)
  229. {
  230. BaseUtil.SetFormValue(this.Controls, dt);
  231. LockMakeCode.Checked = true;
  232. }
  233. }
  234. dt = (DataTable)dh.ExecuteSql("select nvl(ms_spi,0)ms_spi,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");
  235. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  236. string status = dt.Rows[0]["ms_status"].ToString();
  237. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  238. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  239. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  240. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  241. int ms_spi = int.Parse(dt.Rows[0]["ms_spi"].ToString());
  242. if (sncode != ms_sncode.Text)
  243. {
  244. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  245. return;
  246. }
  247. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  248. if (GoodProduct.Checked)
  249. {
  250. if (ms_spi != 0)
  251. {
  252. OperateResult.AppendText(">>" + ms_sncode.Text + "已采集过XRAY良品,无法重复采集\n", Color.Red, ms_sncode);
  253. return;
  254. }
  255. if (ifrework != "0")
  256. {
  257. if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
  258. {
  259. OperateResult.AppendText(">>" + ms_sncode.Text + "序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  260. return;
  261. }
  262. }
  263. else
  264. {
  265. if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
  266. {
  267. OperateResult.AppendText(">>" + ms_sncode.Text + "序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Red, ms_sncode);
  268. return;
  269. }
  270. }
  271. }
  272. SetCollectResult();
  273. }
  274. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  275. }
  276. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  277. }
  278. }
  279. /// <summary>
  280. /// 加载不良代码的ListView的信息
  281. /// </summary>
  282. private void LoadBadCodeListView()
  283. {
  284. sql.Clear();
  285. sql.Append("select bg_code,bg_name ,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  286. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  287. sql.Append("bg_code='" + User.DefaultBadGroup + "' and bg_code is not null order by bgd_detno");
  288. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  289. BadInfSource.DataSource = dt;
  290. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  291. }
  292. /// <summary>
  293. /// 加载已选不良的ListView
  294. /// </summary>
  295. private void LoadChoosedBadListView()
  296. {
  297. sql.Clear();
  298. sql.Append("select mb_id,mbr_id,mb_badcode,mb_badname,mbc_component,mb_bgcode,mb_bgname,WM_CONCAT(distinct mbp_part) mbp_part,WM_CONCAT(distinct mbl_loc) mbl_loc ");
  299. sql.Append("from makebad left join makebadreason on mb_id = mbr_mbid left join makebadrscom on mbc_mbrid = mbr_id left join makebadrspart on MBP_MBRID =mbr_id left join makebadrsloc ");
  300. sql.Append(" on mbl_mbrid = mbr_id where mb_sncode ='" + ms_sncode.Text + "'AND MB_MAKECODE = '" + ma_code.Text + "' AND MB_STEPCODE = '" + User.CurrentStepCode + "' group by mb_id,mbr_id,mb_sncode,mb_badcode,mb_badname,mbc_component,mb_bgcode,mb_bgname");
  301. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  302. BaseUtil.FillDgvWithDataTable(MakeBadView, dt);
  303. }
  304. /// <summary>
  305. /// 设置良品或者不良品的采集结果
  306. /// </summary>
  307. private void SetCollectResult()
  308. {
  309. string ErrorMessage = "";
  310. //如果勾选的是不良品
  311. if (Reject.Checked)
  312. {
  313. LoadBadCodeListView();
  314. LoadChoosedBadListView();
  315. OperateResult.AppendText(">>请采集不良代码\n", Color.Green);
  316. //勾选了自动产生代码
  317. if (AutoBadCode.Checked)
  318. Save_Click(new object(), new EventArgs());
  319. }
  320. else if (GoodProduct.Checked)
  321. {
  322. //如果不是返修的
  323. if (ifrework == "0")
  324. {
  325. 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");
  326. for (int i = 0; i < dt.Rows.Count; i++)
  327. {
  328. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  329. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  330. }
  331. //存在不良记录
  332. if (ErrorMessage != "")
  333. {
  334. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  335. return;
  336. }
  337. else
  338. {
  339. //良品信息采集
  340. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  341. {
  342. //提示正确返回时传递的信息
  343. if (ErrorMessage.Contains("AFTERSUCCESS"))
  344. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  345. LastSncode = ms_sncode.Text;
  346. dh.ExecuteSql("update makeserial set ms_spi = 1 where ms_sncode = '" + ms_sncode.Text + "' and ms_makecode = '" + ma_code.Text + "'", "update");
  347. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
  348. //记录操作日志
  349. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  350. }
  351. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  352. }
  353. }
  354. else
  355. {
  356. if (reworkstatus != "3")
  357. {
  358. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  359. {
  360. //提示正确返回时传递的信息
  361. if (ErrorMessage.Contains("AFTERSUCCESS"))
  362. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  363. LastSncode = ms_sncode.Text;
  364. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
  365. //记录操作日志
  366. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  367. }
  368. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  369. }
  370. else
  371. {
  372. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  373. }
  374. }
  375. }
  376. //加载页面信息
  377. LoadCollectedNum();
  378. LoadCheckQTY();
  379. }
  380. private void 测试采集_SizeChanged(object sender, EventArgs e)
  381. {
  382. asc.controlAutoSize(this);
  383. }
  384. private void LoadCollectedNum()
  385. {
  386. 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");
  387. BaseUtil.SetFormValue(Controls, dt);
  388. }
  389. private void Save_Click(object sender, EventArgs e)
  390. {
  391. if (ms_sncode.Text == "")
  392. {
  393. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  394. return;
  395. }
  396. if (GoodProduct.Checked)
  397. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  398. else if (Reject.Checked)
  399. {
  400. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  401. {
  402. //判断界面工单是否为空时的序列号是否自动归属工单
  403. string oStatus = "";
  404. if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
  405. {
  406. if (ma_code.Text == "")
  407. {
  408. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  409. return;
  410. }
  411. }
  412. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  413. {
  414. 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");
  415. if (dt.Rows.Count > 0)
  416. {
  417. BaseUtil.SetFormValue(this.Controls, dt);
  418. LockMakeCode.Checked = true;
  419. }
  420. }
  421. else
  422. {
  423. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  424. return;
  425. }
  426. 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");
  427. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  428. status = dt.Rows[0]["ms_status"].ToString();
  429. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  430. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  431. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  432. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  433. if (sncode != ms_sncode.Text)
  434. {
  435. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  436. return;
  437. }
  438. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  439. }
  440. else
  441. {
  442. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  443. return;
  444. }
  445. dt = (DataTable)dh.ExecuteSql("SELECT * FROM BOMDetail LEFT JOIN Product ON bd_soncode=pr_code WHERE bd_mothercode = '" + ma_prodcode.Text + "'", "select");
  446. if (dt.Rows.Count > 0)
  447. {
  448. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  449. {
  450. if (MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString() == "" || MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString() == "")
  451. {
  452. OperateResult.AppendText(">>不良位置与不良零件均不可为空\n", Color.Red);
  453. return;
  454. }
  455. }
  456. }
  457. else
  458. {
  459. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  460. {
  461. if (MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString() == "")
  462. {
  463. OperateResult.AppendText(">>不良位置不可为空\n", Color.Red);
  464. return;
  465. }
  466. }
  467. }
  468. List<string> bccode = new List<string>();
  469. List<string> bcremark = new List<string>();
  470. List<string> bgcode = new List<string>();
  471. List<string> bgname = new List<string>();
  472. List<string> bcname = new List<string>();
  473. bccode.Clear();
  474. bcremark.Clear();
  475. bgcode.Clear();
  476. bgname.Clear();
  477. bcname.Clear();
  478. if (MakeBadView.Rows.Count == 0)
  479. {
  480. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  481. return;
  482. }
  483. else
  484. {
  485. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  486. {
  487. if (MakeBadView.Rows[i].Cells["mb_id"].Value.ToString() == "")
  488. {
  489. //获取不良代码组
  490. bgcode.Add(MakeBadView.Rows[i].Cells["mb_bgcode"].Value.ToString());
  491. //获取不良代码组名称
  492. bgname.Add(MakeBadView.Rows[i].Cells["mb_bgname"].Value.ToString());
  493. //获取所有的不良代码
  494. bccode.Add(MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString());
  495. //获取不良名称
  496. bcname.Add(MakeBadView.Rows[i].Cells["mb_badname"].Value.ToString());
  497. //获取所有的不良备注
  498. bcremark.Add(bc_remark.Text);
  499. }
  500. }
  501. }
  502. //如果之前是良品的
  503. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
  504. if (dt.Rows.Count > 0)
  505. {
  506. status = dt.Rows[0]["ms_status"].ToString();
  507. if (status == "1" || status == "2")
  508. {
  509. 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 + "')");
  510. dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  511. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
  512. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
  513. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
  514. }
  515. string checkno = dt.Rows[0]["ms_checkno"].ToString();
  516. //存在抽检批次更新为空
  517. if (checkno != "")
  518. dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
  519. }
  520. else
  521. {
  522. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
  523. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
  524. }
  525. //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
  526. dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
  527. if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", bgcode.ToArray(), bccode.ToArray(), bgname.ToArray(), bcname.ToArray(), bcremark.ToArray(), out ErrorMessage))
  528. {
  529. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
  530. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  531. {
  532. //获取当前序列号对应的不良代码编号
  533. string makebadid = dh.getFieldDataByCondition("makebad", "mb_id", "mb_sncode = '" + ms_sncode.Text + "' and mb_makecode = '" + ma_code.Text + "' and mb_badcode = '" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "'").ToString();
  534. //为空插入不良代码表与不良原因表
  535. if (MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString() == "")
  536. {
  537. DataTable temp = dh.getFieldsDatasByCondition(" BADGROUPDETAIL left join badgroup on bgd_bgid = bg_id", new string[] { "bgd_brgcode", "bgd_dutycode", "bgd_solutioncode", "bgd_brcode" }, "bgd_badcode= '" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "' and bg_code = '" + MakeBadView.Rows[i].Cells["mb_bgcode"].Value.ToString() + "'");
  538. string bgd_brgcode = temp.Rows[0]["bgd_brgcode"].ToString();
  539. string bgd_brcode = temp.Rows[0]["bgd_brcode"].ToString();
  540. string bgd_dutycode = temp.Rows[0]["bgd_dutycode"].ToString();
  541. string bgd_solutioncode = temp.Rows[0]["bgd_solutioncode"].ToString();
  542. string mbr_id = dh.GetSEQ("makebadreason_seq");
  543. string bgd_brgname = dh.getFieldDataByCondition("QUA_NGReasonGroup", "nrg_name", "nrg_code = '" + bgd_brgcode + "'").ToString();
  544. string bgd_brname = dh.getFieldDataByCondition("QUA_NGReason", "nr_name", "nr_code = '" + bgd_brcode + "'").ToString();
  545. string bgd_dutyname = dh.getFieldDataByCondition("NGDuty", "nd_name", "nd_code = '" + bgd_dutycode + "'").ToString();
  546. string bgd_solutionname = dh.getFieldDataByCondition("solution", "so_name", "so_code = '" + bgd_solutioncode + "'").ToString();
  547. sql.Clear();
  548. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  549. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  550. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname) select '" + makebadid + "','" + mbr_id + "','" + bgd_brcode + "',");
  551. sql.Append("'" + bgd_solutioncode + "','" + bgd_dutycode + "','" + bgd_brgcode + "','" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "',");
  552. sql.Append("'" + ms_sncode.Text + "','" + ma_code.Text + "',sysdate,'" + User.UserCode + "','" + bgd_brname + "','" + bgd_solutionname + "','" + MakeBadView.Rows[i].Cells["mb_badname"].Value.ToString() + "','" + bgd_brgname + "','" + bgd_dutyname + "' from dual");
  553. dh.ExecuteSql(sql.GetString(), "insert");
  554. if (MakeBadView.Rows[i].Cells["mbc_component"].Value.ToString() != "")
  555. {
  556. sql.Clear();
  557. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  558. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  559. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + MakeBadView.Rows[i].Cells["mbc_component"].Value.ToString() + "',");
  560. sql.Append("'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',sysdate,'" + User.UserCode + "')");
  561. dh.ExecuteSql(sql.GetString(), "insert");
  562. }
  563. string[] mbl_loc = MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().ToUpper().Split(',');
  564. sql.Clear();
  565. sql.Append("insert into makebadrsloc(mbl_id,mbl_mbrid,mbl_loc,mbl_badcode,mbl_brcode,");
  566. sql.Append("mbl_sncode,mbl_makecode,mbl_indate ,mbl_inman) select makebadrsloc_seq.nextval," + mbr_id);
  567. sql.Append(",:mbl_loc,'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',");
  568. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  569. dh.BatchInsert(sql.GetString(), new string[] { "mbl_loc" }, mbl_loc);
  570. //sql.Clear();
  571. //sql.Append("with temp1 as (select bd_soncode,bd_location from bomdetail,bom where bo_id=bd_bomid ");
  572. //sql.Append(" start with bo_mothercode='" + ma_prodcode.Text + "' connect by bo_mothercode= prior bd_soncode) ");
  573. //sql.Append("select bd_soncode from temp1 where instr(','||bd_location||',','," + MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().ToUpper() + ",')>0");
  574. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  575. //if (dt.Rows.Count > 0)
  576. //{
  577. // for (int j = 0; j < dt.Rows.Count; i++)
  578. // {
  579. // sql.Clear();
  580. // sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  581. // sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  582. // sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + dt.Rows[0][j].ToString() + "',");
  583. // sql.Append("'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',");
  584. // sql.Append("sysdate,'" + User.UserCode + "' from dual");
  585. // dh.ExecuteSql(sql.GetString(), "insert");
  586. // }
  587. //}
  588. if (MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString() != "")
  589. {
  590. string[] mbp_part = MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString().ToUpper().Split(',');
  591. sql.Clear();
  592. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  593. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  594. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",:mbp_part,");
  595. sql.Append("'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',");
  596. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  597. dh.BatchInsert(sql.GetString(), new string[] { "mbp_part" }, mbp_part);
  598. }
  599. }
  600. else
  601. {
  602. //已保存过不良信息的序列号
  603. DataTable temp = dh.getFieldsDatasByCondition(" BADGROUPDETAIL left join badgroup on bgd_bgid = bg_id", new string[] { "bgd_brgcode", "bgd_dutycode", "bgd_solutioncode", "bgd_brcode" }, "bgd_badcode= '" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "' and bg_code = '" + MakeBadView.Rows[i].Cells["mb_bgcode"].Value.ToString() + "'");
  604. string bgd_brgcode = temp.Rows[0]["bgd_brgcode"].ToString();
  605. string bgd_brcode = temp.Rows[0]["bgd_brcode"].ToString();
  606. string bgd_dutycode = temp.Rows[0]["bgd_dutycode"].ToString();
  607. string bgd_solutioncode = temp.Rows[0]["bgd_solutioncode"].ToString();
  608. string mbr_id = MakeBadView.Rows[i].Cells["mbr_id"].Value.ToString();
  609. string bgd_brgname = dh.getFieldDataByCondition("QUA_NGReasonGroup", "nrg_name", "nrg_code = '" + bgd_brgcode + "'").ToString();
  610. string bgd_brname = dh.getFieldDataByCondition("QUA_NGReason", "nr_name", "nr_code = '" + bgd_brcode + "'").ToString();
  611. string bgd_dutyname = dh.getFieldDataByCondition("NGDuty", "nd_name", "nd_code = '" + bgd_dutycode + "'").ToString();
  612. string bgd_solutionname = dh.getFieldDataByCondition("solution", "so_name", "so_code = '" + bgd_solutioncode + "'").ToString();
  613. //删除不良组件,不良位置等信息重新插入
  614. dh.ExecuteSql("delete makebadrscom where mbc_mbrid = '" + mbr_id + "'", "delete");
  615. dh.ExecuteSql("delete makebadrsloc where mbl_mbrid = '" + mbr_id + "'", "delete");
  616. dh.ExecuteSql("delete makebadrspart where mbp_mbrid = '" + mbr_id + "'", "delete");
  617. if (MakeBadView.Rows[i].Cells["mbc_component"].Value.ToString() != "")
  618. {
  619. sql.Clear();
  620. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  621. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  622. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + MakeBadView.Rows[i].Cells["mbc_component"].Value.ToString() + "',");
  623. sql.Append("'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',sysdate,'" + User.UserCode + "')");
  624. dh.ExecuteSql(sql.GetString(), "insert");
  625. }
  626. string[] mbl_loc = MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().ToUpper().Split(',');
  627. sql.Clear();
  628. sql.Append("insert into makebadrsloc(mbl_id,mbl_mbrid,mbl_loc,mbl_badcode,mbl_brcode,");
  629. sql.Append("mbl_sncode,mbl_makecode,mbl_indate ,mbl_inman) select makebadrsloc_seq.nextval," + mbr_id);
  630. sql.Append(",:mbl_loc,'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',");
  631. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  632. dh.BatchInsert(sql.GetString(), new string[] { "mbl_loc" }, mbl_loc);
  633. sql.Clear();
  634. sql.Append("with temp1 as (select bd_soncode,bd_location from bomdetail,bom where bo_id=bd_bomid ");
  635. sql.Append(" start with bo_mothercode='" + ma_prodcode + "' connect by bo_mothercode= prior bd_soncode) ");
  636. sql.Append("select bd_soncode from temp1 where instr(','||bd_location||',','," + MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().ToUpper() + ",')>0");
  637. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  638. if (dt.Rows.Count > 0)
  639. {
  640. for (int j = 0; j < dt.Rows.Count; i++)
  641. {
  642. sql.Clear();
  643. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  644. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  645. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + dt.Rows[0][j].ToString() + "',");
  646. sql.Append("'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',");
  647. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  648. dh.ExecuteSql(sql.GetString(), "insert");
  649. }
  650. }
  651. if (MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString() != "")
  652. {
  653. string[] mbp_part = MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString().ToUpper().Split(',');
  654. sql.Clear();
  655. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  656. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  657. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",:mbp_part,");
  658. sql.Append("'" + MakeBadView.Rows[i].Cells["mb_badcode"].Value.ToString() + "','" + bgd_brcode + "','" + ms_sncode.Text + "','" + ma_code.Text + "',");
  659. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  660. dh.BatchInsert(sql.GetString(), new string[] { "mbp_part" }, mbp_part);
  661. }
  662. }
  663. }
  664. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_id", "nvl(ms_ifrework,0) ms_ifrework", "ms_paststep" }, "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + ma_code.Text + "' ");
  665. string St_ifqccheck = dh.getFieldDataByCondition("source LEFT JOIN STEP on st_code=sc_stepcode", "nvl(St_ifqccheck,0)", "sc_code='" + User.UserSourceCode + "'").ToString();
  666. List<string> SQLS = new List<string>();
  667. LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "快速维修采集", "完成快速维修", User.UserCode);
  668. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修采集", "完成快速维修", ms_sncode.Text, ob_checkno.Text);
  669. if (dt.Rows.Count > 0)
  670. {
  671. string ms_id = dt.Rows[0]["ms_id"].ToString();
  672. string ms_ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  673. if (St_ifqccheck != "-1")
  674. {
  675. if (ms_ifrework == "0")
  676. SQLS.Add("update makeserial set ms_checkno='', ms_nextstepcode ='" + User.CurrentStepCode + "',ms_status=1,ms_stepcode='SMT_REPAIR' where ms_id='" + ms_id + "'");
  677. else
  678. SQLS.Add("update makeserial set ms_checkno='', ms_nextstepcode ='" + User.CurrentStepCode + "',ms_reworkstatus=1,ms_stepcode='SMT_REPAIR' where ms_id='" + ms_id + "'");
  679. }
  680. else
  681. {
  682. if (ms_ifrework == "0")
  683. SQLS.Add("update makeserial set ms_checkno='', ms_nextstepcode ='" + ms_nextstepcode + "',ms_status=1,ms_stepcode='SMT_REPAIR',ms_paststep = REPLACE(ms_paststep,','||'" + ms_nextstepcode + "') where ms_id='" + ms_id + "'");
  684. else
  685. SQLS.Add("update makeserial set ms_checkno='', ms_nextstepcode ='" + ms_nextstepcode + "',ms_reworkstatus=1,ms_stepcode='SMT_REPAIR',ms_paststep = REPLACE(ms_paststep,','||'" + ms_nextstepcode + "') where ms_id='" + ms_id + "'");
  686. if (status == "2")
  687. SQLS.Add("update makeserial set ms_status='2' where ms_id='" + ms_id + "'");
  688. }
  689. }
  690. SQLS.Add("update makebad set mb_status=-1 where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and MB_STEPCODE = '" + User.CurrentStepCode + "'");
  691. dh.ExecuteSQLTran(SQLS.ToArray());
  692. //保存不良原因
  693. LastSncode = ms_sncode.Text;
  694. //采集完不良,聚焦序列号
  695. ms_sncode.Focus();
  696. //记录操作日志
  697. ms_sncode.Text = "";
  698. //清除不良信息
  699. BaseUtil.CleanDGVData(MakeBadView);
  700. //加载页面信息
  701. LoadCollectedNum();
  702. LoadCheckQTY();
  703. }
  704. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  705. }
  706. }
  707. private void bc_code_KeyDown(object sender, KeyEventArgs e)
  708. {
  709. }
  710. private void LoadCheckQTY()
  711. {
  712. sql.Clear();
  713. string condition = "";
  714. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  715. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  716. if (nowcheckqty + 1 == batchqty && AutoCut)
  717. {
  718. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  719. }
  720. else
  721. {
  722. condition = "and ob_status='ENTERING' ";
  723. }
  724. if (pr_sendchecktype.Text == "SaleCode")
  725. {
  726. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  727. }
  728. else if (pr_sendchecktype.Text == "MakeCode")
  729. {
  730. condition += " and ob_makecode='" + ma_code.Text + "'";
  731. }
  732. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  733. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  734. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  735. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  736. if (dt.Rows.Count > 0)
  737. {
  738. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  739. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  740. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  741. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  742. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  743. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  744. if (nowcheckqty == batchqty)
  745. {
  746. ob_nowcheckqty.ForeColor = Color.Red;
  747. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  748. if (AutoCut)
  749. {
  750. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  751. }
  752. }
  753. }
  754. else
  755. {
  756. ob_batchqty.Text = "";
  757. ob_nowcheckqty.Text = "";
  758. ob_checkno.Text = "";
  759. SendCheck.Enabled = false;
  760. }
  761. if (ob_batchqty.Text != "")
  762. {
  763. SendCheck.Enabled = true;
  764. }
  765. else
  766. {
  767. SendCheck.Enabled = false;
  768. }
  769. }
  770. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  771. {
  772. if (GoodProduct.Checked)
  773. {
  774. WaitReject.Enabled = false;
  775. ChooseedReject.Enabled = false;
  776. Save.Visible = false;
  777. }
  778. else
  779. {
  780. WaitReject.Enabled = true;
  781. ChooseedReject.Enabled = true;
  782. Save.Visible = true;
  783. }
  784. if (ms_sncode.Text == "")
  785. {
  786. ms_sncode.Focus();
  787. }
  788. }
  789. private void SendCheck_Click(object sender, EventArgs e)
  790. {
  791. sql.Clear();
  792. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  793. dh.ExecuteSql(sql.GetString(), "select");
  794. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  795. ob_nowcheckqty.Text = "";
  796. ob_batchqty.Text = "";
  797. ob_nowcheckqty.ForeColor = Color.Black;
  798. SendCheck.Enabled = false;
  799. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  800. ms_sncode.Focus();
  801. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  802. //记录操作日志
  803. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  804. ob_checkno.Text = "";
  805. }
  806. private void ob_checkno_TextChanged(object sender, EventArgs e)
  807. {
  808. if (ob_checkno.Text != "")
  809. {
  810. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  811. if (Cut == "" || Cut == "0")
  812. AutoCut = false;
  813. else
  814. AutoCut = true;
  815. SendCheck.Enabled = true;
  816. }
  817. }
  818. /// <summary>
  819. /// 工单变化修改数量
  820. /// </summary>
  821. /// <param name="sender"></param>
  822. /// <param name="e"></param>
  823. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  824. {
  825. if (ma_code.Text.Length > 4)
  826. {
  827. mcd_inqty.Text = "";
  828. mcd_remainqty.Text = "";
  829. ob_batchqty.Text = "";
  830. ob_nowcheckqty.Text = "";
  831. ob_sendqty.Text = "";
  832. LoadCollectedNum();
  833. LoadCheckQTY();
  834. }
  835. }
  836. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  837. {
  838. dh.Dispose();
  839. }
  840. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  841. {
  842. bd_soncode.TableName = "(with temp1 as (select bd_fsoncode,bd_soncode,bd_location,pr_spec,pr_detail from bomdetail innner join bom on bo_id=bd_bomid left join product on bd_soncode = pr_code start with bo_mothercode = '" + ma_prodcode.Text + "' connect by bo_mothercode = prior bd_soncode)select* from temp1)";
  843. bd_soncode.Condition = "1=1";
  844. }
  845. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  846. {
  847. try
  848. {
  849. DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  850. DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
  851. for (int i = 0; i < dr.Length; i++)
  852. {
  853. dt.Rows.Add(dr[i].ItemArray);
  854. }
  855. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  856. }
  857. catch (Exception)
  858. {
  859. }
  860. }
  861. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  862. {
  863. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  864. {
  865. if (!LockSn)
  866. {
  867. ControlLockTimer.Start();
  868. LockSn = true;
  869. Lock_label.Visible = true;
  870. }
  871. else
  872. {
  873. ControlLockTimer.Stop();
  874. LockSn = false;
  875. Lock_label.Visible = false;
  876. }
  877. }
  878. }
  879. private void Reject_CheckedChanged(object sender, EventArgs e)
  880. {
  881. if (Reject.Checked)
  882. {
  883. LoadBadCodeListView();
  884. }
  885. }
  886. private void Prodcode_DbChange(object sender, EventArgs e)
  887. {
  888. MakeBadView.EndEdit();
  889. if (bd_soncode.Text != "")
  890. {
  891. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  892. {
  893. if (MakeBadView.Rows[i].Cells["choose1"].Value != null)
  894. {
  895. if ((Boolean)MakeBadView.Rows[i].Cells["choose1"].Value == true)
  896. {
  897. if (MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString() == "")
  898. {
  899. MakeBadView.Rows[i].Cells["mbp_part"].Value = bd_soncode.Text;
  900. }
  901. else if (!MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString().Contains(bd_soncode.Text))
  902. MakeBadView.Rows[i].Cells["mbp_part"].Value += "," + bd_soncode.Text;
  903. if (MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString() == "")
  904. {
  905. MakeBadView.Rows[i].Cells["mbl_loc"].Value = psl_location.Text.ToUpper();
  906. }
  907. else if (!MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().Contains(psl_location.Text.ToUpper()))
  908. MakeBadView.Rows[i].Cells["mbl_loc"].Value += "," + psl_location.Text.ToUpper();
  909. }
  910. }
  911. }
  912. }
  913. else OperateResult.AppendText(">>不良零件不能为空\n", Color.Red);
  914. }
  915. private void bd_soncode_UserControlTextChanged(object sender, EventArgs e)
  916. {
  917. }
  918. private void bd_soncode_Load(object sender, EventArgs e)
  919. {
  920. }
  921. private void bad_loc_KeyDown(object sender, KeyEventArgs e)
  922. {
  923. if (e.KeyCode == Keys.Enter)
  924. {
  925. if (ma_prodcode.Text != "")
  926. {
  927. if (psl_location.Text != "" && psl_location.Text.Length <= 6)
  928. {
  929. DataTable dt = (DataTable)dh.ExecuteSql("select bd_soncode,bd_location,pr_spec,pr_detail from (with temp1 as (select bd_soncode,bd_location,pr_spec,pr_detail from bomdetail innner join bom on bo_id=bd_bomid left join product on bd_soncode = pr_code start with bo_mothercode= '" + ma_prodcode.Text + "'and nvl(bd_usestatus,' ') <> 'DISABLE' connect by bo_mothercode= prior bd_soncode)select * from temp1) where bd_location = '" + psl_location.Text.ToUpper() + "' OR bd_location LIKE '" + psl_location.Text.ToUpper() + ",%' OR bd_location LIKE '%," + psl_location.Text.ToUpper() + "' OR bd_location LIKE '%," + psl_location.Text.ToUpper() + ",%'", "select");
  930. if (dt.Rows.Count > 0)
  931. {
  932. if (dt.Rows.Count == 1)
  933. {
  934. string psl_prodcode = dt.Rows[0]["bd_soncode"].ToString();
  935. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  936. {
  937. if (MakeBadView.Rows[i].Cells["choose1"].Value != null)
  938. {
  939. if ((Boolean)MakeBadView.Rows[i].Cells["choose1"].Value == true)
  940. {
  941. if (MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString() == "")
  942. {
  943. MakeBadView.Rows[i].Cells["mbp_part"].Value = psl_prodcode;
  944. }
  945. else if (!MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString().Contains(psl_prodcode))
  946. MakeBadView.Rows[i].Cells["mbp_part"].Value += "," + psl_prodcode;
  947. if (MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString() == "")
  948. {
  949. MakeBadView.Rows[i].Cells["mbl_loc"].Value = psl_location.Text.ToUpper();
  950. }
  951. else if (!MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().Contains(psl_location.Text.ToUpper()))
  952. MakeBadView.Rows[i].Cells["mbl_loc"].Value += "," + psl_location.Text.ToUpper();
  953. }
  954. }
  955. }
  956. }
  957. else if (dt.Rows.Count > 1)
  958. {
  959. Boolean ifgetloc = false;
  960. for (int j = 0; j < dt.Rows.Count; j++)
  961. {
  962. string psl_prodcode = dt.Rows[j]["bd_soncode"].ToString();
  963. for (int i = 0; i < MakeBadView.Rows.Count; i++)
  964. {
  965. if (MakeBadView.Rows[i].Cells["choose1"].Value != null)
  966. {
  967. if ((Boolean)MakeBadView.Rows[i].Cells["choose1"].Value == true)
  968. {
  969. if (MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString() == "")
  970. {
  971. OperateResult.AppendText(">>站位" + psl_location.Text + "有替代料,需要提前采集不良零件,第" + (i + 1) + "行不良零件为空\n", Color.Red);
  972. }
  973. else if (MakeBadView.Rows[i].Cells["mbp_part"].Value.ToString().Contains(psl_prodcode))
  974. {
  975. ifgetloc = true;
  976. if (MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString() == "")
  977. {
  978. MakeBadView.Rows[i].Cells["mbl_loc"].Value = psl_location.Text.ToUpper();
  979. }
  980. else if (!MakeBadView.Rows[i].Cells["mbl_loc"].Value.ToString().Contains(psl_location.Text.ToUpper()))
  981. MakeBadView.Rows[i].Cells["mbl_loc"].Value += "," + psl_location.Text.ToUpper();
  982. }
  983. }
  984. }
  985. }
  986. }
  987. if (!ifgetloc)
  988. {
  989. OperateResult.AppendText(">>站位" + psl_location.Text + "有替代料,需要提前采集不良零件,当前所选行均未采集对应不良零件\n", Color.Red);
  990. }
  991. }
  992. }
  993. else
  994. {
  995. OperateResult.AppendText(">>站位" + psl_location.Text.ToUpper() + "无对应物料\n", Color.Red, psl_location);
  996. }
  997. }
  998. else
  999. {
  1000. OperateResult.AppendText(">>不良位置录入不能为空或长度不能大于6\n", Color.Red);
  1001. }
  1002. }
  1003. else
  1004. {
  1005. OperateResult.AppendText(">>产品编号不能为空\n", Color.Red);
  1006. }
  1007. }
  1008. }
  1009. private void psl_location_Leave(object sender, EventArgs e)
  1010. {
  1011. psl_location.Text = "";
  1012. }
  1013. }
  1014. }