using System; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.PublicMethod; using UAS_MES_NEW.Entity; using LabelManager2; using System.IO; using System.Threading; using UAS_MES_NEW.PublicForm; using Seagull.BarTender.Print; using static System.Runtime.CompilerServices.RuntimeHelpers; namespace UAS_MES_NEW.Make { public partial class Make_FuselageLabelPrintGetIMEIWatch : Form { DataHelper dh; DataTable dt; LogStringBuilder sql = new LogStringBuilder(); Document doc; AutoSizeFormClass asc = new AutoSizeFormClass(); //保存StepProduct查询出来的数据 // DataTable ListA = new DataTable(); //保存make left join makecraftdetail left join product的数据 // DataTable ListB; DataTable mapB; string ma_unlimitin = ""; ApplicationClass lbl; string oMakeCode = ""; string oMsId = ""; string oErrorMessage = ""; Thread InitPrint; bool pr_change = false; ftpOperater ftp; DataTable Dbfind; public Make_FuselageLabelPrintGetIMEIWatch() { InitializeComponent(); } private void Make_FuselageLabelPrint_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); OperateResult.AppendText(">>请输入SN\n", Color.Black); InitPrint = new Thread(InPrint); SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); sncode.Focus(); LockMakeCode.GetMakeCodeCtl(ma_code); ma_code.SetLockCheckBox(LockMakeCode); //工单号放大镜配置 ma_code.TableName = "make left join product on ma_prodcode=pr_code"; ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,pr_detail # 产品名称"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_detail" }; ma_code.DbChange += Ma_code_DbChange; ma_code.Condition = "(ma_statuscode='STARTED' or ma_statuscode='FINISH')"; dh = SystemInf.dh; StepCount.StepCode = User.CurrentStepCode; StepCount.Source = User.UserSourceCode; StepCount.LineCode = User.UserLineCode; StepCount.Dh = dh; StepCount.Start(); } private void Ma_code_DbChange(object sender, EventArgs e) { Dbfind = ma_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); ////获取工单的其他信息 //sql.Clear(); //sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,"); //sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on "); //sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'"); //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //if (dt.Rows.Count > 0) //{ // BaseUtil.SetFormValue(this.Controls, dt); //} } Engine engine; private void InPrint() { try { engine = new Engine(true); } catch (Exception ex) { OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red); } } private void sn_code_KeyDown(object sender, KeyEventArgs e) { //按下enter键 if (e.KeyCode == Keys.Enter) { //如果输入的值为空的话,提示不能为空 if (sncode.Text == "") { OperateResult.AppendText(">>序列号不能为空\n", Color.Red); return; } if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage)) { //定义临时变量 string oStatus = ""; //调用公共方法CheckStepSNAndMacode判断工序是否正确 string status = ""; dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sncode.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["ms_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sncode.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["ms_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sncode.Text + "' order by mil_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["mil_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sncode.Text + "' order by mil_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["mil_sncode"].ToString(); } } } } LogicHandler.GetMakeInfo(sncode.Text, out oMakeCode, out status, out oErrorMessage); if (oMakeCode == "" || oMakeCode == null) oMakeCode = ma_code.Text; if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out oErrorMessage)) { string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsId + "'").ToString(); if (nextstepcode != User.CurrentStepCode) { string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString(); OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sncode); return; } //IF (如果ma_code 为空)THEN if (ma_code.Text == "" || ma_code.Text != oMakeCode) { //获取工单的其他信息 sql.Clear(); sql.Append("select ma_code,nvl(mcd_okqty,0),ma_prodcode,pr_detail,nvl(ma_unlimitin,0)ma_unlimitin,"); sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on "); sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'"); mapB = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //如果有数据的话 if (mapB.Rows.Count > 0) { ma_unlimitin = mapB.Rows[0]["ma_unlimitin"].ToString(); //将工单的其他信息赋值到对应的控件 BaseUtil.SetFormValue(this.Controls, mapB); //提示用户“<<工单号:取ma_makecode” OperateResult.AppendText("<<工单号:" + ma_code.Text + "\n", Color.Black); //提示用户“<< 序列号:XXXX” if (PrintLabel.SelectedValue == null) { OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode); return; } if (pr_change) { pr_change = false; if (MessageBox.Show("是否使用默认标签", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { OperateResult.AppendText(">>请选择标签模板\n", Color.Green, sncode); return; } } } //没有数据 else { OperateResult.AppendText(">>无序列号" + sncode.Text + "对应工单信息\n", Color.Red); return; } } //所选标签不为空 if (PrintLabel.SelectedValue != null) { //如果打印张数为空,返回 if (PrintNum.Text == "" || int.Parse(PrintNum.Text) == 0) { OperateResult.AppendText(">>打印张数不可空或者为0\n", Color.Red, sncode); //清空输入框的值,聚焦 sncode.Focus(); //提示用户“>>请输入SN” OperateResult.AppendText(">>请输入SN\n", Color.Black); return; } OperateResult.AppendText("<<序列号:" + sncode.Text + "\n", Color.Black); //按照打印张数打印 string oIMEI1 = ""; string oIMEI2 = ""; string oMEID = ""; string oNetcode = ""; string oPSN = ""; string oID1 = ""; string oID2 = ""; string oID3 = ""; if (!LogicHandler.GetMEIOrNetCodeRange(sncode.Text, ma_code.Text, "", "", out oIMEI1, out oIMEI2, out oMEID, out oNetcode, out oPSN, out oID1, out oID2, out oID3, out oErrorMessage)) { OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red); return; }; dh.ExecuteSql("update makeserial set ms_sncode='" + oPSN + "',ms_firstsn='" + oPSN + "',ms_tsn='" + sncode.Text + "' where ms_id='" + oMsId + "' ", "update"); string oBT = ""; string oWifi = ""; string oCode1 = ""; string oCode2 = ""; string oCode3 = ""; LogicHandler.GetAddressRangeByMO(oPSN, out oWifi, out oBT, out oCode1, out oCode2, out oCode3, out oErrorMessage); //清空输入框的值,聚焦 //doc = lbl.Documents.Open(PrintLabel.Text); if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, oPSN, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "0", out oErrorMessage)) { //提示用户打印成功 OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green); } else { OperateResult.AppendText(oErrorMessage + "\n", Color.Red); } //if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "0", out oErrorMessage)) //{ // //提示用户打印成功 // OperateResult.AppendText(">>序列号:" + sncode.Text + "打印成功\n", Color.Green); //} //else //{ // OperateResult.AppendText(oErrorMessage + "\n", Color.Red); //} //记录日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "机身标打印", "机身标打印成功", sncode.Text, ""); //更新打印的数据 if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, oPSN, "机身标打印", "机身标打印成功", User.UserCode, out oErrorMessage)) { //提示正确返回时传递的信息 if (oErrorMessage.Contains("AFTERSUCCESS")) OperateResult.AppendText(">>" + oErrorMessage + "\n"); if (CollectRemark.Checked && Remark.Text != "") { LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text); } sncode.Text = ""; sncode.Focus(); //刷新打印数量和剩余数量 dt = (DataTable)dh.ExecuteSql("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0)ma_unlimitin from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select"); BaseUtil.SetFormValue(Controls, dt); mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + ""; //IF 剩余数=0,则清空form中的数据, 提示用户“工单:xx已经打印完成,>>请输入SN”, 清空mapB,listC 中的数据 if (int.Parse(mcd_remainqty.Text) == 0 && ma_unlimitin == "0") { OperateResult.AppendText(">>工单:" + ma_code.Text + "打印完成,>>请输入SN\n", Color.Green); } //剩余数量不为0 else { OperateResult.AppendText(">>请输入SN\n", Color.Black); } } else { OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode); //清空输入框的值,聚焦 sncode.Text = ""; sncode.Focus(); } } //标签为空 else { OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode); } } else { OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode); } } else { OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode); } } } private void pr_code_TextChanged(object sender, EventArgs e) { DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + ma_prodcode.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_id='" + la_id + "' ) where COLUMN_VALUE is not null)", "select"); PrintLabel.DataSource = _dt; PrintLabel.DisplayMember = "la_url"; PrintLabel.ValueMember = "la_id"; pr_change = true; } } private void Make_FuselageLabelPrint_Activated(object sender, EventArgs e) { sncode.Focus(); } private void Make_FuselageLabelPrint_FormClosing(object sender, FormClosingEventArgs e) { BaseUtil.ClosePrint(lbl); } private void Make_FuselageLabelPrint_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void PrintLabel_SelectedValueChanged(object sender, EventArgs e) { if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView") { string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString(); PrintNum.Text = (PrintNums == "" ? "1" : PrintNums); } } private void StepCount_Load(object sender, EventArgs e) { } } }