SystemSetting_PrinterTest.cs 5.1 KB

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