Query_SN.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. }
  30. private void Query_SpecialReport_Load(object sender, EventArgs e)
  31. {
  32. InitPrint = new Thread(InPrint);
  33. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  34. BaseUtil.SetFormCenter(stw);
  35. stw.ShowDialog();
  36. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  37. ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
  38. ma_code.FormName = Name;
  39. ma_code.SetValueField = new string[] { "ma_code" };
  40. ma_code.Condition = "ma_statuscode='STARTED'";
  41. ma_code.DbChange += pr_code_DbChange;
  42. }
  43. private void pr_code_DbChange(object sender, EventArgs e)
  44. {
  45. Dbfind = ma_code.ReturnData;
  46. BaseUtil.SetFormValue(this.Controls, Dbfind);
  47. 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");
  48. if (dt.Rows.Count > 0)
  49. {
  50. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  51. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  52. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  53. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  54. }
  55. }
  56. private void InPrint()
  57. {
  58. try
  59. {
  60. engine = new Engine(true);
  61. }
  62. catch (Exception)
  63. {
  64. MessageBox.Show("未正确安装BarTender软件");
  65. }
  66. }
  67. private void Print_Click(object sender, EventArgs e)
  68. {
  69. DataTable dt = new DataTable();
  70. string ErrorMessage = "";
  71. if (!PrintNums.Checked)
  72. {
  73. string batch = System.DateTime.Now.ToString("yyyyMMddhhmiss");
  74. if (RePrintSn.Text == "")
  75. {
  76. 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");
  77. if (dt.Rows.Count < PrintNum.Value)
  78. {
  79. OperateResult.AppendText("未打印数量不足,剩余" + dt.Rows.Count + "未打印\n");
  80. return;
  81. }
  82. for (int i = 0; i < PrintNum.Value; i++)
  83. {
  84. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  85. if (Print.BarTenderS(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))
  86. {
  87. //提示用户打印成功
  88. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  89. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  90. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  91. }
  92. else
  93. {
  94. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  95. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  96. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  97. }
  98. }
  99. 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");
  100. if (dt.Rows.Count > 0)
  101. {
  102. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  103. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  104. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  105. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  106. }
  107. }
  108. else
  109. {
  110. 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");
  111. if (dt.Rows.Count > 0)
  112. {
  113. string mil_sncode = dt.Rows[0]["msl_sncode"].ToString();
  114. if (Print.BarTenderS(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))
  115. {
  116. //提示用户打印成功
  117. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  118. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  119. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  120. }
  121. else
  122. {
  123. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  124. dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
  125. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  126. }
  127. }
  128. else
  129. {
  130. OperateResult.AppendText("序列号:" + RePrintSn.Text + "不在工单" + ma_code.Text + "\n", Color.Red, RePrintSn);
  131. }
  132. }
  133. }
  134. else
  135. {
  136. dh.ExecuteSql("update make set ma_printqty='" + SingleRowCount.Value + "' where ma_code='" + ma_code.Text + "'", "update");
  137. 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");
  138. decimal rowcount = 0;
  139. for (int i = 0; i < dt.Rows.Count; i = i + 1)
  140. {
  141. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  142. if (rowcount % SingleRowCount.Value == 0)
  143. {
  144. if (Print.BarTenderS(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))
  145. {
  146. //提示用户打印成功
  147. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  148. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  149. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  150. }
  151. else
  152. {
  153. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  154. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  155. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  156. }
  157. }
  158. else
  159. {
  160. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  161. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  162. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  163. }
  164. rowcount = rowcount + 1;
  165. }
  166. 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");
  167. if (dt.Rows.Count > 0)
  168. {
  169. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  170. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  171. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  172. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  173. }
  174. }
  175. }
  176. private void pr_code_TextChanged(object sender, EventArgs e)
  177. {
  178. _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");
  179. if (_dt.Rows.Count == 0)
  180. {
  181. _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");
  182. }
  183. if (_dt.Rows.Count > 0)
  184. {
  185. string la_id = _dt.Rows[0]["la_id"].ToString();
  186. _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");
  187. PrintLabel.DataSource = _dt;
  188. PrintLabel.DisplayMember = "la_url";
  189. PrintLabel.ValueMember = "la_id";
  190. }
  191. }
  192. private void PrintByBatch_Click(object sender, EventArgs e)
  193. {
  194. DataTable dt = (DataTable)dh.ExecuteSql("select * from makesnlist where mil_printbatch='" + PrintBatch.Text + "'", "select");
  195. string ErrorMessage = "";
  196. if (dt.Rows.Count > 0)
  197. {
  198. for (int i = 0; i < dt.Rows.Count; i++)
  199. {
  200. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  201. if (Print.BarTenderS(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))
  202. {
  203. //提示用户打印成功
  204. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  205. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  206. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  207. }
  208. else
  209. {
  210. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  211. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  212. }
  213. }
  214. }
  215. else
  216. {
  217. OperateResult.AppendText(">>批号:" + PrintBatch.Text + "不存在\n", Color.Green);
  218. }
  219. }
  220. }
  221. }