SystemSetting_PrinterTest.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using Seagull.BarTender.Print;
  2. using System;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Drawing.Printing;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. namespace UAS_MES_NEW.SystemSetting
  11. {
  12. public partial class SystemSetting_PrinterTest : Form
  13. {
  14. Engine engine = new Engine();
  15. LabelFormatDocument format;
  16. LabelFormatDocument format1;
  17. DataHelper dh = SystemInf.dh;
  18. public SystemSetting_PrinterTest()
  19. {
  20. InitializeComponent();
  21. }
  22. private void PrintTest_Click(object sender, EventArgs e)
  23. {
  24. PrintDocument print = new PrintDocument();
  25. print.PrinterSettings.PrinterName = PrinterList.Text;
  26. print.PrintPage += Print_PrintPage;
  27. print.Print();
  28. }
  29. private void Print_PrintPage(object sender, PrintPageEventArgs e)
  30. {
  31. Graphics g = e.Graphics;
  32. float leftMargin = 10f; //左边距
  33. SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
  34. float yPosition = 5f;//行定位
  35. Font printFont = new Font("微软雅黑", 20f, FontStyle.Bold);//设置字体
  36. yPosition += printFont.GetHeight(g);//另起一行
  37. g.DrawString("成功连接此打印机", printFont, myBrush, leftMargin, yPosition, new StringFormat());
  38. }
  39. private void Setting_Click(object sender, EventArgs e)
  40. {
  41. PrintDialog printd = new PrintDialog();
  42. printd.PrinterSettings.PrinterName = PrinterList.Text;
  43. printd.ShowDialog();
  44. }
  45. private void Export_Click(object sender, EventArgs e)
  46. {
  47. if (SN.Checked)
  48. {
  49. if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  50. {
  51. MessageBox.Show("工单号不存在");
  52. return;
  53. }
  54. ma_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  55. int QTY = 0;
  56. int report = 0;
  57. if (int.TryParse(ma_qty.Text, out QTY))
  58. {
  59. if (int.TryParse(reportqty.Text, out report))
  60. {
  61. Num.Text = (QTY % report == 0 ? QTY / report : QTY / report + 1).ToString();
  62. }
  63. }
  64. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 1)
  65. {
  66. int temp = i;
  67. for (int j = 0; j < format.SubStrings.Count; j++)
  68. {
  69. switch (format.SubStrings[j].Name)
  70. {
  71. case "SN":
  72. format.SubStrings[j].Value = (ma_code.Text.Replace("XX-", "") + lpad(4, (temp).ToString()));
  73. //if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "'"))
  74. //{
  75. // dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before')", "insert");
  76. //};
  77. break;
  78. case "SN2":
  79. //format.SubStrings[j].Value = (ma_code.Text.Replace("XX-", "") + lpad(4, (temp + 1).ToString()));
  80. //if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "'"))
  81. //{
  82. // dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before')", "insert");
  83. //};
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "打印报工条码", "打印成功", "", "");
  90. format.PrintSetup.PrinterName = PrinterList.Text;
  91. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  92. format.Print();
  93. }
  94. }
  95. }
  96. private static string lpad(int length, string number)
  97. {
  98. while (number.Length < length)
  99. {
  100. number = "0" + number;
  101. }
  102. number = number.Substring(number.Length - length, length);
  103. return number;
  104. }
  105. private void SystemSetting_PrinterTest_Load(object sender, EventArgs e)
  106. {
  107. engine.Start();
  108. format = engine.Documents.Open(Application.StartupPath + "/Label.btw");
  109. format1 = engine.Documents.Open(Application.StartupPath + "/Material.btw");
  110. }
  111. private void SN_CheckedChanged(object sender, EventArgs e)
  112. {
  113. if (SN.Checked)
  114. {
  115. ma_code.Visible = true;
  116. label4.Visible = true;
  117. Rn.Visible = true;
  118. label3.Visible = true;
  119. }
  120. else
  121. {
  122. Rn.Visible = false;
  123. label3.Visible = false;
  124. ma_code.Visible = false;
  125. label4.Visible = false;
  126. }
  127. }
  128. private void ma_code_KeyDown(object sender, KeyEventArgs e)
  129. {
  130. if (e.KeyCode == Keys.Enter)
  131. {
  132. DataTable dt = (DataTable)dh.ExecuteSql("select ma_prodcode,pr_detail,ma_qty from make left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'", "select");
  133. if (dt.Rows.Count > 0)
  134. {
  135. BaseUtil.SetFormValue(this.Controls, dt);
  136. }
  137. else
  138. {
  139. MessageBox.Show("工单" + ma_code.Text + "不存在");
  140. }
  141. }
  142. }
  143. }
  144. }