123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using Seagull.BarTender.Print;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- using static System.Runtime.CompilerServices.RuntimeHelpers;
- namespace UAS_MES_NEW.SystemSetting
- {
- public partial class SystemSetting_PrinterTest : Form
- {
- Engine engine = new Engine();
- LabelFormatDocument format;
- DataHelper dh = SystemInf.dh;
- DataTable Dbfind;
- 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(System.Drawing.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 (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
- {
- MessageBox.Show("工单号不存在");
- return;
- }
- /*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");
- if (dt.Rows.Count > 0)
- {
- string pr_machinetype = dt.Rows[0]["pr_machinetype"].ToString();
- if (pr_machinetype != Prefix.Text)
- {
- MessageBox.Show("前缀和产品机型" + pr_machinetype + "不匹配");
- return;
- }
- }*/
- if (OneColumn.Checked)
- {
- format = engine.Documents.Open(Application.StartupPath + "/单排.btw");
- for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 1)
- {
- 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 + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "COLOR":
- format.SubStrings[j].Value = Color.Text;
- break;
- case "MACHINE":
- format.SubStrings[j].Value = MachineType.Text;
- break;
- case "RAM":
- format.SubStrings[j].Value = Ram.Text;
- break;
- default:
- break;
- }
- }
- format.PrintSetup.PrinterName = PrinterList.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
- ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
- ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
- pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
- }
- }
- }
- if (TwoColumn.Checked)
- {
- format = engine.Documents.Open(Application.StartupPath + "/双排.btw");
- 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 + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "SN2":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- default:
- break;
- }
- }
- format.PrintSetup.PrinterName = PrinterList.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
- ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
- ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
- pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
- }
- }
- }
- if (ThreeColumn.Checked)
- {
- format = engine.Documents.Open(Application.StartupPath + "/Label.btw");
- 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 < format.SubStrings.Count; j++)
- {
- switch (format.SubStrings[j].Name)
- {
- case "SN":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "SN2":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "SN3":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- default:
- break;
- }
- }
- format.PrintSetup.PrinterName = PrinterList.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
- ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
- ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
- pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
- }
- }
- }
- if (FourColumn.Checked)
- {
- format = engine.Documents.Open(Application.StartupPath + "/四排.btw");
- for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 4)
- {
- 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 + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "SN2":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "SN3":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- case "SN4":
- format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 3).ToString()));
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
- dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.SubStrings[j].Value + "','before',-1)", "insert");
- break;
- default:
- break;
- }
- }
- format.PrintSetup.PrinterName = PrinterList.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
- ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
- ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
- pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
- }
- }
- }
- }
- 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)
- {
- engine.Start();
- ma_code.TableName = " make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
- ma_code.FormName = Name;
- ma_code.SetValueField = new string[] { "ma_code" };
- ma_code.Condition = "ma_statuscode='STARTED'";
- ma_code.DbChange += pr_code_DbChange;
- }
- private void pr_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- DataTable dt = (DataTable)dh.ExecuteSql("select ma_submodel,ma_color,ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,mil_makecode from makeimeilist where mil_printstatus=-1 group by mil_makecode) on mil_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- Color.Text = dt.Rows[0]["ma_color"].ToString();
- MachineType.Text = dt.Rows[0]["ma_submodel"].ToString();
- pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
- ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
- ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
- pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
- }
- }
- }
- }
|