SystemSetting_PrinterTest.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. namespace UAS_MES_NEW.SystemSetting
  9. {
  10. public partial class SystemSetting_PrinterTest : Form
  11. {
  12. Engine engine = new Engine();
  13. LabelFormatDocument format;
  14. LabelFormatDocument format1;
  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. format.SubStrings["Type"].Value = MachineType.Text;
  53. format.SubStrings["Mark"].Value = Mark.Text;
  54. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 2)
  55. {
  56. int temp = i;
  57. for (int j = 0; j < format.SubStrings.Count; j++)
  58. {
  59. switch (format.SubStrings[j].Name)
  60. {
  61. case "SN":
  62. format.SubStrings[j].Value = (ma_code.Text.Replace("XX-", "") + lpad(4, (temp).ToString()));
  63. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "'"))
  64. {
  65. 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");
  66. };
  67. break;
  68. case "SN2":
  69. format.SubStrings[j].Value = (ma_code.Text.Replace("XX-", "") + lpad(4, (temp + 1).ToString()));
  70. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "'"))
  71. {
  72. 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");
  73. };
  74. break;
  75. default:
  76. break;
  77. }
  78. }
  79. format.PrintSetup.PrinterName = PrinterList.Text;
  80. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  81. format.Print();
  82. }
  83. }
  84. else
  85. {
  86. format1.SubStrings["Mark"].Value = MachineType.Text;
  87. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 3)
  88. {
  89. int temp = i;
  90. for (int j = 0; j < format1.SubStrings.Count; j++)
  91. {
  92. switch (format1.SubStrings[j].Name)
  93. {
  94. case "SN":
  95. format1.SubStrings[j].Value = (Prefix.Text/*+ lpad(4, (temp ).ToString())*/);
  96. break;
  97. case "SN2":
  98. format1.SubStrings[j].Value = (Prefix.Text /*+ lpad(4, (temp + 1).ToString())*/);
  99. break;
  100. case "SN3":
  101. format1.SubStrings[j].Value = (Prefix.Text /*+ lpad(4, (temp + 2).ToString())*/);
  102. break;
  103. default:
  104. break;
  105. }
  106. }
  107. format1.PrintSetup.PrinterName = PrinterList.Text;
  108. format1.PrintSetup.IdenticalCopiesOfLabel = 1;
  109. format1.Print();
  110. }
  111. }
  112. }
  113. private static string lpad(int length, string number)
  114. {
  115. while (number.Length < length)
  116. {
  117. number = "0" + number;
  118. }
  119. number = number.Substring(number.Length - length, length);
  120. return number;
  121. }
  122. private void SystemSetting_PrinterTest_Load(object sender, EventArgs e)
  123. {
  124. label5.Visible = false;
  125. Prefix.Visible = false;
  126. engine.Start();
  127. format = engine.Documents.Open(Application.StartupPath + "/Label.btw");
  128. format1 = engine.Documents.Open(Application.StartupPath + "/Material.btw");
  129. }
  130. private void SN_CheckedChanged(object sender, EventArgs e)
  131. {
  132. if (SN.Checked)
  133. {
  134. label6.Text = "机型相关配置";
  135. label5.Visible = false;
  136. Prefix.Visible = false;
  137. label7.Visible = true;
  138. ma_code.Visible = true;
  139. label4.Visible = true;
  140. Mark.Visible = true;
  141. Rn.Visible = true;
  142. label3.Visible = true;
  143. this.pictureBox1.Image = global::UAS_MES_NEW.Properties.Resources.SN;
  144. }
  145. else
  146. {
  147. this.pictureBox1.Image = global::UAS_MES_NEW.Properties.Resources.Material;
  148. label6.Text = "标签部分(显示)";
  149. label5.Visible = true;
  150. Prefix.Visible = true;
  151. Rn.Visible = false;
  152. label3.Visible = false;
  153. label7.Visible = false;
  154. ma_code.Visible = false;
  155. label4.Visible = false;
  156. Mark.Visible = false;
  157. }
  158. }
  159. }
  160. }