SystemSetting_PrinterTest.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Seagull.BarTender.Print;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Printing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using UAS_MES_NEW.DataOperate;
  12. using UAS_MES_NEW.Entity;
  13. namespace UAS_MES_NEW.SystemSetting
  14. {
  15. public partial class SystemSetting_PrinterTest : Form
  16. {
  17. Engine engine = new Engine();
  18. LabelFormatDocument format;
  19. DataHelper dh = SystemInf.dh;
  20. public SystemSetting_PrinterTest()
  21. {
  22. InitializeComponent();
  23. }
  24. private void PrintTest_Click(object sender, EventArgs e)
  25. {
  26. PrintDocument print = new PrintDocument();
  27. print.PrinterSettings.PrinterName = PrinterList.Text;
  28. print.PrintPage += Print_PrintPage;
  29. print.Print();
  30. }
  31. private void Print_PrintPage(object sender, PrintPageEventArgs e)
  32. {
  33. Graphics g = e.Graphics;
  34. float leftMargin = 10f; //左边距
  35. SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
  36. float yPosition = 5f;//行定位
  37. Font printFont = new Font("微软雅黑", 20f, FontStyle.Bold);//设置字体
  38. yPosition += printFont.GetHeight(g);//另起一行
  39. g.DrawString("成功连接此打印机", printFont, myBrush, leftMargin, yPosition, new StringFormat());
  40. }
  41. private void Setting_Click(object sender, EventArgs e)
  42. {
  43. PrintDialog printd = new PrintDialog();
  44. printd.PrinterSettings.PrinterName = PrinterList.Text;
  45. printd.ShowDialog();
  46. }
  47. private void Export_Click(object sender, EventArgs e)
  48. {
  49. if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  50. {
  51. MessageBox.Show("工单号不存在");
  52. return;
  53. }
  54. /*DataTable dt = (DataTable)dh.ExecuteSql("select pr_machinetype from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  55. if (dt.Rows.Count > 0)
  56. {
  57. string pr_machinetype = dt.Rows[0]["pr_machinetype"].ToString();
  58. if (pr_machinetype != Prefix.Text)
  59. {
  60. MessageBox.Show("前缀和产品机型" + pr_machinetype + "不匹配");
  61. return;
  62. }
  63. }*/
  64. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 4)
  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 "RN1":
  72. format.SubStrings[j].Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  73. 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");
  74. break;
  75. case "RN2":
  76. format.SubStrings[j].Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  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. break;
  79. case "RN3":
  80. format.SubStrings[j].Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
  81. 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");
  82. break;
  83. case "RN4":
  84. format.SubStrings[j].Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 3).ToString()));
  85. 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");
  86. break;
  87. default:
  88. break;
  89. }
  90. }
  91. format.PrintSetup.PrinterName = PrinterList.Text;
  92. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  93. format.Print();
  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. }
  110. }
  111. }