Make_FeedingCollection.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicMethod;
  9. using System.Drawing;
  10. using System.Text.RegularExpressions;
  11. using System.Collections.Generic;
  12. using UAS_MES_NEW.PublicForm;
  13. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_FeedingCollection : Form
  16. {
  17. //MakeSerial表主键
  18. string ms_id;
  19. //制造单号
  20. string make_code;
  21. //产品编号
  22. string make_prodcode;
  23. //工序编号
  24. string nextstepcode;
  25. //完工状态
  26. string ms_status;
  27. //工艺路线编号
  28. //Bom版本
  29. string mabomversion;
  30. string ErrorMessage = "";
  31. List<string> TSN = new List<string>();
  32. Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
  33. //用于提醒的序列B
  34. string[] RemainList = new string[0];
  35. //提醒序列的索引
  36. int RemainIndex = 0;
  37. string oMakeCode = "";
  38. string oMsid = "";
  39. string ms_firstsn = "";
  40. DataHelper dh;
  41. LogStringBuilder sql = new LogStringBuilder();
  42. DataTable DBFind;
  43. DataTable dt;
  44. //保存ListB中的数据
  45. DataTable dt1;
  46. AutoSizeFormClass asc = new AutoSizeFormClass();
  47. List<string> CollectData = new List<string>();
  48. List<string> CollectDataSonCode = new List<string>();
  49. List<string> SPID = new List<string>();
  50. public Make_FeedingCollection()
  51. {
  52. InitializeComponent();
  53. }
  54. private void Make_FeedingCollection_Load(object sender, EventArgs e)
  55. {
  56. asc.controllInitializeSize(this);
  57. LockMakeCode.GetMakeCodeCtl(ma_code);
  58. ma_code.SetLockCheckBox(LockMakeCode);
  59. //工单号放大镜配置
  60. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  61. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品名称,ma_bomversion # Bom版本,ma_softversion # 软件版本,ma_ecncode # ECN号";
  62. ma_code.FormName = Name;
  63. ma_code.DBTitle = "工单查询";
  64. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion", "ma_ecncode" };
  65. ma_code.Condition = "ma_statuscode='STARTED'";
  66. ma_code.DbChange += Ma_code_DBChange;
  67. code.Focus();
  68. dh = SystemInf.dh;
  69. StepCount.StepCode = User.CurrentStepCode;
  70. StepCount.Source = User.UserSourceCode;
  71. StepCount.LineCode = User.UserLineCode;
  72. StepCount.Dh = dh;
  73. StepCount.Start();
  74. }
  75. private void Ma_code_DBChange(object sender, EventArgs e)
  76. {
  77. DBFind = ma_code.ReturnData;
  78. BaseUtil.SetFormValue(this.Controls, DBFind);
  79. string ifforsn = dh.getFieldDataByCondition("make left join stepbom on ma_prodcode=sb_prodcode left join stepproduct on sb_id=sp_sbid", "nvl(sp_ifforsn,0) sp_ifforsn", "ma_code='" + ma_code.Text + "' and sp_craftcode='" + ma_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sb_bomversion='" + ma_bomversion.Text + "' order by sp_detno").ToString();
  80. if (ifforsn != "" && ifforsn != "0")
  81. iflastsn.Checked = true;
  82. else
  83. iflastsn.Checked = false;
  84. }
  85. private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
  86. {
  87. asc.controlAutoSize(this);
  88. }
  89. private void Clean_Click(object sender, EventArgs e)
  90. {
  91. OperateResult.Clear();
  92. }
  93. private void Confirm_Click(object sender, EventArgs e)
  94. {
  95. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  96. code_KeyDown(sender, e2);
  97. }
  98. private void code_KeyDown(object sender, KeyEventArgs e)
  99. {
  100. if (e.KeyCode == Keys.Enter)
  101. {
  102. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  103. {
  104. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sn_code.Text + "' order by ms_id desc", "select");
  105. if (dt.Rows.Count > 0)
  106. {
  107. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  108. }
  109. else
  110. {
  111. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sn_code.Text + "' order by ms_id desc", "select");
  112. if (dt.Rows.Count > 0)
  113. {
  114. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  115. }
  116. else
  117. {
  118. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sn_code.Text + "' order by mil_id desc", "select");
  119. if (dt.Rows.Count > 0)
  120. {
  121. sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
  122. }
  123. else
  124. {
  125. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sn_code.Text + "' order by mil_id desc", "select");
  126. if (dt.Rows.Count > 0)
  127. {
  128. sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
  129. }
  130. }
  131. }
  132. }
  133. if (Loading.Checked)
  134. {
  135. if (code.Text.Replace(" ", "") == "")
  136. {
  137. OperateResult.AppendText(">>采集数据不可为空\n", Color.Red);
  138. return;
  139. }
  140. //如果录入框和工单号均有输入
  141. if (code.Text != "" && ma_code.Text != "" && sn_code.Text == "")
  142. {
  143. GetCollectItem();
  144. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  145. }
  146. //输入框有值但未选择工单号
  147. else if (code.Text != "" && ma_code.Text == "" && sn_code.Text == "")
  148. {
  149. GetCollectItem();
  150. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  151. }
  152. else if (sn_code.Text != "")
  153. {
  154. //索引超出长度表示内容均已提醒
  155. if (RemainIndex >= RemainList.Length)
  156. {
  157. OperateResult.AppendText(">>当前序列号" + sn_code.Text + "不在本道工序,请采集其它序列号\n", Color.Black);
  158. sn_code.Text = "";
  159. code.Text = "";
  160. return;
  161. }
  162. string sp_soncode = dt1.Rows[RemainIndex]["sp_soncode"].ToString();
  163. string sp_fsoncode = dt1.Rows[RemainIndex]["sp_fsoncode"].ToString();
  164. string sp_prefix = dt1.Rows[RemainIndex]["sp_prefix"].ToString();
  165. string sp_regex = dt1.Rows[RemainIndex]["sp_regex"].ToString();
  166. string length = dt1.Rows[RemainIndex]["sp_length"].ToString();
  167. string sp_id = dt1.Rows[RemainIndex]["sp_id"].ToString();
  168. string sp_ifrepeat = dt1.Rows[RemainIndex]["sp_ifrepeat"].ToString();
  169. string sp_ifforsn = dt1.Rows[RemainIndex]["sp_ifforsn"].ToString();
  170. string sp_barcoderule = dt1.Rows[RemainIndex]["sp_barcoderule"].ToString();
  171. string sp_checkbarcode = dt1.Rows[RemainIndex]["sp_checkbarcode"].ToString();
  172. string sp_checksalecode = dt1.Rows[RemainIndex]["sp_checksalecode"].ToString();
  173. //检测主板SN是否和传入的SN一致
  174. if (CheckFirstSN.Checked)
  175. {
  176. if (RemainIndex == 0 && sn_code.Text != code.Text)
  177. {
  178. OperateResult.AppendText(">>首件条码和SN号码不一致\n", Color.Red, code);
  179. return;
  180. }
  181. }
  182. if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  183. {
  184. //判断采集的条码和本次采集的也不能重复
  185. if (CollectData.Contains(code.Text) && sp_ifrepeat != "-1")
  186. {
  187. OperateResult.AppendText(">>条码" + code.Text + "已经上料\n", Color.Red, code);
  188. return;
  189. }
  190. if (sp_checkbarcode != "")
  191. {
  192. if (CheckBarcode.ContainsKey(sp_checkbarcode))
  193. {
  194. if (CheckBarcode[sp_checkbarcode] != code.Text)
  195. {
  196. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  197. return;
  198. }
  199. }
  200. else
  201. {
  202. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  203. return;
  204. }
  205. }
  206. TSN.Add(code.Text.Substring(0, code.Text.Length > 80 ? 80 : code.Text.Length));
  207. if (sp_barcoderule == "BARCODE")
  208. {
  209. sp_soncode = ErrorMessage;
  210. }
  211. Save_OtherCode(sp_fsoncode, sp_soncode, make_code, sn_code.Text, sp_id);
  212. }
  213. else
  214. {
  215. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  216. SetCheck set = new SetCheck("NG", Color.Red);
  217. BaseUtil.SetFormCenter(set);
  218. set.ShowDialog();
  219. }
  220. }
  221. }
  222. //勾选了下料的时候
  223. else if (UnLoading.Checked)
  224. {
  225. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
  226. {
  227. sql.Clear();
  228. sql.Append("select ms_firstsn,cm_makecode,cm_craftcode,nvl(cm_status,0)cm_status,cm_id,cm_stepcode,");
  229. sql.Append("ms_makecode,cm_mccode,cm_materialtype from craftmaterial left join makeserial on cm_makecode");
  230. sql.Append("=ms_makecode and cm_firstsn=ms_firstsn where cm_firstsn='" + code.Text + "' and cm_makecode='" + oMakeCode + "'");
  231. sql.Append("and cm_materialtype=1");
  232. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  233. if (dt.Rows.Count > 0)
  234. {
  235. string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
  236. string ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  237. string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
  238. string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
  239. string cm_materialtype = dt.Rows[0]["cm_materialtype"].ToString();
  240. string cm_status = dt.Rows[0]["cm_status"].ToString();
  241. string cm_makecode = dt.Rows[0]["cm_makecode"].ToString();
  242. string cm_craftcode = dt.Rows[0]["cm_craftcode"].ToString();
  243. //清除已被使用的序列号
  244. sql.Clear();
  245. sql.Append("update makeserial set ms_nextmacode='' where ms_sncode in(select cm_barcode from craftmaterial where ");
  246. sql.Append("cm_makecode='" + cm_makecode + "' and cm_sncode='" + code.Text + "' and cm_stepcode='" + cm_stepcode + "' and cm_craftcode='" + cm_craftcode + "' ");
  247. sql.Append("and cm_materialtype=1 and nvl(cm_status,0) =0) and ms_nextmacode='" + oMakeCode + "'");
  248. dh.ExecuteSql(sql.GetString(), "update");
  249. //进行下料
  250. sql.Clear();
  251. sql.Append("delete from craftmaterial where (cm_sncode in (select sn from makesnrelation where firstsn");
  252. sql.Append("='" + ms_firstsn + "') or cm_sncode = '" + ms_firstsn + "') and cm_makecode = '" + oMakeCode + "' ");
  253. sql.Append("and cm_status = 0 and cm_stepcode='" + User.CurrentStepCode + "' and cm_materialtype=1");
  254. dh.ExecuteSql(sql.GetString(), "delete");
  255. LogicHandler.InsertMakeProcess(ms_macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
  256. //刷新界面值
  257. sql.Clear();
  258. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  259. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code where ");
  260. sql.Append("ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  261. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  262. BaseUtil.SetFormValue(Controls, dt);
  263. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上料采集", "下料成功", code.Text, "");
  264. OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
  265. }
  266. else OperateResult.AppendText(">>序列号" + code.Text + "未上料,无需下料\n", Color.Red, code);
  267. }
  268. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  269. }
  270. }
  271. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  272. }
  273. }
  274. //获取采集的项目
  275. private void GetCollectItem()
  276. {
  277. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(code.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  278. if (!NoteAlready)
  279. {
  280. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  281. return;
  282. }
  283. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
  284. {
  285. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(code.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  286. {
  287. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  288. return;
  289. }
  290. //将录入框的值给序列号
  291. sn_code.Text = code.Text;
  292. sql.Clear();
  293. sql.Append("select ma_prodcode,ma_ecncode,ma_softversion,ms_firstsn,ma_bomversion,ma_qty,ma_code,pr_spec,ms_status,ms_id,ms_craftcode,ms_nextstepcode");
  294. sql.Append(",ms_prodcode,ms_makecode,ms_code,ms_stepname from makeserial left join make on ma_code=ms_makecode ");
  295. sql.Append("left join product on ms_prodcode=pr_code where ms_id='"+ oMsid + "' order by ms_id desc");
  296. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  297. if (dt.Rows.Count > 0)
  298. {
  299. ms_id = dt.Rows[0]["ms_id"].ToString();
  300. make_code = dt.Rows[0]["ma_code"].ToString();
  301. mabomversion = dt.Rows[0]["ma_bomversion"].ToString();
  302. make_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  303. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  304. ms_status = dt.Rows[0]["ms_status"].ToString();
  305. ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  306. BaseUtil.SetFormValue(this.Controls, dt);
  307. string ifforsn = dh.getFieldDataByCondition("make left join stepbom on ma_prodcode=sb_prodcode left join stepproduct on sb_id=sp_sbid", "nvl(sp_ifforsn,0) sp_ifforsn", "ma_code='" + ma_code.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_craftcode='" + ms_craftcode.Text + "' and sb_bomversion='" + ma_bomversion.Text + "' order by sp_detno").ToString();
  308. if (ifforsn != "" && ifforsn != "0")
  309. iflastsn.Checked = true;
  310. else
  311. iflastsn.Checked = false;
  312. LockMakeCode.Checked = true;
  313. //勾选了前一工单
  314. if (iflastsn.Checked)
  315. {
  316. dt = (DataTable)dh.ExecuteSql("select ms_id,ms_makecode,ms_craftcode,ms_status,ms_nextstepcode,ms_prodcode,ms_code from makeserial where ms_sncode='" + code.Text + "' and ms_makecode<>'" + ma_code.Text + "' order by ms_id desc", "select");
  317. string make_code = "";
  318. string make_prodcode = "";
  319. string nextstepcode = "";
  320. string ms_status = "";
  321. if (dt.Rows.Count > 0)
  322. {
  323. ms_id = dt.Rows[0]["ms_id"].ToString();
  324. make_code = dt.Rows[0]["ms_makecode"].ToString();
  325. make_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  326. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  327. ms_status = dt.Rows[0]["ms_status"].ToString();
  328. //判断序列号的前一工单是否已经完工
  329. if (dt.Rows[0]["ms_makecode"].ToString() != ma_code.Text && dt.Rows[0]["ms_status"].ToString() == "2")
  330. {
  331. sql.Clear();
  332. sql.Append("select sp_id,sp_soncode from make inner join stepbom on ma_prodcode=sb_prodcode and ma_bomversion=sb_bomversion left ");
  333. sql.Append("join stepproduct on sp_sbid=sb_id where ma_code='" + ma_code.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' ");
  334. sql.Append("and sp_stepcode='" + User.CurrentStepCode + "' and nvl(sp_ifforsn,0)<>0");
  335. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  336. if (dt.Rows.Count > 0)
  337. {
  338. string sp_id = dt.Rows[0]["sp_id"].ToString();
  339. string sp_soncode = dt.Rows[0]["sp_soncode"].ToString();
  340. if (!dh.CheckExist("Craftmaterial", "cm_makecode='" + ma_code.Text + "' and cm_soncode='" + make_prodcode + "' and cm_sncode='" + code.Text + "' and cm_status=0"))
  341. {
  342. CollectDataSonCode.Add(sp_soncode);
  343. SPID.Add(sp_id);
  344. CollectData.Add(code.Text.Substring(0, code.Text.Length > 80 ? 80 : code.Text.Length));
  345. sn_code.Text = code.Text;
  346. OperateResult.AppendText(">>序列号" + code.Text + ",物料" + sp_soncode + "上料成功\n", Color.Green);
  347. RemainIndex = RemainIndex + 1;
  348. GetItem();
  349. return;
  350. }
  351. else
  352. {
  353. GetItem();
  354. }
  355. }
  356. else OperateResult.AppendText(">>序列号" + code.Text + "无生产信息\n", Color.Red, code);
  357. }
  358. else OperateResult.AppendText(">>序列号" + code.Text + "已被工单" + dt.Rows[0]["ms_makecode"].ToString() + "绑定,尚未完工\n", Color.Red, code);
  359. }
  360. else OperateResult.AppendText(">>序列号" + code.Text + "无生产信息\n", Color.Red, code);
  361. }
  362. else
  363. {
  364. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id='"+oMsid+"' order by ms_id desc", "select");
  365. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  366. ms_status = dt.Rows[0]["ms_status"].ToString();
  367. sn_code.Text = code.Text;
  368. sql.Clear();
  369. sql.Append("select ma_code,ma_softversion,ma_ecncode,ma_prodcode,pr_spec,ma_qty from makeserial left join product ");
  370. sql.Append(" on ms_prodcode=pr_code left join make on ms_makecode=ma_code left join ");
  371. sql.Append("makecraftdetail on mcd_macode=ms_makecode where ms_id='" + oMsid + "'");
  372. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  373. BaseUtil.SetFormValue(this.Controls, dt);
  374. OperateResult.AppendText(">>获取序列号" + code.Text + "成功\n", Color.Green);
  375. GetItem();
  376. }
  377. }
  378. else
  379. {
  380. OperateResult.AppendText(">>序列号" + code.Text + "不存在\n", Color.Red, code);
  381. code.Text = "";
  382. sn_code.Text = "";
  383. }
  384. }
  385. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  386. }
  387. private void GetItem()
  388. {
  389. //单独用一个DataTable存储一个
  390. dt1 = new DataTable();
  391. sql.Clear();
  392. sql.Append("select max(sp_id)sp_id,max(sp_detno)sp_detno,min(sp_ifrepeat)sp_ifrepeat,max(sp_checkbarcode)sp_checkbarcode,nvl(min(sp_checksalecode),0)sp_checksalecode,");
  393. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  394. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  395. sql.Append("sp_regex,max(pr_detail)pr_detail,max(substr(pr_spec,0,20))pr_spec from stepproduct left join product on pr_code=sp_fsoncode where ");
  396. sql.Append("sp_bomversion='" + ma_bomversion.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' ");
  397. sql.Append("And sp_mothercode ='" + ma_prodcode.Text + "' and sp_tracekind=1 and not exists(select 1 from craftmaterial where ");
  398. sql.Append("cm_sncode in (select '" + ms_firstsn + "' from dual union select sn from makesnrelation where firstsn='" + ms_firstsn + "') and cm_makecode='" + ma_code.Text + "' and cm_fsoncode=");
  399. sql.Append("sp_fsoncode and cm_status=0) group by sp_fsoncode order by SP_DETNO asc");
  400. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  401. code.Clear();
  402. //用于记录提醒的数据长度
  403. RemainList = new string[dt1.Rows.Count];
  404. for (int i = 0; i < dt1.Rows.Count; i++)
  405. {
  406. string soncode = dt1.Rows[i]["sp_soncode"].ToString();
  407. string prdetail = dt1.Rows[i]["pr_detail"].ToString();
  408. RemainList[i] = soncode + "(" + prdetail + ")";
  409. }
  410. if (dt1.Rows.Count > 0)
  411. {
  412. try
  413. {
  414. string soncode = dt1.Rows[RemainIndex]["sp_soncode"].ToString();
  415. string prdetail = dt1.Rows[RemainIndex]["pr_detail"].ToString();
  416. OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
  417. }
  418. catch (Exception)
  419. {
  420. OperateResult.AppendText(">>序列号" + sn_code.Text + "上料采集完成!\n", Color.Green);
  421. code.Text = "";
  422. sn_code.Text = "";
  423. }
  424. }
  425. else
  426. {
  427. OperateResult.AppendText(">>序列号" + sn_code.Text + "不在本道工序,请采集其它序列号\n", Color.Black);
  428. if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sn_code.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  429. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  430. else
  431. {
  432. //提示正确返回时传递的信息
  433. if (ErrorMessage.Contains("AFTERSUCCESS"))
  434. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  435. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  436. }
  437. code.Text = "";
  438. sn_code.Text = "";
  439. }
  440. }
  441. //此类中通用的保存逻辑
  442. private void Save_OtherCode(string sp_fsoncode, string sp_soncode, string ma_code, string ms_sncode, string sp_id)
  443. {
  444. CollectDataSonCode.Add(sp_soncode);
  445. //采集成功提示
  446. CollectData.Add(code.Text.Substring(0, code.Text.Length > 80 ? 80 : code.Text.Length));
  447. if (!CheckBarcode.ContainsKey(sp_fsoncode))
  448. {
  449. CheckBarcode.Add(sp_fsoncode, code.Text.Substring(0, code.Text.Length > 80 ? 80 : code.Text.Length));
  450. }
  451. SPID.Add(sp_id);
  452. OperateResult.AppendText(">>物料" + sp_soncode + "采集成功,条码" + code.Text + "\n", Color.Green);
  453. LabelDataGridView.Rows[RemainIndex].Cells["BarCode"].Value = code.Text;
  454. if (code.Text.Length > 80)
  455. OperateResult.AppendText(">>采集条码" + code.Text + "程度超过长度限制80,内容截取前80位进行采集\n", Color.Red);
  456. code.Clear();
  457. RemainIndex = RemainIndex + 1;
  458. //如果+1后不小于B序列的长度,则已采集完成,不需要进行提示了
  459. if (RemainIndex < RemainList.Length)
  460. {
  461. OperateResult.AppendText("<<请采集" + RemainList[RemainIndex] + "的物料数据\n", Color.Black);
  462. }
  463. else
  464. {
  465. sql.Clear();
  466. sql.Append("insert into Craftmaterial (cm_id ,cm_makecode,cm_maid,cm_maprodcode, cm_soncode, cm_mscode, cm_sncode, cm_stepcode, cm_stepname,cm_fsoncode,");
  467. sql.Append("cm_craftcode,cm_craftname,cm_barcode,cm_inqty,cm_indate,cm_inman,cm_linecode,cm_wccode,cm_sourcecode,cm_spid,cm_status,cm_materialtype,cm_firstsn)");
  468. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  469. sql.Append("mcd_stepname,sp_fsoncode,ms_craftcode,ms_craftname,:barcode,1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "',ma_wccode,");
  470. sql.Append("'" + User.UserSourceCode + "',:sp_id,0,1,ms_firstsn from make left join makecraftdetail on mcd_macode=ma_code left join stepproduct on sp_stepcode=mcd_stepcode ");
  471. sql.Append(" and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code and sp_craftcode=ms_craftcode ");
  472. sql.Append("where ma_code='" + make_code + "'and sp_id=:sp_id1 and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_id='"+oMsid+"'");
  473. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode", "sp_id", "sp_id1" }, CollectDataSonCode.ToArray(), CollectData.ToArray(), SPID.ToArray(), SPID.ToArray());
  474. try
  475. {
  476. string Log = "";
  477. for (int i = 0; i < CollectDataSonCode.Count; i++)
  478. {
  479. Log += CollectDataSonCode.ToArray()[i] + " " + CollectData.ToArray()[i] + " " + SPID.ToArray()[i];
  480. }
  481. LogManager.DoLog(Log);
  482. }
  483. catch (Exception)
  484. {
  485. }
  486. //更新序列号半成品已被使用
  487. dh.BatchInsert("update makeserial set ms_nextmacode='" + ma_code + "' where ms_id=(select max(ms_id) from makeserial where ms_sncode=:sncode and ms_nextmacode is null and ms_makecode<>'" + ma_code + "')", new string[] { "sncode" }, TSN.ToArray());
  488. if (ma_ecncode_label.Checked || ma_softversion_label.Checked)
  489. {
  490. string ecnText = ma_ecncode_label.Checked ? ma_ecncode.Text : "";
  491. string softversionText = ma_softversion_label.Checked ? ma_softversion.Text : "";
  492. string remark = sir_remark_label.Checked ? sir_remark.Text : "";
  493. sql.Clear();
  494. sql.Append("insert into SNRELATIONINFORECORD(SIR_ID,SIR_SNCODE,SIR_MSCODE,SIR_ECNCODE,SIR_SOFTVER,");
  495. sql.Append("SIR_LINECODE,SIR_SOURCECODE,SIR_STEPCODE,SIR_MACODE,SIR_PRODCODE,SIR_INMAN,SIR_INDATE,sir_firstsn,sir_remark) select ");
  496. sql.Append("SNRELATIONINFORECORD_SEQ.nextval,'" + sn_code.Text + "',ms_code,'" + ecnText + "','" + softversionText + "',");
  497. sql.Append("'" + User.UserLineCode + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + ma_code + "','" + ma_prodcode.Text + "',");
  498. sql.Append("'" + User.UserCode + "',sysdate,ms_firstsn,'" + remark + "' from makeserial where ms_sncode='" + sn_code.Text + "' and ms_makecode='" + ma_code + "'");
  499. dh.ExecuteSql(sql.GetString(), "insert");
  500. }
  501. CollectData.Clear();
  502. TSN.Clear();
  503. SPID.Clear();
  504. CheckBarcode.Clear();
  505. CollectDataSonCode.Clear();
  506. //采集成功,设置序列号栏目为空
  507. RemainIndex = 0;
  508. OperateResult.AppendText(">>序列号" + sn_code.Text + "上料采集完成!\n", Color.Green);
  509. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上料采集", "上料成功", sn_code.Text, "");
  510. if (LogicHandler.SetStepResult(ma_code, User.UserSourceCode, sn_code.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  511. {
  512. //提示正确返回时传递的信息
  513. if (ErrorMessage.Contains("AFTERSUCCESS"))
  514. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  515. sn_code.Text = "";
  516. //刷新数据
  517. EventArgs e = new EventArgs();
  518. object sender = null;
  519. ma_code_UserControlTextChanged(sender, e);
  520. }
  521. else
  522. {
  523. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  524. }
  525. }
  526. }
  527. private void ClearSn_code_Click(object sender, EventArgs e)
  528. {
  529. sn_code.Clear();
  530. SPID.Clear();
  531. TSN.Clear();
  532. CheckBarcode.Clear();
  533. CollectData.Clear();
  534. CollectDataSonCode.Clear();
  535. if (dt1 != null)
  536. BaseUtil.CleanDataTableData(dt1);
  537. RemainIndex = 0;
  538. BaseUtil.CleanDGVData(LabelDataGridView);
  539. OperateResult.AppendText(">>请采集序列号\n", Color.Black);
  540. }
  541. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  542. {
  543. if (ma_code.Text.Length > 5)
  544. {
  545. string ErrMessage = "";
  546. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  547. {
  548. mcd_inqty.Text = "";
  549. mcd_remainqty.Text = "";
  550. sql.Clear();
  551. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  552. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code where ");
  553. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  554. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  555. if (dt.Rows.Count > 0)
  556. BaseUtil.SetFormValue(Controls, dt);
  557. }
  558. }
  559. }
  560. }
  561. }