Query_SN.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_makecode='" + ma_code.Text + "' and nvl(mil_printstatus,0)=0 order by mil_sncode", "select");
  72. if (dt.Rows.Count < PrintNum.Value)
  73. {
  74. OperateResult.AppendText("未打印数量不足,剩余" + dt.Rows.Count + "未打印\n");
  75. return;
  76. }
  77. for (int i = 0; i < PrintNum.Value; i++)
  78. {
  79. string mil_sncode = dt.Rows[i]["mil_sncode"].ToString();
  80. 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))
  81. {
  82. //提示用户打印成功
  83. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  84. OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
  85. }
  86. else
  87. {
  88. dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
  89. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Green);
  90. }
  91. }
  92. 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");
  93. if (dt.Rows.Count > 0)
  94. {
  95. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  96. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  97. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  98. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  99. }
  100. }
  101. private void pr_code_TextChanged(object sender, EventArgs e)
  102. {
  103. _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");
  104. if (_dt.Rows.Count == 0)
  105. {
  106. _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");
  107. }
  108. if (_dt.Rows.Count > 0)
  109. {
  110. string la_id = _dt.Rows[0]["la_id"].ToString();
  111. _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");
  112. PrintLabel.DataSource = _dt;
  113. PrintLabel.DisplayMember = "la_url";
  114. PrintLabel.ValueMember = "la_id";
  115. }
  116. }
  117. }
  118. }