Make_ColorBoxLoadPrint.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. string ErrorMessage = "";
  30. System.DateTime[] indate;
  31. ApplicationClass lbl;
  32. Thread InitPrint;
  33. List<string> CollectData = new List<string>();
  34. List<string> CollectDataSonCode = new List<string>();
  35. public Make_ColorBoxLoadPrint()
  36. {
  37. InitializeComponent();
  38. load.Checked = true;
  39. }
  40. private void 标签打印_Load(object sender, EventArgs e)
  41. {
  42. dh = new DataHelper();
  43. code.Focus();
  44. asc.controllInitializeSize(this);
  45. InitPrint = new Thread(InPrint);
  46. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  47. BaseUtil.SetFormCenter(stw);
  48. stw.ShowDialog();
  49. //工单号放大镜配置
  50. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  51. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_detail # 产品名称,ma_bomversion # Bom版本";
  52. ma_code.FormName = Name;
  53. ma_code.DBTitle = "工单查询";
  54. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "ma_qty", "pr_detail", "ma_craftcode", "ma_bomversion" };
  55. ma_code.Condition = "ma_statuscode='STARTED' order by ma_updatedate desc";
  56. ma_code.DbChange += Ms_makecode_DbChange;
  57. Lock.GetMakeCodeCtl(ma_code);
  58. ma_code.SetLockCheckBox(Lock);
  59. }
  60. private void Ms_makecode_DbChange(object sender, EventArgs e)
  61. {
  62. dt = ma_code.ReturnData;
  63. BaseUtil.SetFormValue(this.Controls, dt);
  64. }
  65. private void InPrint()
  66. {
  67. try
  68. {
  69. lbl = new ApplicationClass();
  70. BaseUtil.WriteLbl(lbl);
  71. }
  72. catch (Exception ex)
  73. {
  74. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  75. }
  76. }
  77. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  78. {
  79. if (e.KeyCode == Keys.Enter)
  80. {
  81. if (code.Text == "")
  82. {
  83. OperateResult.AppendText(">>输入内容不能为空\n", Color.Red);
  84. return;
  85. }
  86. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  87. {
  88. string Msid;
  89. if (ma_code.Text == "")
  90. {
  91. if (!LogicHandler.GetMakeInfo(code.Text, out macode, out ErrorMessage))
  92. {
  93. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  94. return;
  95. }
  96. }
  97. if (ma_code.Text != macode || ListA.Rows.Count == 0)
  98. {
  99. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage) || ListA.Rows.Count > 0)
  100. {
  101. sql.Clear();
  102. sql.Append("select ma_code,ma_craftcode,ms_sncode,ma_qty,pr_detail,pr_code,ma_bomversion from makeserial left join make on ");
  103. sql.Append("ms_makecode=ma_code left join product on ms_prodcode=pr_code where ms_sncode='" + code.Text + "' and ms_makecode='" + ma_code.Text + "'");
  104. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  105. if (dt.Rows.Count > 0)
  106. {
  107. BaseUtil.SetFormValue(this.Controls, dt);
  108. LoadCollectNum();
  109. if (PrintLabel.SelectedValue == null)
  110. {
  111. OperateResult.AppendText(">>产品编号:" + pr_code.Text + "未维护彩盒标签\n", Color.Red);
  112. return;
  113. }
  114. ms_sncode.Text = code.Text;
  115. }
  116. //判断当前的执行状态 ,Loading表示执行上料操作,UnLoading表示执行下料操作
  117. if (load.Checked == true)
  118. {
  119. OperateResult.AppendText(">>开始执行上料工序\n");
  120. sql.Clear();
  121. sql.Append("select sp_id,sp_tracekind,sp_barcoderule,sp_prefix,sp_ifuseregex,sp_ifforsn,sp_length,sp_description,sp_soncode,pr_detail,pr_spec,");
  122. sql.Append("sp_repcode,pr_id,sp_type,case when (sp_type='物料' and sp_soncode=pr_code) then '已采集' else '未采集' end sp_ifpick ,sp_prefix,");
  123. sql.Append("sp_length,sp_regex,sp_ifforsn from stepproduct left join product on pr_code=sp_soncode where sp_bomversion='" + ma_bomversion.Text + "' and ");
  124. sql.Append("sp_craftcode='" + ma_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' And sp_mothercode ='" + pr_code.Text + "' ");
  125. sql.Append("and((sp_type = '物料' and(sp_tracekind <> 2 or sp_tracekind is null))or sp_type <> '物料') order by SP_DETNO asc");
  126. ListA = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  127. //获取对应 产品的机身标的打印模板
  128. if (ListA.Rows.Count > 0)
  129. {
  130. OperateResult.AppendText(">>请采集" + ListA.Rows[RemainIndex]["sp_soncode"].ToString() + "的条码\n");
  131. code.Clear();
  132. }
  133. }
  134. else if (unload.Checked == true)
  135. {
  136. if (LogicHandler.CheckStepSNAndMacode(macode, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage))
  137. {
  138. dt = (DataTable)dh.ExecuteSql("select cm_id,cm_stepcode,ms_makecode,cm_mccode from craftmaterial left join makeserial on cm_makecode=ms_makecode and cm_sncode=ms_sncode where ms_sncode='" + code.Text + "' and cm_makecode='" + macode + "'", "select");
  139. if (dt.Rows.Count > 0)
  140. {
  141. string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
  142. string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
  143. string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
  144. dh.ExecuteSql("delete from craftmaterial where cm_sncode='" + code.Text + "' and cm_makecode='" + macode + "'", "delete");
  145. LogicHandler.InsertMakeProcess(ms_macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
  146. int count = dh.getRowCount("craftMaterial", "cm_mccode='" + cm_mccode + "' and cm_stepcode='" + cm_stepcode + "' and cm_sncode='" + code.Text + "'");
  147. if (count == 0)
  148. dh.UpdateByCondition("makecraftdetail ", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty = mcd_okqty - 1", "mcd_mccode='" + cm_mccode + "' and mcd_stepcode='" + cm_stepcode + "'");
  149. OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
  150. }
  151. else OperateResult.AppendText(">>该序列号未上料,无需下料\n", Color.Red, code);
  152. }
  153. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  154. }
  155. }
  156. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  157. }
  158. else
  159. {
  160. //获取上料需要传递的参数,sp_soncode,sp_id
  161. string sp_soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
  162. string sp_prefix = ListA.Rows[RemainIndex]["sp_prefix"].ToString();
  163. string sp_regex = ListA.Rows[RemainIndex]["sp_regex"].ToString();
  164. string length = ListA.Rows[RemainIndex]["sp_length"].ToString();
  165. string sp_id = ListA.Rows[RemainIndex]["sp_id"].ToString();
  166. string sp_ifforsn = ListA.Rows[RemainIndex]["sp_ifforsn"].ToString();
  167. string sp_tracekind = ListA.Rows[RemainIndex]["sp_tracekind"].ToString();
  168. string sp_barcoderule = ListA.Rows[RemainIndex]["sp_barcoderule"].ToString();
  169. if (LogicHandler.CheckSNBeforeLoad(macode, code.Text, sp_soncode, sp_barcoderule, sp_prefix, length, out ErrorMessage))
  170. {
  171. CollectData.Add(code.Text);
  172. CollectDataSonCode.Add(ListA.Rows[RemainIndex]["sp_soncode"].ToString());
  173. OperateResult.AppendText(">>物料" + code.Text + "采集成功\n", Color.Green, code);
  174. RemainIndex = RemainIndex + 1;
  175. }
  176. else
  177. {
  178. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  179. return;
  180. }
  181. code.Clear();
  182. if (RemainIndex <= ListA.Rows.Count - 1)
  183. OperateResult.AppendText(">>请采集物料编号为" + ListA.Rows[RemainIndex]["sp_soncode"].ToString() + "的条码\n");
  184. if (RemainIndex == ListA.Rows.Count)
  185. {
  186. sql.Clear();
  187. sql.Append("insert into Craftmaterial (cm_id ,cm_makecode,cm_maid,cm_maprodcode, cm_soncode, cm_mscode, cm_sncode, cm_stepcode, cm_stepname,");
  188. 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)");
  189. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  190. sql.Append("mcd_stepname,ma_craftcode,ma_craftname,:barcode,1,sysdate,'" + User.UserCode + "',ma_linecode,ma_wccode,");
  191. 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 ");
  192. sql.Append("and sp_craftcode=ma_craftcode and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code ");
  193. sql.Append("where ma_code='" + macode + "'and sp_id=" + sp_id + " and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + ms_sncode.Text + "'");
  194. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode" }, CollectDataSonCode.ToArray(), CollectData.ToArray());
  195. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "对应的物料已经采集完成\n", Color.Green);
  196. Print.CodeSoft(Tag.ToString(), lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, ms_sncode.Text, int.Parse(PrintNum.Text), indate[PrintLabel.SelectedIndex]);
  197. RemainIndex = 0;
  198. CollectData.Clear();
  199. CollectDataSonCode.Clear();
  200. if (LogicHandler.SetTestResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "彩盒上料打印", "彩盒上料成功", User.UserCode, out ErrorMessage))
  201. {
  202. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  203. code.Clear();
  204. LoadCollectNum();
  205. BaseUtil.CleanDataTableData(ListA);
  206. }
  207. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  208. return;
  209. }
  210. }
  211. }
  212. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  213. }
  214. }
  215. private void 标签打印_SizeChanged(object sender, EventArgs e)
  216. {
  217. asc.controlAutoSize(this);
  218. }
  219. private void pr_code_TextChanged(object sender, EventArgs e)
  220. {
  221. dt = (DataTable)dh.ExecuteSql("select pl_labelname,pl_labelcode,pl_indate,pl_labelurl from productlabel where pl_prodcode='" + pr_code.Text + "' and pl_labeltype='彩盒标' order by pl_isdefault desc", "select");
  222. PrintLabel.DataSource = dt;
  223. PrintLabel.DisplayMember = "pl_labelname";
  224. PrintLabel.ValueMember = "pl_labelcode";
  225. ftpOperater ftp = new ftpOperater();
  226. indate = new System.DateTime[dt.Rows.Count];
  227. for (int i = 0; i < dt.Rows.Count; i++)
  228. {
  229. BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
  230. indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
  231. }
  232. }
  233. private void LoadCollectNum()
  234. {
  235. 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");
  236. BaseUtil.SetFormValue(Controls, dt);
  237. }
  238. private void 标签打印_FormClosing(object sender, FormClosingEventArgs e)
  239. {
  240. BaseUtil.ClosePrint(lbl);
  241. }
  242. }
  243. }