Make_PreFeedingCollection.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. //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. int CollectCount = 0;
  51. public Make_PreFeedingCollection()
  52. {
  53. InitializeComponent();
  54. }
  55. private void Make_FeedingCollection_Load(object sender, EventArgs e)
  56. {
  57. asc.controllInitializeSize(this);
  58. string cachenum = BaseUtil.GetCacheData("ProdCodeNum").ToString();
  59. ProdNum.Value = decimal.Parse(cachenum == "" ? "1" : cachenum);
  60. LockMakeCode.GetMakeCodeCtl(ma_code);
  61. ma_code.SetLockCheckBox(LockMakeCode);
  62. //工单号放大镜配置
  63. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  64. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品名称,ma_bomversion # Bom版本,ma_softversion # 软件版本,ma_ecncode # ECN号";
  65. ma_code.FormName = Name;
  66. ma_code.DBTitle = "工单查询";
  67. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion", "ma_ecncode" };
  68. ma_code.Condition = "ma_statuscode='STARTED'";
  69. ma_code.DbChange += Ma_code_DBChange;
  70. code.Focus();
  71. dh = SystemInf.dh;
  72. StepCount.StepCode = User.CurrentStepCode;
  73. StepCount.Source = User.UserSourceCode;
  74. StepCount.LineCode = User.UserLineCode;
  75. StepCount.Dh = dh;
  76. StepCount.Start();
  77. }
  78. private void Ma_code_DBChange(object sender, EventArgs e)
  79. {
  80. DBFind = ma_code.ReturnData;
  81. BaseUtil.SetFormValue(this.Controls, DBFind);
  82. GetItem();
  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. else
  111. {
  112. if (mainbarcode.Text == "")
  113. {
  114. mainbarcode.Text = code.Text;
  115. GetItem();
  116. code.Clear();
  117. return;
  118. }
  119. string sp_soncode = "";
  120. string sp_fsoncode = "";
  121. string sp_prefix = "";
  122. string sp_regex = "";
  123. string length = "";
  124. string sp_id = "";
  125. string sp_ifrepeat = "";
  126. string sp_ifforsn = "";
  127. string sp_barcoderule = "";
  128. string sp_checkbarcode = "";
  129. string sp_checksalecode = "";
  130. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  131. {
  132. object value = LabelDataGridView.Rows[i].Cells["BarCode"].Value;
  133. if (value == null || (value != null && value.ToString() == ""))
  134. {
  135. RemainIndex = i;
  136. sp_soncode = dt1.Rows[i]["sp_soncode"].ToString();
  137. sp_fsoncode = dt1.Rows[i]["sp_fsoncode"].ToString();
  138. sp_prefix = dt1.Rows[i]["sp_prefix"].ToString();
  139. sp_regex = dt1.Rows[i]["sp_regex"].ToString();
  140. length = dt1.Rows[i]["sp_length"].ToString();
  141. sp_id = dt1.Rows[i]["sp_id"].ToString();
  142. sp_ifrepeat = dt1.Rows[i]["sp_ifrepeat"].ToString();
  143. sp_ifforsn = dt1.Rows[i]["sp_ifforsn"].ToString();
  144. sp_barcoderule = dt1.Rows[i]["sp_barcoderule"].ToString();
  145. sp_checkbarcode = dt1.Rows[i]["sp_checkbarcode"].ToString();
  146. sp_checksalecode = dt1.Rows[i]["sp_checksalecode"].ToString();
  147. break;
  148. }
  149. }
  150. if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  151. {
  152. //查询条码是否存在预加工列表
  153. if (dh.CheckExist("BEFOREHANDPROCESS", "bhp_barcode='" + code.Text + "'"))
  154. {
  155. OperateResult.AppendText(">> 条码" + code.Text + "已经上料\n", Color.Red, code);
  156. return;
  157. }
  158. LabelDataGridView.Rows[RemainIndex].Cells["BarCode"].Value = code.Text;
  159. string maincode = LabelDataGridView.Rows[0].Cells["BarCode"].Value.ToString();
  160. sql.Clear();
  161. sql.Append("insert into BEFOREHANDPROCESS(bhp_id,bhp_maincode,bhp_barcode,bhp_prodcode,bhp_indate,bhp_inman)");
  162. sql.Append("values(BEFOREHANDPROCESS_seq.nextval,'" + maincode + "','" + code.Text + "','" + sp_fsoncode + "',sysdate,'" + User.UserCode + "')");
  163. dh.ExecuteSql(sql.GetString(), "insert");
  164. OperateResult.AppendText(">> 条码" + code.Text + "上料成功\n", Color.Green, code);
  165. code.Clear();
  166. CollectCount = CollectCount + 1;
  167. if (CollectCount == ProdNum.Value)
  168. {
  169. mainbarcode.Text = "";
  170. CollectCount = 0;
  171. SetCheck set = new SetCheck("OK", Color.Green);
  172. BaseUtil.SetFormCenter(set);
  173. set.ShowDialog();
  174. }
  175. }
  176. else
  177. {
  178. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  179. SetCheck set = new SetCheck("NG", Color.Red);
  180. BaseUtil.SetFormCenter(set);
  181. set.ShowDialog();
  182. }
  183. }
  184. }
  185. else if (UnLoading.Checked)
  186. {
  187. bool finddata = false;
  188. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  189. {
  190. object value = LabelDataGridView.Rows[i].Cells["BarCode"].Value;
  191. if (value != null && value.ToString() != "")
  192. {
  193. if (code.Text == value.ToString())
  194. {
  195. finddata = true;
  196. //拆解主物料,全部解绑
  197. if (i == 0)
  198. {
  199. string yes_or_no = MessageBox.Show(this.ParentForm, "是否解绑所有物料", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  200. if (yes_or_no == "Yes")
  201. {
  202. sql.Clear();
  203. sql.Append("delete from BEFOREHANDPROCESS where bhp_maincode='" + code.Text + "'");
  204. dh.ExecuteSql(sql.GetString(), "delete");
  205. mainbarcode.Text = "";
  206. GetItem();
  207. }
  208. }
  209. else
  210. {
  211. sql.Clear();
  212. sql.Append("delete from BEFOREHANDPROCESS where bhp_barcode='" + code.Text + "'");
  213. dh.ExecuteSql(sql.GetString(), "delete");
  214. LabelDataGridView.Rows[i].Cells["BarCode"].Value = "";
  215. }
  216. OperateResult.AppendText(">> 条码" + code.Text + "下料成功\n", Color.Green, code);
  217. }
  218. }
  219. }
  220. if (!finddata)
  221. {
  222. OperateResult.AppendText(">>条码" + code.Text + "未上料\n", Color.Red, code);
  223. }
  224. }
  225. }
  226. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  227. }
  228. }
  229. private void SaveData()
  230. {
  231. List<string> pr_code = new List<string>();
  232. List<string> barcode = new List<string>();
  233. }
  234. private void GetItem()
  235. {
  236. //单独用一个DataTable存储一个
  237. dt1 = new DataTable();
  238. if (mainbarcode.Text == "")
  239. {
  240. sql.Clear();
  241. 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,");
  242. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  243. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  244. sql.Append("sp_regex,max(substr(pr_spec,0,20))pr_detail from stepproduct left join stepbom on sb_bomversion=sp_bomversion ");
  245. sql.Append("left join product on pr_code=sp_fsoncode where ");
  246. sql.Append("sp_mothercode ='" + ma_prodcode.Text + "' and sp_tracekind=1 and sp_ifbeforhandle=-1 group by sp_fsoncode order by SP_DETNO asc");
  247. }
  248. else
  249. {
  250. sql.Clear();
  251. 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,");
  252. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  253. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  254. 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 ");
  255. 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 ");
  256. 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");
  257. }
  258. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  259. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  260. }
  261. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  262. {
  263. if (ma_code.Text.Length > 5)
  264. {
  265. string ErrMessage = "";
  266. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  267. {
  268. mcd_inqty.Text = "";
  269. mcd_remainqty.Text = "";
  270. sql.Clear();
  271. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  272. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code where ");
  273. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  274. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  275. if (dt.Rows.Count > 0)
  276. BaseUtil.SetFormValue(Controls, dt);
  277. }
  278. }
  279. }
  280. private void ClearSn_code_Click(object sender, EventArgs e)
  281. {
  282. mainbarcode.Clear();
  283. code.Clear();
  284. if (dt1 != null)
  285. BaseUtil.CleanDataTableData(dt1);
  286. RemainIndex = 0;
  287. BaseUtil.CleanDGVData(LabelDataGridView);
  288. OperateResult.AppendText(">>请采集条码\n", Color.Black);
  289. GetItem();
  290. }
  291. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  292. {
  293. BaseUtil.SetCacheData("ProdCodeNum", ProdNum.Value.ToString());
  294. }
  295. }
  296. }