Make_PreFeedingCollection.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicMethod;
  9. using System.Drawing;
  10. using System.Text.RegularExpressions;
  11. using System.Collections.Generic;
  12. using UAS_MES_NEW.PublicForm;
  13. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_PreFeedingCollection : Form
  16. {
  17. //工艺路线编号
  18. string ErrorMessage = "";
  19. List<string> TSN = new List<string>();
  20. Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
  21. //用于提醒的序列B
  22. string[] RemainList = new string[0];
  23. //提醒序列的索引
  24. int RemainIndex = 0;
  25. DataHelper dh;
  26. LogStringBuilder sql = new LogStringBuilder();
  27. DataTable DBFind;
  28. //保存ListB中的数据
  29. DataTable dt1;
  30. AutoSizeFormClass asc = new AutoSizeFormClass();
  31. List<string> CollectData = new List<string>();
  32. List<string> CollectDataSonCode = new List<string>();
  33. List<string> SPID = new List<string>();
  34. int CollectCount = 0;
  35. public Make_PreFeedingCollection()
  36. {
  37. InitializeComponent();
  38. }
  39. private void Make_FeedingCollection_Load(object sender, EventArgs e)
  40. {
  41. asc.controllInitializeSize(this);
  42. string cachenum = BaseUtil.GetCacheData("ProdCodeNum").ToString();
  43. ProdNum.Value = decimal.Parse(cachenum == "" ? "1" : cachenum);
  44. LockMakeCode.GetMakeCodeCtl(ma_code);
  45. ma_code.SetLockCheckBox(LockMakeCode);
  46. //工单号放大镜配置
  47. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  48. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品名称,ma_bomversion # Bom版本,ma_softversion # 软件版本,ma_ecncode # ECN号";
  49. ma_code.FormName = Name;
  50. ma_code.DBTitle = "工单查询";
  51. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion", "ma_ecncode" };
  52. ma_code.Condition = "ma_statuscode='STARTED'";
  53. ma_code.DbChange += Ma_code_DBChange;
  54. code.Focus();
  55. dh = SystemInf.dh;
  56. }
  57. private void Ma_code_DBChange(object sender, EventArgs e)
  58. {
  59. DBFind = ma_code.ReturnData;
  60. BaseUtil.SetFormValue(this.Controls, DBFind);
  61. GetItem();
  62. }
  63. private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
  64. {
  65. asc.controlAutoSize(this);
  66. }
  67. private void Clean_Click(object sender, EventArgs e)
  68. {
  69. OperateResult.Clear();
  70. }
  71. private void Confirm_Click(object sender, EventArgs e)
  72. {
  73. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  74. code_KeyDown(sender, e2);
  75. }
  76. bool GetMainCode = false;
  77. private void code_KeyDown(object sender, KeyEventArgs e)
  78. {
  79. if (e.KeyCode == Keys.Enter)
  80. {
  81. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  82. {
  83. if (Loading.Checked)
  84. {
  85. string Count = dh.getFieldDataByCondition("BEFOREHANDPROCESS", "count(distinct bhp_maincode)", "bhp_makecode='" + ma_code.Text + "'").ToString();
  86. mcd_inqty1.Text = Count;
  87. if (int.Parse(ma_qty.Text) + 1 < int.Parse(Count))
  88. {
  89. OperateResult.AppendText(">>预加工数量" + Count + "已达到工单数量" + ma_qty.Text + "\n", Color.Red);
  90. return;
  91. }
  92. if (code.Text.Replace(" ", "") == "")
  93. {
  94. OperateResult.AppendText(">>采集数据不可为空\n", Color.Red);
  95. return;
  96. }
  97. else
  98. {
  99. if (mainbarcode.Text == "")
  100. {
  101. mainbarcode.Text = code.Text;
  102. GetMainCode = true;
  103. OperateResult.AppendText(">> 获取条码" + code.Text + "成功\n");
  104. GetItem();
  105. }
  106. else
  107. {
  108. GetMainCode = false;
  109. }
  110. string sp_soncode = "";
  111. string sp_fsoncode = "";
  112. string sp_prefix = "";
  113. string sp_regex = "";
  114. string length = "";
  115. string sp_id = "";
  116. string sp_ifrepeat = "";
  117. string sp_ifforsn = "";
  118. string sp_barcoderule = "";
  119. string sp_checkbarcode = "";
  120. string sp_checksalecode = "";
  121. bool needload = false;
  122. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  123. {
  124. object value = LabelDataGridView.Rows[i].Cells["BarCode"].Value;
  125. if (value == null || (value != null && value.ToString() == ""))
  126. {
  127. RemainIndex = i;
  128. needload = true;
  129. sp_soncode = dt1.Rows[i]["sp_soncode"].ToString();
  130. sp_fsoncode = dt1.Rows[i]["sp_fsoncode"].ToString();
  131. sp_prefix = dt1.Rows[i]["sp_prefix"].ToString();
  132. sp_regex = dt1.Rows[i]["sp_regex"].ToString();
  133. length = dt1.Rows[i]["sp_length"].ToString();
  134. sp_id = dt1.Rows[i]["sp_id"].ToString();
  135. sp_ifrepeat = dt1.Rows[i]["sp_ifrepeat"].ToString();
  136. sp_ifforsn = dt1.Rows[i]["sp_ifforsn"].ToString();
  137. sp_barcoderule = dt1.Rows[i]["sp_barcoderule"].ToString();
  138. sp_checkbarcode = dt1.Rows[i]["sp_checkbarcode"].ToString();
  139. sp_checksalecode = dt1.Rows[i]["sp_checksalecode"].ToString();
  140. break;
  141. }
  142. }
  143. if (GetMainCode && RemainIndex != 0)
  144. {
  145. code.Clear();
  146. return;
  147. }
  148. if (!needload)
  149. {
  150. OperateResult.AppendText(">>没有需要采集的物料,请重新采集\n", Color.Red, code);
  151. mainbarcode.Clear();
  152. SetCheck set = new SetCheck("NG", Color.Red);
  153. BaseUtil.SetFormCenter(set);
  154. set.ShowDialog();
  155. return;
  156. }
  157. if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  158. {
  159. //查询条码是否存在预加工列表
  160. if (dh.CheckExist("BEFOREHANDPROCESS", "bhp_barcode='" + code.Text + "'"))
  161. {
  162. OperateResult.AppendText(">> 条码" + code.Text + "已经上料\n", Color.Red, code);
  163. return;
  164. }
  165. //获取的主条码和绑定条码必须一致
  166. if (RemainIndex == 0)
  167. {
  168. if (code.Text != mainbarcode.Text)
  169. {
  170. OperateResult.AppendText(">>获取的主条码" + mainbarcode.Text + "和" + code.Text + "不一致\n", Color.Red, code);
  171. SetCheck set = new SetCheck("NG", Color.Red);
  172. BaseUtil.SetFormCenter(set);
  173. set.ShowDialog();
  174. return;
  175. }
  176. }
  177. LabelDataGridView.Rows[RemainIndex].Cells["BarCode"].Value = code.Text;
  178. string maincode = LabelDataGridView.Rows[0].Cells["BarCode"].Value.ToString();
  179. sql.Clear();
  180. sql.Append("insert into BEFOREHANDPROCESS(bhp_id,bhp_maincode,bhp_barcode,bhp_prodcode,bhp_indate,bhp_inman,bhp_makecode)");
  181. sql.Append("values(BEFOREHANDPROCESS_seq.nextval,'" + maincode + "','" + code.Text + "','" + sp_fsoncode + "',sysdate,'" + User.UserCode + "','" + ma_code.Text + "')");
  182. dh.ExecuteSql(sql.GetString(), "insert");
  183. OperateResult.AppendText(">> 条码" + code.Text + "上料成功\n", Color.Green, code);
  184. code.Clear();
  185. CollectCount = CollectCount + 1;
  186. if (CollectCount == ProdNum.Value || RemainIndex == LabelDataGridView.Rows.Count - 1)
  187. {
  188. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "预加工采集", "上料物料" + mainbarcode.Text, "", "");
  189. mainbarcode.Text = "";
  190. CollectCount = 0;
  191. SetCheck set = new SetCheck("OK", Color.Green);
  192. BaseUtil.SetFormCenter(set);
  193. set.ShowDialog();
  194. }
  195. }
  196. else
  197. {
  198. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  199. SetCheck set = new SetCheck("NG", Color.Red);
  200. BaseUtil.SetFormCenter(set);
  201. set.ShowDialog();
  202. }
  203. }
  204. }
  205. else if (UnLoading.Checked)
  206. {
  207. mainbarcode.Text = code.Text;
  208. GetItem();
  209. bool finddata = false;
  210. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  211. {
  212. object value = LabelDataGridView.Rows[i].Cells["BarCode"].Value;
  213. if (value != null && value.ToString() != "")
  214. {
  215. if (code.Text == value.ToString())
  216. {
  217. finddata = true;
  218. //拆解主物料,全部解绑
  219. if (i == 0)
  220. {
  221. string yes_or_no = MessageBox.Show(this.ParentForm, "是否解绑所有物料", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  222. if (yes_or_no == "Yes")
  223. {
  224. sql.Clear();
  225. sql.Append("delete from BEFOREHANDPROCESS where bhp_maincode='" + code.Text + "'");
  226. dh.ExecuteSql(sql.GetString(), "delete");
  227. mainbarcode.Text = "";
  228. GetItem();
  229. OperateResult.AppendText(">> 条码" + code.Text + "下料成功\n", Color.Green, code);
  230. }
  231. }
  232. else
  233. {
  234. sql.Clear();
  235. sql.Append("delete from BEFOREHANDPROCESS where bhp_barcode='" + code.Text + "'");
  236. dh.ExecuteSql(sql.GetString(), "delete");
  237. LabelDataGridView.Rows[i].Cells["BarCode"].Value = "";
  238. OperateResult.AppendText(">> 条码" + code.Text + "下料成功\n", Color.Green, code);
  239. }
  240. }
  241. }
  242. }
  243. if (!finddata)
  244. {
  245. OperateResult.AppendText(">>条码" + code.Text + "未上料\n", Color.Red, code);
  246. }
  247. }
  248. }
  249. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  250. }
  251. }
  252. private void SaveData()
  253. {
  254. List<string> pr_code = new List<string>();
  255. List<string> barcode = new List<string>();
  256. }
  257. private void GetItem()
  258. {
  259. //单独用一个DataTable存储一个
  260. dt1 = new DataTable();
  261. if (mainbarcode.Text == "")
  262. {
  263. sql.Clear();
  264. 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,");
  265. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  266. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  267. sql.Append("sp_regex,max(substr(pr_spec,0,20))pr_detail from stepproduct left join stepbom on sb_bomversion=sp_bomversion and sp_craftcode=sb_craftcode ");
  268. sql.Append("left join product on pr_code=sp_fsoncode where ");
  269. sql.Append("sp_mothercode ='" + ma_prodcode.Text + "' and sp_craftcode='" + ma_craftcode.Text + "' and sp_tracekind=1 and sp_ifbeforhandle=-1 group by sp_fsoncode order by SP_DETNO asc");
  270. }
  271. else
  272. {
  273. sql.Clear();
  274. 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,");
  275. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  276. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  277. sql.Append("sp_regex,max(substr(pr_spec,0,20))pr_detail,max(bhp_barcode)bhp_barcode from stepproduct left join stepbom on sb_bomversion=sp_bomversion and sp_craftcode=sb_craftcode ");
  278. sql.Append("left join product on pr_code=sp_fsoncode left join (select * from BEFOREHANDPROCESS where bhp_maincode='" + mainbarcode.Text + "') on bhp_prodcode=sp_fsoncode where ");
  279. sql.Append("sp_mothercode ='" + ma_prodcode.Text + "' and sp_craftcode='" + ma_craftcode.Text + "' and sp_tracekind=1 and sp_ifbeforhandle=-1 and (bhp_maincode='" + mainbarcode.Text + "' or bhp_maincode is null) group by sp_fsoncode order by SP_DETNO asc");
  280. }
  281. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  282. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  283. string Count = dh.getFieldDataByCondition("BEFOREHANDPROCESS", "count(distinct bhp_maincode)", "bhp_makecode='" + ma_code.Text + "'").ToString();
  284. mcd_inqty1.Text = Count;
  285. }
  286. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  287. {
  288. if (ma_code.Text.Length > 5)
  289. {
  290. string ErrMessage = "";
  291. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  292. {
  293. string Count = dh.getFieldDataByCondition("BEFOREHANDPROCESS", "count(distinct bhp_maincode)", "bhp_makecode='" + ma_code.Text + "'").ToString();
  294. mcd_inqty1.Text = Count;
  295. mcd_remainqty.Text = "";
  296. sql.Clear();
  297. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  298. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code where ");
  299. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  300. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  301. if (dt.Rows.Count > 0)
  302. BaseUtil.SetFormValue(Controls, dt);
  303. }
  304. }
  305. }
  306. private void ClearSn_code_Click(object sender, EventArgs e)
  307. {
  308. mainbarcode.Clear();
  309. code.Clear();
  310. if (dt1 != null)
  311. BaseUtil.CleanDataTableData(dt1);
  312. RemainIndex = 0;
  313. BaseUtil.CleanDGVData(LabelDataGridView);
  314. OperateResult.AppendText(">>请采集条码\n", Color.Black);
  315. GetItem();
  316. }
  317. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  318. {
  319. BaseUtil.SetCacheData("ProdCodeNum", ProdNum.Value.ToString());
  320. }
  321. }
  322. }