Make_FeedingCollection.cs 37 KB

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