Make_ColorBoxLoadPrint.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES.DataOperate;
  7. using UAS_MES.PublicMethod;
  8. using UAS_MES.Entity;
  9. using LabelManager2;
  10. using System.Threading;
  11. using UAS_MES.PublicForm;
  12. using System.Collections.Generic;
  13. namespace UAS_MES.Make
  14. {
  15. public partial class Make_ColorBoxLoadPrint : Form
  16. {
  17. DataHelper dh;
  18. DataTable dt;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. //保存StepProduct查询出来的数据
  22. DataTable ListA = new DataTable();
  23. //制造单号
  24. string macode;
  25. //当前工单的序列号
  26. //string sn_code;
  27. //当前提示的索引
  28. int RemainIndex = 0;
  29. Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
  30. List<string> TSN = new List<string>();
  31. string ErrorMessage = "";
  32. System.DateTime[] indate;
  33. string ms_firstsn = "";
  34. ApplicationClass lbl;
  35. Document doc;
  36. Thread InitPrint;
  37. List<string> CollectData = new List<string>();
  38. List<string> CollectDataSonCode = new List<string>();
  39. List<string> SPID = new List<string>();
  40. public Make_ColorBoxLoadPrint()
  41. {
  42. InitializeComponent();
  43. load.Checked = true;
  44. }
  45. private void Make_ColorBoxLoadPrint_Load(object sender, EventArgs e)
  46. {
  47. asc.controllInitializeSize(this);
  48. InitPrint = new Thread(InPrint);
  49. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  50. BaseUtil.SetFormCenter(stw);
  51. stw.ShowDialog();
  52. //工单号放大镜配置
  53. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  54. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_detail # 产品名称,ma_bomversion # Bom版本";
  55. ma_code.FormName = Name;
  56. ma_code.DBTitle = "工单查询";
  57. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "ma_qty", "pr_detail", "ma_craftcode", "ma_bomversion" };
  58. ma_code.Condition = "ma_statuscode='STARTED' order by ma_updatedate desc";
  59. ma_code.DbChange += Ms_makecode_DbChange;
  60. Lock.GetMakeCodeCtl(ma_code);
  61. ma_code.SetLockCheckBox(Lock);
  62. code.Focus();
  63. dh = SystemInf.dh;
  64. StepCount.StepCode = User.CurrentStepCode;
  65. StepCount.Source = User.UserSourceCode;
  66. StepCount.LineCode = User.UserLineCode;
  67. StepCount.Dh = dh;
  68. StepCount.Start();
  69. }
  70. private void Ms_makecode_DbChange(object sender, EventArgs e)
  71. {
  72. dt = ma_code.ReturnData;
  73. BaseUtil.SetFormValue(this.Controls, dt);
  74. }
  75. private void InPrint()
  76. {
  77. try
  78. {
  79. lbl = new ApplicationClass();
  80. BaseUtil.WriteLbl();
  81. }
  82. catch (Exception ex)
  83. {
  84. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  85. }
  86. }
  87. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  88. {
  89. if (e.KeyCode == Keys.Enter)
  90. {
  91. if (code.Text == "")
  92. {
  93. OperateResult.AppendText(">>输入内容不能为空\n", Color.Red);
  94. return;
  95. }
  96. if (SystemInf.UpperCollection)
  97. {
  98. code.Text = code.Text.ToUpper();
  99. }
  100. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  101. {
  102. string Msid;
  103. if (ListA.Rows.Count == 0 && load.Checked)
  104. {
  105. if (SystemInf.GetRelation)
  106. {
  107. string sn = dh.getFieldDataByCondition("SNRELATION_VIEW", "sr_sn", "content like '%" + code.Text + "%'").ToString();
  108. int count = int.Parse(dh.getFieldDataByCondition("SNRELATION_VIEW", "count(1) cn", "content like '%" + code.Text + "%'").ToString());
  109. if (sn == ""|| count > 1)
  110. {
  111. MessageBox.Show("SN:" + code.Text + "未找到关联信息");
  112. return;
  113. }
  114. else
  115. {
  116. if (SystemInf.UpperCollection)
  117. code.Text = sn.ToUpper();
  118. else
  119. code.Text = sn;
  120. }
  121. }
  122. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage) || ListA.Rows.Count > 0)
  123. {
  124. sql.Clear();
  125. sql.Append("select ma_code,ms_craftcode,ms_sncode,ma_qty,pr_detail,pr_code,nvl(ms_bomversion,ma_bomversion) ms_bomversion,ms_firstsn from makeserial left join make on ");
  126. sql.Append("ms_makecode=ma_code left join product on ms_prodcode=pr_code where ms_id='" + Msid + "'");
  127. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  128. if (dt.Rows.Count > 0)
  129. {
  130. BaseUtil.SetFormValue(this.Controls, dt);
  131. ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  132. Lock.Checked = true;
  133. LoadCollectNum();
  134. OperateResult.AppendText(">>获取序列号" + code.Text + "成功\n", Color.Green);
  135. if (PrintLabel.SelectedValue == null)
  136. {
  137. OperateResult.AppendText(">>产品编号:" + pr_code.Text + "未维护彩盒标签\n", Color.Red, code);
  138. return;
  139. }
  140. ms_sncode.Text = code.Text;
  141. code.Text = "";
  142. }
  143. sql.Clear();
  144. 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,sp_fsoncode,max(sp_barcoderule)");
  145. sql.Append("sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  146. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)sp_regex,max(sp_instr)sp_instr");
  147. sql.Append(",max(pr_detail)pr_detail from stepproduct left join product on pr_code=sp_fsoncode where ");
  148. sql.Append("sp_bomversion='" + ms_bomversion.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' ");
  149. sql.Append("And sp_mothercode ='" + pr_code.Text + "' and sp_tracekind=1 and not exists(select 1 from craftmaterial where ");
  150. 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_soncode=");
  151. sql.Append("sp_soncode and cm_status=0) group by sp_fsoncode order by SP_DETNO asc");
  152. ListA = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  153. //获取对应 产品的机身标的打印模板
  154. if (ListA.Rows.Count > 0)
  155. {
  156. string soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
  157. string prdetail = ListA.Rows[RemainIndex]["pr_detail"].ToString();
  158. OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
  159. code.Clear();
  160. }
  161. else
  162. {
  163. OperateResult.AppendText(">>当前序列号" + ms_sncode.Text + "不在本道工序,请采集其它序列号\n", Color.Black);
  164. if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  165. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  166. else
  167. {
  168. //提示正确返回时传递的信息
  169. if (ErrorMessage.Contains("AFTERSUCCESS"))
  170. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  171. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "上料采集完成!\n", Color.Green);
  172. }
  173. return;
  174. }
  175. }
  176. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  177. }
  178. else if (unload.Checked == true)
  179. {
  180. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage))
  181. {
  182. dt = (DataTable)dh.ExecuteSql("select ms_firstsn,cm_id,cm_stepcode,ms_makecode,cm_mccode,cm_makecode,cm_craftcode from craftmaterial left join makeserial on cm_makecode=ms_makecode and cm_sncode=ms_sncode where cm_sncode='" + code.Text + "' and cm_makecode='" + macode + "' and cm_materialtype=1", "select");
  183. if (dt.Rows.Count > 0)
  184. {
  185. string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
  186. 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_makecode = dt.Rows[0]["cm_makecode"].ToString();
  190. string cm_craftcode = dt.Rows[0]["cm_craftcode"].ToString();
  191. sql.Clear();
  192. sql.Append("update makeserial set ms_nextmacode='' where ms_sncode in(select cm_barcode from craftmaterial where ");
  193. sql.Append("cm_makecode='" + cm_makecode + "' and cm_sncode='" + code.Text + "' and cm_stepcode='" + cm_stepcode + "' and cm_craftcode='" + cm_craftcode + "' ");
  194. sql.Append("and cm_materialtype=1 and nvl(cm_status,0) =0) and ms_nextmacode='" + macode + "'");
  195. dh.ExecuteSql(sql.GetString(), "update");
  196. //进行下料
  197. sql.Clear();
  198. sql.Append("delete from craftmaterial where (cm_sncode in (select sn from makesnrelation where firstsn");
  199. sql.Append("='" + ms_firstsn + "') or cm_sncode = '" + ms_firstsn + "') and cm_makecode = '" + macode + "' ");
  200. sql.Append("and cm_status = 0 and cm_stepcode='" + User.CurrentStepCode + "' and cm_materialtype=1");
  201. dh.ExecuteSql(sql.GetString(), "delete");
  202. LogicHandler.InsertMakeProcess(macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
  203. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "上料采集", "下料成功", code.Text, "");
  204. OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
  205. }
  206. else OperateResult.AppendText(">>该序列号未上料,无需下料\n", Color.Red, code);
  207. }
  208. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  209. }
  210. else
  211. {
  212. //获取上料需要传递的参数,sp_soncode,sp_id
  213. string sp_soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
  214. string sp_fsoncode = ListA.Rows[RemainIndex]["sp_fsoncode"].ToString();
  215. string sp_prefix = ListA.Rows[RemainIndex]["sp_prefix"].ToString();
  216. string sp_regex = ListA.Rows[RemainIndex]["sp_regex"].ToString();
  217. string length = ListA.Rows[RemainIndex]["sp_length"].ToString();
  218. string sp_id = ListA.Rows[RemainIndex]["sp_id"].ToString();
  219. string sp_ifrepeat = ListA.Rows[RemainIndex]["sp_ifrepeat"].ToString();
  220. string sp_ifforsn = ListA.Rows[RemainIndex]["sp_ifforsn"].ToString();
  221. string sp_barcoderule = ListA.Rows[RemainIndex]["sp_barcoderule"].ToString();
  222. string sp_checkbarcode = ListA.Rows[RemainIndex]["sp_checkbarcode"].ToString();
  223. string sp_checksalecode = ListA.Rows[RemainIndex]["sp_checksalecode"].ToString();
  224. string sp_instr = ListA.Rows[RemainIndex]["sp_instr"].ToString();
  225. 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))
  226. {
  227. //判断采集的条码和本次采集的也不能重复
  228. if (CollectData.Contains(code.Text) && sp_ifrepeat != "-1")
  229. {
  230. OperateResult.AppendText(">>条码" + code.Text + "已经上料\n", Color.Red, code);
  231. return;
  232. }
  233. TSN.Add(code.Text.Substring(0, code.Text.Length > 40 ? 40 : code.Text.Length));
  234. if (sp_checkbarcode != "")
  235. {
  236. if (CheckBarcode.ContainsKey(sp_checkbarcode))
  237. {
  238. if (CheckBarcode[sp_checkbarcode] != code.Text)
  239. {
  240. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  241. return;
  242. }
  243. }
  244. else
  245. {
  246. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  247. return;
  248. }
  249. }
  250. if (sp_barcoderule == "BARCODE")
  251. {
  252. sp_soncode = ErrorMessage;
  253. }
  254. CollectData.Add(code.Text.Substring(0, code.Text.Length > 40 ? 40 : code.Text.Length));
  255. SPID.Add(sp_id);
  256. CollectDataSonCode.Add(sp_soncode);
  257. if (!CheckBarcode.ContainsKey(sp_fsoncode))
  258. {
  259. CheckBarcode.Add(sp_fsoncode, code.Text.Substring(0, code.Text.Length > 40 ? 40 : code.Text.Length));
  260. }
  261. OperateResult.AppendText(">>物料" + code.Text + "采集成功,条码号" + code.Text + "\n", Color.Green, code);
  262. RemainIndex = RemainIndex + 1;
  263. }
  264. else
  265. {
  266. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  267. return;
  268. }
  269. code.Clear();
  270. if (RemainIndex <= ListA.Rows.Count - 1)
  271. {
  272. string soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
  273. string prdetail = ListA.Rows[RemainIndex]["pr_detail"].ToString();
  274. OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
  275. }
  276. if (RemainIndex == ListA.Rows.Count)
  277. {
  278. sql.Clear();
  279. 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,");
  280. 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)");
  281. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  282. sql.Append("mcd_stepname,sp_fsoncode,ms_craftcode,ms_craftname,:barcode,1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "',ma_wccode,");
  283. 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 ");
  284. sql.Append("and sp_craftcode=ma_craftcode and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code ");
  285. sql.Append("where ma_code='" + ma_code.Text + "'and sp_id=:sp_id1 and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + ms_sncode.Text + "'");
  286. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode", "sp_id", "sp_id1" }, CollectDataSonCode.ToArray(), CollectData.ToArray(), SPID.ToArray(), SPID.ToArray());
  287. //更新半成品SN已被工单使用
  288. 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());
  289. try
  290. {
  291. string Log = "";
  292. for (int i = 0; i < CollectDataSonCode.Count; i++)
  293. {
  294. Log += CollectDataSonCode.ToArray()[i] + " " + CollectData.ToArray()[i] + " " + SPID.ToArray()[i];
  295. }
  296. LogManager.DoLog(Log);
  297. }
  298. catch (Exception)
  299. {
  300. }
  301. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "对应的物料已经采集完成\n", Color.Green);
  302. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "上料采集", "上料成功", ms_sncode.Text, "");
  303. RemainIndex = 0;
  304. TSN.Clear();
  305. SPID.Clear();
  306. CollectData.Clear();
  307. CheckBarcode.Clear();
  308. CollectDataSonCode.Clear();
  309. BaseUtil.CleanDataTable(ListA);
  310. if (LogicHandler.SetTestResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "彩盒上料打印", "彩盒上料成功", User.UserCode, out ErrorMessage))
  311. {
  312. //提示正确返回时传递的信息
  313. if (ErrorMessage.Contains("AFTERSUCCESS"))
  314. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  315. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  316. code.Clear();
  317. LoadCollectNum();
  318. BaseUtil.CleanDataTableData(ListA);
  319. }
  320. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  321. // doc = lbl.Documents.Open(PrintLabel.Text);
  322. if (!Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, ms_sncode.Text, int.Parse(PrintNum.Text), ma_code.Text, pr_code.Text, "彩盒标", "0", out ErrorMessage))
  323. {
  324. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  325. }
  326. return;
  327. }
  328. }
  329. }
  330. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  331. }
  332. }
  333. private void Make_ColorBoxLoadPrint_SizeChanged(object sender, EventArgs e)
  334. {
  335. asc.controlAutoSize(this);
  336. }
  337. private void pr_code_TextChanged(object sender, EventArgs e)
  338. {
  339. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='彩盒标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  340. PrintLabel.DataSource = _dt;
  341. PrintLabel.DisplayMember = "la_url";
  342. PrintLabel.ValueMember = "la_id";
  343. }
  344. private void LoadCollectNum()
  345. {
  346. dt = (DataTable)dh.ExecuteSql("select ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  347. BaseUtil.SetFormValue(Controls, dt);
  348. }
  349. private void Make_ColorBoxLoadPrint_FormClosing(object sender, FormClosingEventArgs e)
  350. {
  351. BaseUtil.ClosePrint(lbl);
  352. }
  353. private void ClearSn_code_Click(object sender, EventArgs e)
  354. {
  355. if (ListA != null)
  356. BaseUtil.CleanDataTableData(ListA);
  357. TSN.Clear();
  358. SPID.Clear();
  359. CheckBarcode.Clear();
  360. CollectDataSonCode.Clear();
  361. CollectData.Clear();
  362. RemainIndex = 0;
  363. code.Clear();
  364. OperateResult.AppendText(">>请重新采集序列号\n");
  365. }
  366. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  367. {
  368. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  369. {
  370. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  371. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  372. }
  373. }
  374. private void code_KeyDown(object sender, KeyEventArgs e)
  375. {
  376. }
  377. }
  378. }