SystemSetting_PrinterTest.cs 6.6 KB

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