Make_ColorBoxLoadPrint.cs 15 KB

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