SystemSetting_PrinterTest.cs 5.8 KB

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