Make_FeedingCollectionCombine.cs 33 KB

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