Make_ColorBoxLoadPrint.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 (ListA.Rows.Count == 0)
  90. {
  91. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage) || ListA.Rows.Count > 0)
  92. {
  93. sql.Clear();
  94. sql.Append("select ma_code,ma_craftcode,ms_sncode,ma_qty,pr_detail,pr_code,ma_bomversion from makeserial left join make on ");
  95. sql.Append("ms_makecode=ma_code left join product on ms_prodcode=pr_code where ms_id='" + Msid + "'");
  96. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  97. if (dt.Rows.Count > 0)
  98. {
  99. BaseUtil.SetFormValue(this.Controls, dt);
  100. LoadCollectNum();
  101. if (PrintLabel.SelectedValue == null)
  102. {
  103. OperateResult.AppendText(">>产品编号:" + pr_code.Text + "未维护彩盒标签\n", Color.Red);
  104. return;
  105. }
  106. ms_sncode.Text = code.Text;
  107. }
  108. //判断当前的执行状态 ,Loading表示执行上料操作,UnLoading表示执行下料操作
  109. if (load.Checked == true)
  110. {
  111. OperateResult.AppendText(">>开始执行上料工序\n");
  112. sql.Clear();
  113. 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,");
  114. sql.Append("sp_repcode,pr_id,sp_type,case when (sp_type='物料' and sp_soncode=pr_code) then '已采集' else '未采集' end sp_ifpick ,sp_prefix,");
  115. 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 ");
  116. sql.Append("sp_craftcode='" + ma_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' And sp_mothercode ='" + pr_code.Text + "' ");
  117. sql.Append("and((sp_type = '物料' and(sp_tracekind <> 2 or sp_tracekind is null))or sp_type <> '物料') order by SP_DETNO asc");
  118. ListA = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  119. //获取对应 产品的机身标的打印模板
  120. if (ListA.Rows.Count > 0)
  121. {
  122. OperateResult.AppendText(">>请采集" + ListA.Rows[RemainIndex]["sp_soncode"].ToString() + "的条码\n");
  123. code.Clear();
  124. }
  125. }
  126. else if (unload.Checked == true)
  127. {
  128. if (LogicHandler.CheckStepSNAndMacode(macode, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage))
  129. {
  130. 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");
  131. if (dt.Rows.Count > 0)
  132. {
  133. string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
  134. string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
  135. string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
  136. dh.ExecuteSql("delete from craftmaterial where cm_sncode='" + code.Text + "' and cm_makecode='" + macode + "'", "delete");
  137. LogicHandler.InsertMakeProcess(ms_macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
  138. int count = dh.getRowCount("craftMaterial", "cm_mccode='" + cm_mccode + "' and cm_stepcode='" + cm_stepcode + "' and cm_sncode='" + code.Text + "'");
  139. if (count == 0)
  140. 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 + "'");
  141. OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
  142. }
  143. else OperateResult.AppendText(">>该序列号未上料,无需下料\n", Color.Red, code);
  144. }
  145. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  146. }
  147. }
  148. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  149. }
  150. else
  151. {
  152. //获取上料需要传递的参数,sp_soncode,sp_id
  153. string sp_soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
  154. string sp_prefix = ListA.Rows[RemainIndex]["sp_prefix"].ToString();
  155. string sp_regex = ListA.Rows[RemainIndex]["sp_regex"].ToString();
  156. string length = ListA.Rows[RemainIndex]["sp_length"].ToString();
  157. string sp_id = ListA.Rows[RemainIndex]["sp_id"].ToString();
  158. string sp_ifforsn = ListA.Rows[RemainIndex]["sp_ifforsn"].ToString();
  159. string sp_tracekind = ListA.Rows[RemainIndex]["sp_tracekind"].ToString();
  160. string sp_barcoderule = ListA.Rows[RemainIndex]["sp_barcoderule"].ToString();
  161. if (LogicHandler.CheckSNBeforeLoad(macode, code.Text, sp_soncode, sp_barcoderule, sp_prefix, length, out ErrorMessage))
  162. {
  163. CollectData.Add(code.Text);
  164. CollectDataSonCode.Add(ListA.Rows[RemainIndex]["sp_soncode"].ToString());
  165. OperateResult.AppendText(">>物料" + code.Text + "采集成功\n", Color.Green, code);
  166. RemainIndex = RemainIndex + 1;
  167. }
  168. else
  169. {
  170. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  171. return;
  172. }
  173. code.Clear();
  174. if (RemainIndex <= ListA.Rows.Count - 1)
  175. OperateResult.AppendText(">>请采集物料编号为" + ListA.Rows[RemainIndex]["sp_soncode"].ToString() + "的条码\n");
  176. if (RemainIndex == ListA.Rows.Count)
  177. {
  178. sql.Clear();
  179. sql.Append("insert into Craftmaterial (cm_id ,cm_makecode,cm_maid,cm_maprodcode, cm_soncode, cm_mscode, cm_sncode, cm_stepcode, cm_stepname,");
  180. 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)");
  181. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  182. sql.Append("mcd_stepname,ma_craftcode,ma_craftname,:barcode,1,sysdate,'" + User.UserCode + "',ma_linecode,ma_wccode,");
  183. 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 ");
  184. sql.Append("and sp_craftcode=ma_craftcode and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code ");
  185. sql.Append("where ma_code='" + macode + "'and sp_id=" + sp_id + " and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + ms_sncode.Text + "'");
  186. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode" }, CollectDataSonCode.ToArray(), CollectData.ToArray());
  187. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "对应的物料已经采集完成\n", Color.Green);
  188. Print.CodeSoft(Tag.ToString(), lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, ms_sncode.Text, int.Parse(PrintNum.Text), indate[PrintLabel.SelectedIndex]);
  189. RemainIndex = 0;
  190. CollectData.Clear();
  191. CollectDataSonCode.Clear();
  192. if (LogicHandler.SetTestResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "彩盒上料打印", "彩盒上料成功", User.UserCode, out ErrorMessage))
  193. {
  194. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  195. code.Clear();
  196. LoadCollectNum();
  197. BaseUtil.CleanDataTableData(ListA);
  198. }
  199. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  200. return;
  201. }
  202. }
  203. }
  204. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  205. }
  206. }
  207. private void 标签打印_SizeChanged(object sender, EventArgs e)
  208. {
  209. asc.controlAutoSize(this);
  210. }
  211. private void pr_code_TextChanged(object sender, EventArgs e)
  212. {
  213. 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");
  214. PrintLabel.DataSource = dt;
  215. PrintLabel.DisplayMember = "pl_labelname";
  216. PrintLabel.ValueMember = "pl_labelcode";
  217. ftpOperater ftp = new ftpOperater();
  218. indate = new System.DateTime[dt.Rows.Count];
  219. for (int i = 0; i < dt.Rows.Count; i++)
  220. {
  221. BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
  222. indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
  223. }
  224. }
  225. private void LoadCollectNum()
  226. {
  227. 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");
  228. BaseUtil.SetFormValue(Controls, dt);
  229. }
  230. private void 标签打印_FormClosing(object sender, FormClosingEventArgs e)
  231. {
  232. BaseUtil.ClosePrint(lbl);
  233. }
  234. }
  235. }