Query_SN.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using DevExpress.Printing.Core.PdfExport.Metafile;
  2. using HslCommunication;
  3. using LabelManager2;
  4. using Seagull.BarTender.Print;
  5. using System;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Security.Cryptography;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. using UAS_MES_NEW.DataOperate;
  13. using UAS_MES_NEW.Entity;
  14. using UAS_MES_NEW.PublicForm;
  15. using UAS_MES_NEW.PublicMethod;
  16. namespace UAS_MES_NEW.Query
  17. {
  18. public partial class Query_SN : Form
  19. {
  20. DataHelper dh = SystemInf.dh;
  21. Engine engine;
  22. Thread InitPrint;
  23. DataTable Dbfind;
  24. Document doc;
  25. DataTable _dt;
  26. public Query_SN()
  27. {
  28. InitializeComponent();
  29. try { UAS_MES_NEW.I18n.LanguageManager.Localize(this); } catch { }
  30. }
  31. private void Query_SpecialReport_Load(object sender, EventArgs e)
  32. {
  33. InitPrint = new Thread(InPrint);
  34. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  35. BaseUtil.SetFormCenter(stw);
  36. stw.ShowDialog();
  37. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  38. ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
  39. ma_code.FormName = Name;
  40. ma_code.SetValueField = new string[] { "ma_code" };
  41. ma_code.Condition = "ma_statuscode='STARTED'";
  42. ma_code.DbChange += pr_code_DbChange;
  43. }
  44. private void pr_code_DbChange(object sender, EventArgs e)
  45. {
  46. Dbfind = ma_code.ReturnData;
  47. BaseUtil.SetFormValue(this.Controls, Dbfind);
  48. DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,mil_makecode from makeimeilist where mil_printstatus=-1 group by mil_makecode) on mil_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
  49. if (dt.Rows.Count > 0)
  50. {
  51. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  52. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  53. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  54. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  55. }
  56. }
  57. private void InPrint()
  58. {
  59. try
  60. {
  61. engine = new Engine(true);
  62. }
  63. catch (Exception)
  64. {
  65. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("未正确安装BarTender软件"));
  66. }
  67. }
  68. private void Print_Click(object sender, EventArgs e)
  69. {
  70. DataTable dt = new DataTable();
  71. string ErrorMessage = "";
  72. if (!PrintNums.Checked)
  73. {
  74. string batch = System.DateTime.Now.ToString("yyyyMMddhhmiss");
  75. if (RePrintSn.Text == "")
  76. {
  77. dt = (DataTable)dh.ExecuteSql("select msl_sncode from makesnlist where msl_makecode='" + ma_code.Text + "' and nvl(msl_printstatus,0)=0 order by msl_sncode", "select");
  78. if (dt.Rows.Count < PrintNum.Value)
  79. {
  80. OperateResult.AppendText("未打印数量不足,剩余" + dt.Rows.Count + "未打印\n");
  81. return;
  82. }
  83. for (int i = 0; i < PrintNum.Value; i++)
  84. {
  85. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  86. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
  87. {
  88. //提示用户打印成功
  89. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  90. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  91. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  92. }
  93. else
  94. {
  95. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  96. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  97. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  98. }
  99. }
  100. dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
  101. if (dt.Rows.Count > 0)
  102. {
  103. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  104. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  105. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  106. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  107. }
  108. }
  109. else
  110. {
  111. dt = (DataTable)dh.ExecuteSql("select msl_sncode from makesnlist left join makeimeilist on mil_sncode=msl_sncode and mil_makecode=msl_makecode where msl_makecode='" + ma_code.Text + "' and (msl_sncode='" + RePrintSn.Text + "' or mil_imei1='"+RePrintSn.Text+"' or mil_imei2='"+RePrintSn.Text + "')order by msl_sncode", "select");
  112. if (dt.Rows.Count > 0)
  113. {
  114. string mil_sncode = dt.Rows[0]["msl_sncode"].ToString();
  115. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
  116. {
  117. //提示用户打印成功
  118. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  119. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  120. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  121. }
  122. else
  123. {
  124. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  125. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  126. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  127. }
  128. }
  129. else
  130. {
  131. OperateResult.AppendText("序列号:" + RePrintSn.Text + "不在工单" + ma_code.Text + "\n", Color.Red, RePrintSn);
  132. }
  133. }
  134. }
  135. else
  136. {
  137. dh.ExecuteSql("update make set ma_printqty='" + SingleRowCount.Value + "' where ma_code='" + ma_code.Text + "'", "update");
  138. dt = (DataTable)dh.ExecuteSql("select msl_sncode from (select msl_sncode from makesnlist where msl_makecode='" + ma_code.Text + "' and nvl(msl_printstatus,0)=0 order by msl_sncode) where rownum<='" + PrintNum.Value * SingleRowCount.Value + "'", "select");
  139. decimal rowcount = 0;
  140. for (int i = 0; i < dt.Rows.Count; i = i + 1)
  141. {
  142. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  143. if (rowcount % SingleRowCount.Value == 0)
  144. {
  145. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
  146. {
  147. //提示用户打印成功
  148. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  149. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  150. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  151. }
  152. else
  153. {
  154. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  155. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  156. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  157. }
  158. }
  159. else
  160. {
  161. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  162. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  163. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  164. }
  165. rowcount = rowcount + 1;
  166. }
  167. dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
  168. if (dt.Rows.Count > 0)
  169. {
  170. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  171. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  172. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  173. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  174. }
  175. }
  176. }
  177. private void pr_code_TextChanged(object sender, EventArgs e)
  178. {
  179. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  180. if (_dt.Rows.Count == 0)
  181. {
  182. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode is null and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  183. }
  184. if (_dt.Rows.Count > 0)
  185. {
  186. string la_id = _dt.Rows[0]["la_id"].ToString();
  187. _dt = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id from FILEPATH where fp_id in (select * from table(select parsestring(LA_SOFTTYPE,';') from label where la_templatetype='机身标' and la_id='" + la_id + "') where COLUMN_VALUE is not null)", "select");
  188. PrintLabel.DataSource = _dt;
  189. PrintLabel.DisplayMember = "la_url";
  190. PrintLabel.ValueMember = "la_id";
  191. }
  192. }
  193. private void PrintByBatch_Click(object sender, EventArgs e)
  194. {
  195. DataTable dt = (DataTable)dh.ExecuteSql("select * from makesnlist where mil_printbatch='" + PrintBatch.Text + "'", "select");
  196. string ErrorMessage = "";
  197. if (dt.Rows.Count > 0)
  198. {
  199. for (int i = 0; i < dt.Rows.Count; i++)
  200. {
  201. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  202. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
  203. {
  204. //提示用户打印成功
  205. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  206. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  207. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  208. }
  209. else
  210. {
  211. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  212. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  213. }
  214. }
  215. }
  216. else
  217. {
  218. OperateResult.AppendText(">>批号:" + PrintBatch.Text + "不存在\n", Color.Green);
  219. }
  220. }
  221. }
  222. }