Query_SN.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. if (RePrintSn.Text == "")
  74. {
  75. 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");
  76. if (dt.Rows.Count < PrintNum.Value)
  77. {
  78. OperateResult.AppendText("未打印数量不足,剩余" + dt.Rows.Count + "未打印\n");
  79. return;
  80. }
  81. for (int i = 0; i < PrintNum.Value; i++)
  82. {
  83. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  84. 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))
  85. {
  86. //提示用户打印成功
  87. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  88. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  89. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  90. }
  91. else
  92. {
  93. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  94. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  95. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  96. }
  97. }
  98. 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");
  99. if (dt.Rows.Count > 0)
  100. {
  101. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  102. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  103. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  104. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  105. }
  106. }
  107. else
  108. {
  109. dt = (DataTable)dh.ExecuteSql("select msl_sncode from makesnlist where msl_makecode='" + ma_code.Text + "' and msl_sncode='" + RePrintSn.Text + "' order by msl_sncode", "select");
  110. if (dt.Rows.Count > 0)
  111. {
  112. string mil_sncode = dt.Rows[0]["msl_sncode"].ToString();
  113. 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))
  114. {
  115. //提示用户打印成功
  116. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  117. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  118. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  119. }
  120. else
  121. {
  122. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  123. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  124. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  125. }
  126. }
  127. else
  128. {
  129. OperateResult.AppendText("序列号:" + RePrintSn.Text + "不在工单" + ma_code.Text + "\n", Color.Red, RePrintSn);
  130. }
  131. }
  132. }
  133. else
  134. {
  135. dh.ExecuteSql("update make set ma_printqty='" + SingleRowCount.Value + "' where ma_code='" + ma_code.Text + "'", "update");
  136. 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");
  137. decimal rowcount = 0;
  138. for (int i = 0; i < dt.Rows.Count; i = i + 1)
  139. {
  140. string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
  141. if (rowcount % SingleRowCount.Value == 0)
  142. {
  143. 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))
  144. {
  145. //提示用户打印成功
  146. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  147. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  148. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  149. }
  150. else
  151. {
  152. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  153. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  154. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  155. }
  156. }
  157. else
  158. {
  159. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  160. dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
  161. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  162. }
  163. rowcount = rowcount + 1;
  164. }
  165. 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");
  166. if (dt.Rows.Count > 0)
  167. {
  168. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  169. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  170. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  171. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  172. }
  173. }
  174. }
  175. private void pr_code_TextChanged(object sender, EventArgs e)
  176. {
  177. _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");
  178. if (_dt.Rows.Count == 0)
  179. {
  180. _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");
  181. }
  182. if (_dt.Rows.Count > 0)
  183. {
  184. string la_id = _dt.Rows[0]["la_id"].ToString();
  185. _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");
  186. PrintLabel.DataSource = _dt;
  187. PrintLabel.DisplayMember = "la_url";
  188. PrintLabel.ValueMember = "la_id";
  189. }
  190. }
  191. }
  192. }