Make_FeedingCollectionCombineFix.cs 46 KB

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