Make_FeedingCollection1.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. using System.IO.Ports;
  14. using DevExpress.XtraPrinting;
  15. namespace UAS_MES_NEW.Make
  16. {
  17. public partial class Make_FeedingCollection1 : Form
  18. {
  19. //MakeSerial表主键
  20. string ms_id;
  21. //制造单号
  22. string make_code;
  23. //产品编号
  24. string make_prodcode;
  25. //工序编号
  26. string nextstepcode;
  27. //完工状态
  28. string ms_status;
  29. //工艺路线编号
  30. //Bom版本
  31. string mabomversion;
  32. string ErrorMessage = "";
  33. List<string> TSN = new List<string>();
  34. Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
  35. //用于提醒的序列B
  36. string[] RemainList = new string[0];
  37. //提醒序列的索引
  38. int RemainIndex = 0;
  39. string oMakeCode = "";
  40. string oMsid = "";
  41. string ms_firstsn = "";
  42. DataHelper dh;
  43. LogStringBuilder sql = new LogStringBuilder();
  44. DataTable DBFind;
  45. DataTable dt;
  46. //保存ListB中的数据
  47. DataTable dt1;
  48. AutoSizeFormClass asc = new AutoSizeFormClass();
  49. List<string> CollectData = new List<string>();
  50. List<string> CollectDataSonCode = new List<string>();
  51. List<string> SPID = new List<string>();
  52. public Make_FeedingCollection1()
  53. {
  54. InitializeComponent();
  55. }
  56. private void Make_FeedingCollection_Load(object sender, EventArgs e)
  57. {
  58. asc.controllInitializeSize(this);
  59. LockMakeCode.GetMakeCodeCtl(ma_code);
  60. ma_code.SetLockCheckBox(LockMakeCode);
  61. //工单号放大镜配置
  62. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  63. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品名称,ma_bomversion # Bom版本,ma_softversion # 软件版本,ma_ecncode # ECN号";
  64. ma_code.FormName = Name;
  65. ma_code.DBTitle = "工单查询";
  66. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion", "ma_ecncode" };
  67. ma_code.Condition = "ma_statuscode='STARTED'";
  68. ma_code.DbChange += Ma_code_DBChange;
  69. code.Focus();
  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. if (User.UserAccountType == "admin")
  77. {
  78. UnLoading.Enabled = true;
  79. }
  80. }
  81. private void Ma_code_DBChange(object sender, EventArgs e)
  82. {
  83. DBFind = ma_code.ReturnData;
  84. BaseUtil.SetFormValue(this.Controls, DBFind);
  85. 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();
  86. if (ifforsn != "" && ifforsn != "0")
  87. iflastsn.Checked = true;
  88. else
  89. iflastsn.Checked = false;
  90. }
  91. private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
  92. {
  93. asc.controlAutoSize(this);
  94. }
  95. private void Clean_Click(object sender, EventArgs e)
  96. {
  97. OperateResult.Clear();
  98. }
  99. private void Confirm_Click(object sender, EventArgs e)
  100. {
  101. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  102. code_KeyDown(sender, e2);
  103. }
  104. private void code_KeyDown(object sender, KeyEventArgs e)
  105. {
  106. if (e.KeyCode == Keys.Enter)
  107. {
  108. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  109. {
  110. if (Loading.Checked)
  111. {
  112. if (code.Text.Replace(" ", "") == "")
  113. {
  114. OperateResult.AppendText(">>采集数据不可为空\n", Color.Red);
  115. return;
  116. }
  117. //如果录入框和工单号均有输入
  118. if (code.Text != "" && ma_code.Text != "" && sn_code.Text == "")
  119. {
  120. GetCollectItem();
  121. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  122. }
  123. //输入框有值但未选择工单号
  124. else if (code.Text != "" && ma_code.Text == "" && sn_code.Text == "")
  125. {
  126. GetCollectItem();
  127. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  128. }
  129. else if (sn_code.Text != "")
  130. {
  131. if (dh.CheckExist("makesnlist", "msl_sncode='" + code.Text + "'"))
  132. {
  133. if (CollectDataSonCode.ToArray().Length > 0)
  134. {
  135. sql.Clear();
  136. 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,");
  137. 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)");
  138. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  139. sql.Append("mcd_stepname,sp_fsoncode,ms_craftcode,ms_craftname,:barcode,1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "',ma_wccode,");
  140. sql.Append("'" + User.UserSourceCode + "',:sp_id,0,1,ms_firstsn from make left join makecraftdetail on mcd_maid=ma_id left join stepproduct on sp_stepcode=mcd_stepcode ");
  141. sql.Append(" and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code and sp_craftcode=ms_craftcode ");
  142. sql.Append("where ma_code='" + make_code + "'and sp_id=:sp_id1 and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + sn_code.Text + "'");
  143. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode", "sp_id", "sp_id1" }, CollectDataSonCode.ToArray(), CollectData.ToArray(), SPID.ToArray(), SPID.ToArray());
  144. }
  145. sn_code.Clear();
  146. SPID.Clear();
  147. TSN.Clear();
  148. CheckBarcode.Clear();
  149. CollectData.Clear();
  150. CollectDataSonCode.Clear();
  151. if (dt1 != null)
  152. BaseUtil.CleanDataTableData(dt1);
  153. RemainIndex = 0;
  154. BaseUtil.CleanDGVData(LabelDataGridView);
  155. GetCollectItem();
  156. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  157. return;
  158. }
  159. //索引超出长度表示内容均已提醒
  160. if (RemainIndex >= RemainList.Length)
  161. {
  162. OperateResult.AppendText(">>当前序列号" + sn_code.Text + "不在本道工序,请采集其它序列号\n", Color.Red);
  163. sn_code.Text = "";
  164. code.Text = "";
  165. return;
  166. }
  167. string sp_soncode = dt1.Rows[RemainIndex]["sp_soncode"].ToString();
  168. string sp_fsoncode = dt1.Rows[RemainIndex]["sp_fsoncode"].ToString();
  169. string sp_prefix = dt1.Rows[RemainIndex]["sp_prefix"].ToString();
  170. string sp_regex = dt1.Rows[RemainIndex]["sp_regex"].ToString();
  171. string length = dt1.Rows[RemainIndex]["sp_length"].ToString();
  172. string sp_id = dt1.Rows[RemainIndex]["sp_id"].ToString();
  173. string sp_ifrepeat = dt1.Rows[RemainIndex]["sp_ifrepeat"].ToString();
  174. string sp_ifforsn = dt1.Rows[RemainIndex]["sp_ifforsn"].ToString();
  175. string sp_barcoderule = dt1.Rows[RemainIndex]["sp_barcoderule"].ToString();
  176. string sp_checkbarcode = dt1.Rows[RemainIndex]["sp_checkbarcode"].ToString();
  177. string sp_checksalecode = dt1.Rows[RemainIndex]["sp_checksalecode"].ToString();
  178. if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  179. {
  180. //判断采集的条码和本次采集的也不能重复
  181. if (CollectData.Contains(code.Text) && sp_ifrepeat != "-1")
  182. {
  183. OperateResult.AppendText(">>条码" + code.Text + "已经上料\n", Color.Red, code);
  184. return;
  185. }
  186. if (sp_checkbarcode != "")
  187. {
  188. if (CheckBarcode.ContainsKey(sp_checkbarcode))
  189. {
  190. if (CheckBarcode[sp_checkbarcode] != code.Text)
  191. {
  192. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  193. return;
  194. }
  195. }
  196. else
  197. {
  198. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  199. return;
  200. }
  201. }
  202. TSN.Add(code.Text);
  203. if (sp_barcoderule == "BARCODE")
  204. {
  205. sp_soncode = ErrorMessage;
  206. }
  207. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上物料", sn_code.Text + "上物料" + code.Text + "料号" + sp_fsoncode, sn_code.Text, "");
  208. Save_OtherCode(sp_fsoncode, sp_soncode, make_code, sn_code.Text, sp_id);
  209. }
  210. else
  211. {
  212. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  213. SetCheck set = new SetCheck("NG", Color.Red);
  214. BaseUtil.SetFormCenter(set);
  215. set.ShowDialog();
  216. }
  217. }
  218. }
  219. //勾选了下料的时候
  220. else if (UnLoading.Checked)
  221. {
  222. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
  223. {
  224. sql.Clear();
  225. sql.Append("select ms_firstsn,cm_makecode,cm_craftcode,nvl(cm_status,0)cm_status,cm_id,cm_stepcode,");
  226. sql.Append("ms_makecode,cm_mccode,cm_materialtype from craftmaterial left join makeserial on cm_makecode");
  227. sql.Append("=ms_makecode and cm_sncode=ms_sncode where cm_sncode='" + code.Text + "' and cm_makecode='" + oMakeCode + "'");
  228. sql.Append("and cm_materialtype=1 and cm_stepcode='" + User.CurrentStepCode + "' ");
  229. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  230. if (dt.Rows.Count > 0)
  231. {
  232. string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
  233. string ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  234. string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
  235. string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
  236. string cm_materialtype = dt.Rows[0]["cm_materialtype"].ToString();
  237. string cm_status = dt.Rows[0]["cm_status"].ToString();
  238. string cm_makecode = dt.Rows[0]["cm_makecode"].ToString();
  239. string cm_craftcode = dt.Rows[0]["cm_craftcode"].ToString();
  240. //清除已被使用的序列号
  241. sql.Clear();
  242. sql.Append("update makeserial set ms_nextmacode='' where ms_sncode in(select cm_barcode from craftmaterial where ");
  243. sql.Append("cm_makecode='" + cm_makecode + "' and cm_sncode='" + code.Text + "' and cm_stepcode='" + cm_stepcode + "' and cm_craftcode='" + cm_craftcode + "' ");
  244. sql.Append("and cm_materialtype=1 and nvl(cm_status,0) =0) and ms_nextmacode='" + oMakeCode + "'");
  245. dh.ExecuteSql(sql.GetString(), "update");
  246. //进行下料
  247. sql.Clear();
  248. sql.Append("delete from craftmaterial where (cm_sncode in (select sn from makesnrelation where firstsn");
  249. sql.Append("='" + ms_firstsn + "') or cm_sncode = '" + ms_firstsn + "') and cm_makecode = '" + oMakeCode + "' ");
  250. sql.Append("and cm_status = 0 and cm_stepcode='" + User.CurrentStepCode + "' and cm_materialtype=1");
  251. dh.ExecuteSql(sql.GetString(), "delete");
  252. LogicHandler.InsertMakeProcess(ms_macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
  253. //刷新界面值
  254. sql.Clear();
  255. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  256. sql.Append("from make left join makecraftdetail_view on mcd_macode=ma_code where ");
  257. sql.Append("ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  258. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  259. BaseUtil.SetFormValue(Controls, dt);
  260. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上料采集", "下料成功", code.Text, "");
  261. OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
  262. }
  263. else OperateResult.AppendText(">>序列号" + code.Text + "未上料,无需下料\n", Color.Red, code);
  264. }
  265. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  266. }
  267. }
  268. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  269. }
  270. }
  271. //获取采集的项目
  272. private void GetCollectItem()
  273. {
  274. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(code.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  275. if (!NoteAlready)
  276. {
  277. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  278. return;
  279. }
  280. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + code.Text + "' order by ms_id desc", "select");
  281. if (dt.Rows.Count > 0)
  282. {
  283. code.Text = dt.Rows[0]["ms_sncode"].ToString();
  284. }
  285. else
  286. {
  287. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + code.Text + "' order by ms_id desc", "select");
  288. if (dt.Rows.Count > 0)
  289. {
  290. code.Text = dt.Rows[0]["ms_sncode"].ToString();
  291. }
  292. else
  293. {
  294. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + code.Text + "' order by mil_id desc", "select");
  295. if (dt.Rows.Count > 0)
  296. {
  297. code.Text = dt.Rows[0]["mil_sncode"].ToString();
  298. }
  299. else
  300. {
  301. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + code.Text + "' order by mil_id desc", "select");
  302. if (dt.Rows.Count > 0)
  303. {
  304. code.Text = dt.Rows[0]["mil_sncode"].ToString();
  305. }
  306. }
  307. }
  308. }
  309. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
  310. {
  311. nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
  312. if (nextstepcode != User.CurrentStepCode)
  313. {
  314. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  315. OperateResult.AppendText("<<序列号:" + code.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, code);
  316. return;
  317. }
  318. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(code.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  319. {
  320. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  321. return;
  322. }
  323. //将录入框的值给序列号
  324. sn_code.Text = code.Text;
  325. sql.Clear();
  326. 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");
  327. sql.Append(",ms_prodcode,ms_makecode,ms_code,ms_stepname from makeserial left join make on ma_code=ms_makecode ");
  328. sql.Append("left join product on ms_prodcode=pr_code where ms_sncode='" + code.Text + "' order by ms_id desc");
  329. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  330. if (dt.Rows.Count > 0)
  331. {
  332. ms_id = dt.Rows[0]["ms_id"].ToString();
  333. make_code = dt.Rows[0]["ma_code"].ToString();
  334. mabomversion = dt.Rows[0]["ma_bomversion"].ToString();
  335. make_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  336. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  337. ms_status = dt.Rows[0]["ms_status"].ToString();
  338. ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  339. BaseUtil.SetFormValue(this.Controls, dt);
  340. 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();
  341. if (ifforsn != "" && ifforsn != "0")
  342. iflastsn.Checked = true;
  343. else
  344. iflastsn.Checked = false;
  345. LockMakeCode.Checked = true;
  346. //勾选了前一工单
  347. if (iflastsn.Checked)
  348. {
  349. 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");
  350. string make_code = "";
  351. string make_prodcode = "";
  352. string nextstepcode = "";
  353. string ms_status = "";
  354. if (dt.Rows.Count > 0)
  355. {
  356. ms_id = dt.Rows[0]["ms_id"].ToString();
  357. make_code = dt.Rows[0]["ms_makecode"].ToString();
  358. make_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  359. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  360. ms_status = dt.Rows[0]["ms_status"].ToString();
  361. //判断序列号的前一工单是否已经完工
  362. if (dt.Rows[0]["ms_makecode"].ToString() != ma_code.Text && dt.Rows[0]["ms_status"].ToString() == "2")
  363. {
  364. sql.Clear();
  365. sql.Append("select sp_id,sp_soncode from make inner join stepbom on ma_prodcode=sb_prodcode and ma_bomversion=sb_bomversion left ");
  366. sql.Append("join stepproduct on sp_sbid=sb_id where ma_code='" + ma_code.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' ");
  367. sql.Append("and sp_stepcode='" + User.CurrentStepCode + "' and nvl(sp_ifforsn,0)<>0");
  368. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  369. if (dt.Rows.Count > 0)
  370. {
  371. string sp_id = dt.Rows[0]["sp_id"].ToString();
  372. string sp_soncode = dt.Rows[0]["sp_soncode"].ToString();
  373. if (!dh.CheckExist("Craftmaterial", "cm_makecode='" + ma_code.Text + "' and cm_soncode='" + make_prodcode + "' and cm_sncode='" + code.Text + "' and cm_status=0"))
  374. {
  375. CollectDataSonCode.Add(sp_soncode);
  376. SPID.Add(sp_id);
  377. CollectData.Add(code.Text);
  378. sn_code.Text = code.Text;
  379. OperateResult.AppendText(">>序列号" + code.Text + ",物料" + sp_soncode + "上料成功\n", Color.Green);
  380. RemainIndex = RemainIndex + 1;
  381. GetItem();
  382. return;
  383. }
  384. else
  385. {
  386. GetItem();
  387. }
  388. }
  389. else OperateResult.AppendText(">>序列号" + code.Text + "无生产信息\n", Color.Red, code);
  390. }
  391. else OperateResult.AppendText(">>序列号" + code.Text + "已被工单" + dt.Rows[0]["ms_makecode"].ToString() + "绑定,尚未完工\n", Color.Red, code);
  392. }
  393. else OperateResult.AppendText(">>序列号" + code.Text + "无生产信息\n", Color.Red, code);
  394. }
  395. else
  396. {
  397. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_sncode='" + code.Text + "' and ms_makecode='" + ma_code.Text + "' order by ms_id desc", "select");
  398. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  399. ms_status = dt.Rows[0]["ms_status"].ToString();
  400. sn_code.Text = code.Text;
  401. sql.Clear();
  402. sql.Append("select ma_code,ma_softversion,ma_ecncode,ma_prodcode,pr_spec,ma_qty from makeserial left join product ");
  403. sql.Append(" on ms_prodcode=pr_code left join make on ms_makecode=ma_code left join ");
  404. sql.Append("makecraftdetail_view on mcd_macode=ms_makecode where ms_id='" + oMsid + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  405. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  406. BaseUtil.SetFormValue(this.Controls, dt);
  407. OperateResult.AppendText(">>获取序列号" + code.Text + "成功\n", Color.Green);
  408. GetItem();
  409. }
  410. }
  411. else
  412. {
  413. OperateResult.AppendText(">>序列号" + code.Text + "不存在\n", Color.Red, code);
  414. code.Text = "";
  415. sn_code.Text = "";
  416. }
  417. }
  418. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  419. }
  420. private void GetItem()
  421. {
  422. //单独用一个DataTable存储一个
  423. dt1 = new DataTable();
  424. sql.Clear();
  425. sql.Append("select max(pr_lightbox)pr_lightbox,sp_id,max(sp_detno)sp_detno,min(sp_ifrepeat)sp_ifrepeat,max(sp_checkbarcode)sp_checkbarcode,min(sp_checksalecode)sp_checksalecode,");
  426. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  427. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  428. 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 ");
  429. sql.Append("sp_bomversion='" + ma_bomversion.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' ");
  430. sql.Append("And sp_mothercode ='" + ma_prodcode.Text + "' and sp_tracekind=1 and not exists(select 1 from craftmaterial where ");
  431. 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=");
  432. sql.Append("sp_fsoncode and cm_status=0) group by sp_fsoncode,sp_id order by SP_DETNO asc");
  433. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  434. code.Clear();
  435. //用于记录提醒的数据长度
  436. RemainList = new string[dt1.Rows.Count];
  437. for (int i = 0; i < dt1.Rows.Count; i++)
  438. {
  439. string soncode = dt1.Rows[i]["sp_soncode"].ToString();
  440. string prdetail = dt1.Rows[i]["pr_detail"].ToString();
  441. string pr_lightbox = dt1.Rows[i]["pr_lightbox"].ToString();
  442. if (port.IsOpen)
  443. {
  444. byte[] t = new byte[2];
  445. t[0] = 0x00;
  446. switch (pr_lightbox)
  447. {
  448. case "01":
  449. t[1] = 0X01;
  450. break;
  451. case "02":
  452. t[1] = 0X02;
  453. break;
  454. case "03":
  455. t[1] = 0X03;
  456. break;
  457. case "04":
  458. t[1] = 0X04;
  459. break;
  460. case "05":
  461. t[1] = 0X05;
  462. break;
  463. case "06":
  464. t[1] = 0X06;
  465. break;
  466. case "07":
  467. t[1] = 0X07;
  468. break;
  469. case "08":
  470. t[1] = 0X08;
  471. break;
  472. case "09":
  473. t[1] = 0X09;
  474. break;
  475. case "10":
  476. t[1] = 0X10;
  477. break;
  478. case "11":
  479. t[1] = 0X11;
  480. break;
  481. case "0A":
  482. t[1] = 0X0A;
  483. break;
  484. case "12":
  485. t[1] = 0X12;
  486. break;
  487. case "13":
  488. t[1] = 0X13;
  489. break;
  490. case "14":
  491. t[1] = 0X14;
  492. break;
  493. case "15":
  494. t[1] = 0X15;
  495. break;
  496. case "16":
  497. t[1] = 0X16;
  498. break;
  499. case "17":
  500. t[1] = 0X17;
  501. break;
  502. case "18":
  503. t[1] = 0X18;
  504. break;
  505. case "19":
  506. t[1] = 0X19;
  507. break;
  508. case "1A":
  509. t[1] = 0X1A;
  510. break;
  511. case "1B":
  512. t[1] = 0X1B;
  513. break;
  514. default:
  515. break;
  516. }
  517. port.Write(t, 0, 2);
  518. }
  519. RemainList[i] = soncode + "(" + prdetail + ")";
  520. }
  521. if (dt1.Rows.Count > 0)
  522. {
  523. try
  524. {
  525. string soncode = dt1.Rows[RemainIndex]["sp_soncode"].ToString();
  526. string prdetail = dt1.Rows[RemainIndex]["pr_detail"].ToString();
  527. OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
  528. }
  529. catch (Exception)
  530. {
  531. OperateResult.AppendText(">>序列号" + sn_code.Text + "上料采集完成!\n", Color.Green);
  532. code.Text = "";
  533. sn_code.Text = "";
  534. }
  535. }
  536. else
  537. {
  538. OperateResult.AppendText(">>序列号" + sn_code.Text + "不在本道工序,请采集其它序列号\n", Color.Red);
  539. if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sn_code.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  540. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  541. else
  542. {
  543. //提示正确返回时传递的信息
  544. if (ErrorMessage.Contains("AFTERSUCCESS"))
  545. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  546. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  547. }
  548. code.Text = "";
  549. sn_code.Text = "";
  550. }
  551. }
  552. //此类中通用的保存逻辑
  553. private void Save_OtherCode(string sp_fsoncode, string sp_soncode, string ma_code, string ms_sncode, string sp_id)
  554. {
  555. CollectDataSonCode.Add(sp_soncode);
  556. //采集成功提示
  557. CollectData.Add(code.Text);
  558. if (!CheckBarcode.ContainsKey(sp_fsoncode))
  559. {
  560. CheckBarcode.Add(sp_fsoncode, code.Text);
  561. }
  562. SPID.Add(sp_id);
  563. OperateResult.AppendText(">>物料" + sp_soncode + "采集成功,条码" + code.Text + "\n", Color.Green);
  564. LabelDataGridView.Rows[RemainIndex].Cells["BarCode"].Value = code.Text;
  565. if (code.Text.Length > 80)
  566. OperateResult.AppendText(">>采集条码" + code.Text + "程度超过长度限制80,内容截取前80位进行采集\n", Color.Red);
  567. code.Clear();
  568. RemainIndex = RemainIndex + 1;
  569. //如果+1后不小于B序列的长度,则已采集完成,不需要进行提示了
  570. if (RemainIndex < RemainList.Length)
  571. {
  572. OperateResult.AppendText("<<请采集" + RemainList[RemainIndex] + "的物料数据\n", Color.Black);
  573. }
  574. else
  575. {
  576. sql.Clear();
  577. 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,");
  578. 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)");
  579. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  580. sql.Append("mcd_stepname,sp_fsoncode,ms_craftcode,ms_craftname,:barcode,1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "',ma_wccode,");
  581. sql.Append("'" + User.UserSourceCode + "',:sp_id,0,1,ms_firstsn from make left join makecraftdetail on mcd_maid=ma_id left join stepproduct on sp_stepcode=mcd_stepcode ");
  582. sql.Append(" and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code and sp_craftcode=ms_craftcode ");
  583. sql.Append("where ma_code='" + make_code + "'and sp_id=:sp_id1 and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + ms_sncode + "'");
  584. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode", "sp_id", "sp_id1" }, CollectDataSonCode.ToArray(), CollectData.ToArray(), SPID.ToArray(), SPID.ToArray());
  585. try
  586. {
  587. string Log = "";
  588. for (int i = 0; i < CollectDataSonCode.Count; i++)
  589. {
  590. Log += CollectDataSonCode.ToArray()[i] + " " + CollectData.ToArray()[i] + " " + SPID.ToArray()[i];
  591. }
  592. LogManager.DoLog(Log);
  593. }
  594. catch (Exception)
  595. {
  596. }
  597. //更新序列号半成品已被使用
  598. 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());
  599. if (ma_ecncode_label.Checked || ma_softversion_label.Checked)
  600. {
  601. string ecnText = ma_ecncode_label.Checked ? ma_ecncode.Text : "";
  602. string softversionText = ma_softversion_label.Checked ? ma_softversion.Text : "";
  603. string remark = sir_remark_label.Checked ? sir_remark.Text : "";
  604. sql.Clear();
  605. sql.Append("insert into SNRELATIONINFORECORD(SIR_ID,SIR_SNCODE,SIR_MSCODE,SIR_ECNCODE,SIR_SOFTVER,");
  606. sql.Append("SIR_LINECODE,SIR_SOURCECODE,SIR_STEPCODE,SIR_MACODE,SIR_PRODCODE,SIR_INMAN,SIR_INDATE,sir_firstsn,sir_remark) select ");
  607. sql.Append("SNRELATIONINFORECORD_SEQ.nextval,'" + sn_code.Text + "',ms_code,'" + ecnText + "','" + softversionText + "',");
  608. sql.Append("'" + User.UserLineCode + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + ma_code + "','" + ma_prodcode.Text + "',");
  609. sql.Append("'" + User.UserCode + "',sysdate,ms_firstsn,'" + remark + "' from makeserial where ms_sncode='" + sn_code.Text + "' and ms_makecode='" + ma_code + "'");
  610. dh.ExecuteSql(sql.GetString(), "insert");
  611. }
  612. CollectData.Clear();
  613. TSN.Clear();
  614. SPID.Clear();
  615. CheckBarcode.Clear();
  616. CollectDataSonCode.Clear();
  617. //采集成功,设置序列号栏目为空
  618. RemainIndex = 0;
  619. OperateResult.AppendText(">>序列号" + sn_code.Text + "上料采集完成!\n", Color.Green);
  620. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上料采集", "上料成功", sn_code.Text, "");
  621. if (LogicHandler.SetStepResult(ma_code, User.UserSourceCode, sn_code.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  622. {
  623. if (port.IsOpen)
  624. {
  625. byte[] t = new byte[2];
  626. t[0] = 0X00;
  627. t[1] = 0XFF;
  628. port.Write(t, 0, 2);
  629. }
  630. //提示正确返回时传递的信息
  631. if (ErrorMessage.Contains("AFTERSUCCESS"))
  632. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  633. sn_code.Text = "";
  634. //刷新数据
  635. EventArgs e = new EventArgs();
  636. object sender = null;
  637. ma_code_UserControlTextChanged(sender, e);
  638. }
  639. else
  640. {
  641. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  642. }
  643. }
  644. }
  645. private void ClearSn_code_Click(object sender, EventArgs e)
  646. {
  647. sn_code.Clear();
  648. SPID.Clear();
  649. TSN.Clear();
  650. CheckBarcode.Clear();
  651. CollectData.Clear();
  652. CollectDataSonCode.Clear();
  653. if (dt1 != null)
  654. BaseUtil.CleanDataTableData(dt1);
  655. RemainIndex = 0;
  656. BaseUtil.CleanDGVData(LabelDataGridView);
  657. OperateResult.AppendText(">>请采集序列号\n", Color.Black);
  658. }
  659. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  660. {
  661. if (ma_code.Text.Length > 5)
  662. {
  663. string ErrMessage = "";
  664. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  665. {
  666. mcd_inqty.Text = "";
  667. mcd_remainqty.Text = "";
  668. sql.Clear();
  669. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  670. sql.Append("from make left join makecraftdetail_view on mcd_macode=ma_code where ");
  671. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  672. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  673. if (dt.Rows.Count > 0)
  674. BaseUtil.SetFormValue(Controls, dt);
  675. }
  676. }
  677. }
  678. SerialPort port = new SerialPort();
  679. private void OpenPort_Click(object sender, EventArgs e)
  680. {
  681. port.PortName = serialPortCombox1.Text;
  682. port.BaudRate = 9600;
  683. port.Open();
  684. OperateResult.AppendText(">>串口打开成功\n");
  685. }
  686. private void StepCount_Load(object sender, EventArgs e)
  687. {
  688. }
  689. }
  690. }