123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using Seagull.BarTender.Print;
- using System;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- namespace UAS_MES_NEW.SystemSetting
- {
- public partial class SystemSetting_PrinterTest : Form
- {
- Engine engine = new Engine();
- LabelFormatDocument format;
- LabelFormatDocument format1;
- DataHelper dh = SystemInf.dh;
- public SystemSetting_PrinterTest()
- {
- InitializeComponent();
- }
- private void PrintTest_Click(object sender, EventArgs e)
- {
- PrintDocument print = new PrintDocument();
- print.PrinterSettings.PrinterName = PrinterList.Text;
- print.PrintPage += Print_PrintPage;
- print.Print();
- }
- private void Print_PrintPage(object sender, PrintPageEventArgs e)
- {
- Graphics g = e.Graphics;
- float leftMargin = 10f; //左边距
- SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
- float yPosition = 5f;//行定位
- Font printFont = new Font("微软雅黑", 20f, FontStyle.Bold);//设置字体
- yPosition += printFont.GetHeight(g);//另起一行
- g.DrawString("成功连接此打印机", printFont, myBrush, leftMargin, yPosition, new StringFormat());
- }
- private void Setting_Click(object sender, EventArgs e)
- {
- PrintDialog printd = new PrintDialog();
- printd.PrinterSettings.PrinterName = PrinterList.Text;
- printd.ShowDialog();
- }
- private void Export_Click(object sender, EventArgs e)
- {
- if (SN.Checked)
- {
- if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
- {
- MessageBox.Show("工单号不存在");
- return;
- }
- format.SubStrings["Type"].Value = MachineType.Text;
- format.SubStrings["Mark"].Value = Mark.Text;
- for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 2)
- {
- int temp = i;
- for (int j = 0; j < format.SubStrings.Count; j++)
- {
- switch (format.SubStrings[j].Name)
- {
- case "SN":
- format.SubStrings[j].Value = (ma_code.Text.Replace("XX-", "") + lpad(4, (temp).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "'"))
- {
- 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");
- };
- break;
- case "SN2":
- format.SubStrings[j].Value = (ma_code.Text.Replace("XX-", "") + lpad(4, (temp + 1).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "'"))
- {
- 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");
- };
- break;
- default:
- break;
- }
- }
- format.PrintSetup.PrinterName = PrinterList.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- }
- }
- else
- {
- format1.SubStrings["Mark"].Value = MachineType.Text;
- for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 3)
- {
- int temp = i;
- for (int j = 0; j < format1.SubStrings.Count; j++)
- {
- switch (format1.SubStrings[j].Name)
- {
- case "SN":
- format1.SubStrings[j].Value = (Prefix.Text/*+ lpad(4, (temp ).ToString())*/);
- break;
- case "SN2":
- format1.SubStrings[j].Value = (Prefix.Text /*+ lpad(4, (temp + 1).ToString())*/);
- break;
- case "SN3":
- format1.SubStrings[j].Value = (Prefix.Text /*+ lpad(4, (temp + 2).ToString())*/);
- break;
- default:
- break;
- }
- }
- format1.PrintSetup.PrinterName = PrinterList.Text;
- format1.PrintSetup.IdenticalCopiesOfLabel = 1;
- format1.Print();
- }
- }
- }
- private static string lpad(int length, string number)
- {
- while (number.Length < length)
- {
- number = "0" + number;
- }
- number = number.Substring(number.Length - length, length);
- return number;
- }
- private void SystemSetting_PrinterTest_Load(object sender, EventArgs e)
- {
- label5.Visible = false;
- Prefix.Visible = false;
- engine.Start();
- format = engine.Documents.Open(Application.StartupPath + "/Label.btw");
- format1 = engine.Documents.Open(Application.StartupPath + "/Material.btw");
- }
- private void SN_CheckedChanged(object sender, EventArgs e)
- {
- if (SN.Checked)
- {
- label6.Text = "机型相关配置";
- label5.Visible = false;
- Prefix.Visible = false;
- label7.Visible = true;
- ma_code.Visible = true;
- label4.Visible = true;
- Mark.Visible = true;
- Rn.Visible = true;
- label3.Visible = true;
- this.pictureBox1.Image = global::UAS_MES_NEW.Properties.Resources.SN;
- }
- else
- {
- this.pictureBox1.Image = global::UAS_MES_NEW.Properties.Resources.Material;
- label6.Text = "标签部分(显示)";
- label5.Visible = true;
- Prefix.Visible = true;
- Rn.Visible = false;
- label3.Visible = false;
- label7.Visible = false;
- ma_code.Visible = false;
- label4.Visible = false;
- Mark.Visible = false;
- }
- }
- }
- }
|