123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using DevExpress.Printing.Core.PdfExport.Metafile;
- using HslCommunication;
- using LabelManager2;
- using Seagull.BarTender.Print;
- using System;
- using System.Data;
- using System.Drawing;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicForm;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Query
- {
- public partial class Query_SN : Form
- {
- DataHelper dh = SystemInf.dh;
- Engine engine;
- Thread InitPrint;
- DataTable Dbfind;
- Document doc;
- DataTable _dt;
- public Query_SN()
- {
- InitializeComponent();
- }
- private void Query_SpecialReport_Load(object sender, EventArgs e)
- {
- InitPrint = new Thread(InPrint);
- SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- 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_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)
- {
- 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 void InPrint()
- {
- try
- {
- engine = new Engine(true);
- }
- catch (Exception)
- {
- MessageBox.Show("未正确安装BarTender软件");
- }
- }
- private void Print_Click(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- string ErrorMessage = "";
- if (!PrintNums.Checked)
- {
- string batch = System.DateTime.Now.ToString("yyyyMMddhhmiss");
- if (RePrintSn.Text == "")
- {
- dt = (DataTable)dh.ExecuteSql("select msl_sncode from makesnlist where msl_makecode='" + ma_code.Text + "' and nvl(msl_printstatus,0)=0 order by msl_sncode", "select");
- if (dt.Rows.Count < PrintNum.Value)
- {
- OperateResult.AppendText("未打印数量不足,剩余" + dt.Rows.Count + "未打印\n");
- return;
- }
- for (int i = 0; i < PrintNum.Value; i++)
- {
- string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
- if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
- {
- //提示用户打印成功
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
- }
- else
- {
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- 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();
- }
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select msl_sncode from makesnlist left join makeimeilist on mil_sncode=msl_sncode and mil_makecode=msl_makecode where msl_makecode='" + ma_code.Text + "' and (msl_sncode='" + RePrintSn.Text + "' or mil_imei1='"+RePrintSn.Text+"' or mil_imei2='"+RePrintSn.Text + "')order by msl_sncode", "select");
- if (dt.Rows.Count > 0)
- {
- string mil_sncode = dt.Rows[0]["msl_sncode"].ToString();
- if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
- {
- //提示用户打印成功
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
- }
- else
- {
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1,msl_printbatch='" + batch + "' where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- else
- {
- OperateResult.AppendText("序列号:" + RePrintSn.Text + "不在工单" + ma_code.Text + "\n", Color.Red, RePrintSn);
- }
- }
- }
- else
- {
- dh.ExecuteSql("update make set ma_printqty='" + SingleRowCount.Value + "' where ma_code='" + ma_code.Text + "'", "update");
- dt = (DataTable)dh.ExecuteSql("select msl_sncode from (select msl_sncode from makesnlist where msl_makecode='" + ma_code.Text + "' and nvl(msl_printstatus,0)=0 order by msl_sncode) where rownum<='" + PrintNum.Value * SingleRowCount.Value + "'", "select");
- decimal rowcount = 0;
- for (int i = 0; i < dt.Rows.Count; i = i + 1)
- {
- string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
- if (rowcount % SingleRowCount.Value == 0)
- {
- if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
- {
- //提示用户打印成功
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
- }
- else
- {
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- else
- {
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
- }
- rowcount = rowcount + 1;
- }
- 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 void pr_code_TextChanged(object sender, EventArgs e)
- {
- _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
- if (_dt.Rows.Count == 0)
- {
- _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode is null and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
- }
- if (_dt.Rows.Count > 0)
- {
- string la_id = _dt.Rows[0]["la_id"].ToString();
- _dt = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id from FILEPATH where fp_id in (select * from table(select parsestring(LA_SOFTTYPE,';') from label where la_templatetype='机身标' and la_id='" + la_id + "') where COLUMN_VALUE is not null)", "select");
- PrintLabel.DataSource = _dt;
- PrintLabel.DisplayMember = "la_url";
- PrintLabel.ValueMember = "la_id";
- }
- }
- private void PrintByBatch_Click(object sender, EventArgs e)
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select * from makesnlist where mil_printbatch='" + PrintBatch.Text + "'", "select");
- string ErrorMessage = "";
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string mil_sncode = dt.Rows[i]["msl_sncode"].ToString();
- if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, mil_sncode, int.Parse("1"), ma_code.Text, pr_code.Text, "机身标", "0", out ErrorMessage))
- {
- //提示用户打印成功
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- dh.ExecuteSql("update makesnlist set msl_printstatus=-1 where msl_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>序列号:" + mil_sncode + "打印结束\n", Color.Green);
- }
- else
- {
- dh.ExecuteSql("update makeimeilist set mil_printstatus=-1 where mil_sncode='" + mil_sncode + "'", "update");
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- }
- else
- {
- OperateResult.AppendText(">>批号:" + PrintBatch.Text + "不存在\n", Color.Green);
- }
- }
- }
- }
|