Make_PreFeedingCollection.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. StepCount.StepCode = User.CurrentStepCode;
  57. StepCount.Source = User.UserSourceCode;
  58. StepCount.LineCode = User.UserLineCode;
  59. StepCount.Dh = dh;
  60. StepCount.Tag1 = Tag.ToString();
  61. StepCount.Start();
  62. }
  63. private void Ma_code_DBChange(object sender, EventArgs e)
  64. {
  65. DBFind = ma_code.ReturnData;
  66. BaseUtil.SetFormValue(this.Controls, DBFind);
  67. GetItem();
  68. }
  69. private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
  70. {
  71. asc.controlAutoSize(this);
  72. }
  73. private void Clean_Click(object sender, EventArgs e)
  74. {
  75. OperateResult.Clear();
  76. }
  77. private void Confirm_Click(object sender, EventArgs e)
  78. {
  79. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  80. code_KeyDown(sender, e2);
  81. }
  82. bool GetMainCode = false;
  83. private void code_KeyDown(object sender, KeyEventArgs e)
  84. {
  85. if (e.KeyCode == Keys.Enter)
  86. {
  87. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  88. {
  89. if (Loading.Checked)
  90. {
  91. if (code.Text.Replace(" ", "") == "")
  92. {
  93. OperateResult.AppendText(">>采集数据不可为空\n", Color.Red);
  94. return;
  95. }
  96. else
  97. {
  98. if (mainbarcode.Text == "")
  99. {
  100. mainbarcode.Text = code.Text;
  101. GetMainCode = true;
  102. OperateResult.AppendText(">> 获取条码" + code.Text + "成功\n");
  103. GetItem();
  104. }
  105. else
  106. {
  107. GetMainCode = false;
  108. }
  109. string sp_soncode = "";
  110. string sp_fsoncode = "";
  111. string sp_prefix = "";
  112. string sp_regex = "";
  113. string length = "";
  114. string sp_id = "";
  115. string sp_ifrepeat = "";
  116. string sp_ifforsn = "";
  117. string sp_barcoderule = "";
  118. string sp_checkbarcode = "";
  119. string sp_checksalecode = "";
  120. bool needload = false;
  121. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  122. {
  123. object value = LabelDataGridView.Rows[i].Cells["BarCode"].Value;
  124. if (value == null || (value != null && value.ToString() == ""))
  125. {
  126. RemainIndex = i;
  127. needload = true;
  128. sp_soncode = dt1.Rows[i]["sp_soncode"].ToString();
  129. sp_fsoncode = dt1.Rows[i]["sp_fsoncode"].ToString();
  130. sp_prefix = dt1.Rows[i]["sp_prefix"].ToString();
  131. sp_regex = dt1.Rows[i]["sp_regex"].ToString();
  132. length = dt1.Rows[i]["sp_length"].ToString();
  133. sp_id = dt1.Rows[i]["sp_id"].ToString();
  134. sp_ifrepeat = dt1.Rows[i]["sp_ifrepeat"].ToString();
  135. sp_ifforsn = dt1.Rows[i]["sp_ifforsn"].ToString();
  136. sp_barcoderule = dt1.Rows[i]["sp_barcoderule"].ToString();
  137. sp_checkbarcode = dt1.Rows[i]["sp_checkbarcode"].ToString();
  138. sp_checksalecode = dt1.Rows[i]["sp_checksalecode"].ToString();
  139. break;
  140. }
  141. }
  142. if (GetMainCode && RemainIndex != 0)
  143. {
  144. code.Clear();
  145. return;
  146. }
  147. if (!needload)
  148. {
  149. OperateResult.AppendText(">>没有需要采集的物料,请重新采集\n", Color.Red, code);
  150. mainbarcode.Clear();
  151. SetCheck set = new SetCheck("NG", Color.Red);
  152. BaseUtil.SetFormCenter(set);
  153. set.ShowDialog();
  154. return;
  155. }
  156. if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  157. {
  158. //查询条码是否存在预加工列表
  159. if (dh.CheckExist("BEFOREHANDPROCESS", "bhp_barcode='" + code.Text + "'"))
  160. {
  161. OperateResult.AppendText(">> 条码" + code.Text + "已经上料\n", Color.Red, code);
  162. return;
  163. }
  164. //获取的主条码和绑定条码必须一致
  165. if (RemainIndex == 0)
  166. {
  167. if (code.Text != mainbarcode.Text)
  168. {
  169. OperateResult.AppendText(">>获取的主条码" + mainbarcode.Text + "和" + code.Text + "不一致\n", Color.Red, code);
  170. SetCheck set = new SetCheck("NG", Color.Red);
  171. BaseUtil.SetFormCenter(set);
  172. set.ShowDialog();
  173. return;
  174. }
  175. }
  176. LabelDataGridView.Rows[RemainIndex].Cells["BarCode"].Value = code.Text;
  177. string maincode = LabelDataGridView.Rows[0].Cells["BarCode"].Value.ToString();
  178. sql.Clear();
  179. sql.Append("insert into BEFOREHANDPROCESS(bhp_id,bhp_maincode,bhp_barcode,bhp_prodcode,bhp_indate,bhp_inman)");
  180. sql.Append("values(BEFOREHANDPROCESS_seq.nextval,'" + maincode + "','" + code.Text + "','" + sp_fsoncode + "',sysdate,'" + User.UserCode + "')");
  181. dh.ExecuteSql(sql.GetString(), "insert");
  182. OperateResult.AppendText(">> 条码" + code.Text + "上料成功\n", Color.Green, code);
  183. code.Clear();
  184. CollectCount = CollectCount + 1;
  185. if (CollectCount == ProdNum.Value || RemainIndex == LabelDataGridView.Rows.Count - 1)
  186. {
  187. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "预加工采集", "上料物料" + mainbarcode.Text, "", "");
  188. mainbarcode.Text = "";
  189. CollectCount = 0;
  190. SetCheck set = new SetCheck("OK", Color.Green);
  191. BaseUtil.SetFormCenter(set);
  192. set.ShowDialog();
  193. }
  194. }
  195. else
  196. {
  197. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  198. SetCheck set = new SetCheck("NG", Color.Red);
  199. BaseUtil.SetFormCenter(set);
  200. set.ShowDialog();
  201. }
  202. }
  203. }
  204. else if (UnLoading.Checked)
  205. {
  206. bool finddata = false;
  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.ToString() != "")
  211. {
  212. if (code.Text == value.ToString())
  213. {
  214. finddata = true;
  215. //拆解主物料,全部解绑
  216. if (i == 0)
  217. {
  218. string yes_or_no = MessageBox.Show(this.ParentForm, "是否解绑所有物料", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  219. if (yes_or_no == "Yes")
  220. {
  221. sql.Clear();
  222. sql.Append("delete from BEFOREHANDPROCESS where bhp_maincode='" + code.Text + "'");
  223. dh.ExecuteSql(sql.GetString(), "delete");
  224. mainbarcode.Text = "";
  225. GetItem();
  226. OperateResult.AppendText(">> 条码" + code.Text + "下料成功\n", Color.Green, code);
  227. }
  228. }
  229. else
  230. {
  231. sql.Clear();
  232. sql.Append("delete from BEFOREHANDPROCESS where bhp_barcode='" + code.Text + "'");
  233. dh.ExecuteSql(sql.GetString(), "delete");
  234. LabelDataGridView.Rows[i].Cells["BarCode"].Value = "";
  235. OperateResult.AppendText(">> 条码" + code.Text + "下料成功\n", Color.Green, code);
  236. }
  237. }
  238. }
  239. }
  240. if (!finddata)
  241. {
  242. OperateResult.AppendText(">>条码" + code.Text + "未上料\n", Color.Red, code);
  243. }
  244. }
  245. }
  246. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  247. }
  248. }
  249. private void SaveData()
  250. {
  251. List<string> pr_code = new List<string>();
  252. List<string> barcode = new List<string>();
  253. }
  254. private void GetItem()
  255. {
  256. //单独用一个DataTable存储一个
  257. dt1 = new DataTable();
  258. if (mainbarcode.Text == "")
  259. {
  260. sql.Clear();
  261. 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,");
  262. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  263. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  264. sql.Append("sp_regex,max(substr(pr_spec,0,20))pr_detail from stepproduct left join stepbom on sb_bomversion=sp_bomversion ");
  265. sql.Append("left join product on pr_code=sp_fsoncode where ");
  266. sql.Append("sp_mothercode ='" + ma_prodcode.Text + "' and sp_tracekind=1 and sp_ifbeforhandle=-1 group by sp_fsoncode order by SP_DETNO asc");
  267. }
  268. else
  269. {
  270. sql.Clear();
  271. 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,");
  272. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  273. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  274. 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 ");
  275. 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 ");
  276. sql.Append("sp_mothercode ='" + ma_prodcode.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");
  277. }
  278. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  279. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  280. }
  281. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  282. {
  283. if (ma_code.Text.Length > 5)
  284. {
  285. string ErrMessage = "";
  286. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  287. {
  288. mcd_inqty.Text = "";
  289. mcd_remainqty.Text = "";
  290. sql.Clear();
  291. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  292. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code where ");
  293. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  294. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  295. if (dt.Rows.Count > 0)
  296. BaseUtil.SetFormValue(Controls, dt);
  297. }
  298. }
  299. }
  300. private void ClearSn_code_Click(object sender, EventArgs e)
  301. {
  302. mainbarcode.Clear();
  303. code.Clear();
  304. if (dt1 != null)
  305. BaseUtil.CleanDataTableData(dt1);
  306. RemainIndex = 0;
  307. BaseUtil.CleanDGVData(LabelDataGridView);
  308. OperateResult.AppendText(">>请采集条码\n", Color.Black);
  309. GetItem();
  310. }
  311. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  312. {
  313. BaseUtil.SetCacheData("ProdCodeNum", ProdNum.Value.ToString());
  314. }
  315. }
  316. }