using HslCommunication.Profinet.Knx; using LabelManager2; using Seagull.BarTender.Print; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; 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.Make { public partial class Make_RePrintLabel : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); AutoSizeFormClass asc = new AutoSizeFormClass(); Engine engine; Thread InitPrint;//实例化打印进程 DataTable dt; DataTable listA; string getlabel = ""; DataTable mapB; string ms_id = ""; DataTable formValue;//界面赋值 string type = ""; string errorMessage = ""; public Make_RePrintLabel() { InitializeComponent(); } private void Make_RePrintLabel_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(); inputText.Focus(); dh = SystemInf.dh; } private void InPrint() { try { engine = new Engine(true); BaseUtil.WriteLbl(); } catch (Exception) { OperateResult.AppendText("未正确安装Bartender软件\n", Color.Red); } } private void Make_RePrintLabel_SizeChanged(object sender, EventArgs e) { //窗体大小变化的时候 asc.controlAutoSize(this); } private void Make_RePrintLabel_FormClosing(object sender, FormClosingEventArgs e) { //窗口关闭的时候 BaseUtil.ClosePrint(engine); } private void radioButton_CheckedChange(object sender, EventArgs e) { RadioButton btn = sender as RadioButton; if ((btn.Name == "giftBox" || btn.Name == "fuselagel") && btn.Checked) { //如果是切换成彩盒或者机身标提示用户 输入SN OperateResult.AppendText(">>请输入SN\n", Color.Black); clearAll(); } else if (btn.Name == "CartonBox" && btn.Checked) { OperateResult.AppendText(">>请输入卡通箱号\n", Color.Black); clearAll(); } else if (btn.Name == "BigBox" && btn.Checked) { OperateResult.AppendText(">>请输入大箱号\n", Color.Black); clearAll(); } else if (btn.Name == "Pallte" && btn.Checked) { OperateResult.AppendText(">>请输入栈板号\n", Color.Black); clearAll(); } } private void inputText_KeyDown(object sender, KeyEventArgs e) { //按下enter键 if (e.KeyCode == Keys.Enter) { if (inputText.Text == "") { OperateResult.AppendText("<<输入不能为空\n", Color.Red); return; } OperateResult.AppendText(">>" + inputText.Text + "\n", Color.Black); //打印类型为彩盒或者机身标 if (giftBox.Checked || fuselagel.Checked) { //select max(ms_id)ms_id from makeserial where ms_sncode=? ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + inputText.Text + "'").ToString(); if (ms_id == "") { //如果ms_id 无值或者为空,提示用户SN不存在,请输入SN sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + inputText.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + inputText.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { OperateResult.AppendText("<>请输入SN\n", Color.Black); return; } else { ms_id = dt.Rows[0]["ms_id"].ToString(); } } else { ms_id = dt.Rows[0]["ms_id"].ToString(); } } ////判断是否装箱通过 //if (checkPacked()) //{ // return; //} //界面赋值 formValue = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode,pr_code,pr_detail from makeserial left join product on MS_PRODCODE=pr_code where ms_id='" + ms_id + "'", "select"); BaseUtil.SetFormValue(this.Controls, formValue); //无值,可补打 inputValue.Text = formValue.Rows[0]["ms_sncode"].ToString(); inputText.Text = ""; } //打印类型为卡通箱 else if (CartonBox.Checked) { dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_outboxcode='" + inputText.Text + "' or ms_imei2='" + inputText.Text + "' or ms_imei1='" + inputText.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { inputText.Text = dt.Rows[0]["ms_outboxcode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_imei2='" + inputText.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { inputText.Text = dt.Rows[0]["ms_outboxcode"].ToString(); } } //查询箱号是否存在 dt = (DataTable)dh.ExecuteSql("select pa_id,pa_prodcode pr_code,pa_makecode ms_makecode,pr_detail from package left join product on pr_code=pa_prodcode where pa_outboxcode='" + inputText.Text + "' and pa_type=1", "select"); if (dt.Rows.Count == 0) { //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号” OperateResult.AppendText("<<箱号:" + inputText.Text + "不存在\n", Color.Red, inputText); OperateResult.AppendText(">>请输入卡通箱号\n", Color.Black); return; } //界面赋值 BaseUtil.SetFormValue(this.Controls, dt); //有值,可以打 //展示产品编号和标签模板到界面 inputValue.Text = inputText.Text; inputText.Text = ""; } else if (BigBox.Checked) { dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_imei1='" + inputText.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { inputText.Text = dt.Rows[0]["ms_outboxcode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_imei2='" + inputText.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { inputText.Text = dt.Rows[0]["ms_outboxcode"].ToString(); } } //查询箱号是否存在 dt = (DataTable)dh.ExecuteSql("select pa_id,pa_prodcode pr_code,pa_makecode ms_makecode,pr_detail from package left join product on pr_code=pa_prodcode where pa_outboxcode='" + inputText.Text + "' and pa_type=2", "select"); if (dt.Rows.Count == 0) { //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号” OperateResult.AppendText("<<箱号:" + inputText.Text + "不存在\n", Color.Red, inputText); OperateResult.AppendText(">>请输入大箱号\n", Color.Black); return; } //界面赋值 BaseUtil.SetFormValue(this.Controls, dt); //有值,可以打 //展示产品编号和标签模板到界面 inputValue.Text = inputText.Text; inputText.Text = ""; } else if (Pallte.Checked) { dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_imei1='" + inputText.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { inputText.Text = dt.Rows[0]["ms_outboxcode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_imei2='" + inputText.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { inputText.Text = dt.Rows[0]["ms_outboxcode"].ToString(); } } //查询箱号是否存在 dt = (DataTable)dh.ExecuteSql("select pa_id,pa_prodcode pr_code,pa_makecode ms_makecode,pr_detail from package left join product on pr_code=pa_prodcode where pa_outboxcode='" + inputText.Text + "' and pa_type=3", "select"); if (dt.Rows.Count == 0) { //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号” OperateResult.AppendText("<<栈板:" + inputText.Text + "不存在\n", Color.Red, inputText); OperateResult.AppendText(">>请输入栈板号\n", Color.Black); return; } //界面赋值 BaseUtil.SetFormValue(this.Controls, dt); //有值,可以打 //展示产品编号和标签模板到界面 inputValue.Text = inputText.Text; inputText.Text = ""; } print_Click(sender, new EventArgs()); } } private void PrintLabel_TextChanged(object sender, EventArgs e) { if (pr_code.Text == "") { return; } if (fuselagel.Checked) type = "机身标"; else if (giftBox.Checked) type = "彩盒标"; else if (CartonBox.Checked) type = "卡通箱标"; else if (BigBox.Checked) type = "大箱标"; else type = "栈板标"; listA = (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='" + type + "' and la_statuscode='AUDITED' order by la_isdefault", "select"); if (listA.Rows.Count == 0) { listA = (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='" + type + "' and la_statuscode='AUDITED' order by la_isdefault", "select"); } if (listA.Rows.Count > 0) { string la_id = listA.Rows[0]["la_id"].ToString(); listA = (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 = listA; PrintLabel.DisplayMember = "la_url"; PrintLabel.ValueMember = "la_id"; } } private void print_Click(object sender, EventArgs e) { //输入值字段值不为空,打印不为空,有选中打印模板,才可以进行打印,打印前再次判断 if (inputValue.Text == "") { OperateResult.AppendText("<<无箱号或者序列号\n", Color.Red); return; } if (PrintLabel.Text == "") { OperateResult.AppendText("<<无打印模板\n", Color.Red); return; } //打印类型 彩盒或者标签,再次判断是否已装箱,未转号 if (giftBox.Checked || fuselagel.Checked) { mapB = (DataTable)dh.ExecuteSql("select ms_outboxcode, nvl(ms_downstatus,0) ms_downstatus from makeserial where ms_id='" + ms_id + "' and ms_sncode='" + inputValue.Text + "'", "select"); if (mapB.Rows.Count == 0) { //无值提示用户序列号错误,不存在或者已经发生转号 OperateResult.AppendText("<<序列号错误,不存在或已经发生转号\n", Color.Red); return; } //如果ms_outboxcode 不为空,则提示用户,已经装箱不允许单独打印 if (mapB.Rows[0]["ms_outboxcode"].ToString() != "" && !AllowInBox.Checked) { OperateResult.AppendText("<0,则更新ms_downstatus=-1 where ms_id=?id,同时插入记录至表 MAKEDOWN if (mapB.Rows[0]["ms_downstatus"].ToString() == "0") { //dh.ExecuteSql("update makeserial set ms_downstatus='-1' where ms_id='" + ms_id + "'", "update"); //插入数据 //putInfo2MakeDown(); } } //打印类型为卡通箱标签 else if (CartonBox.Checked) { //select pa_downstatus from package where pa_outboxcode=? 输入值code mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select"); //无值提示用户箱号错误,不存在。 if (mapB.Rows.Count == 0) { OperateResult.AppendText("<<箱号:" + inputValue.Text + "错误,不存在\n", Color.Red); return; } //doc = lbl.Documents.Open(PrintLabel.Text); if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "卡通箱标", "-1", out errorMessage)) { //判断通过,打印 OperateResult.AppendText("<<打印成功\n", Color.Green); } else { OperateResult.AppendText(errorMessage + "\n", Color.Red); } //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱标签补打印,箱号:" + inputValue.Text, "补打印成功", inputValue.Text, ""); //如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN //if (mapB.Rows[0]["pa_downstatus"].ToString() == "0") //{ // dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update"); // //插入MakeDown表 // putInfo2MakeDown(); //} } else if (BigBox.Checked) { //select pa_downstatus from package where pa_outboxcode=? 输入值code mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select"); //无值提示用户箱号错误,不存在。 if (mapB.Rows.Count == 0) { OperateResult.AppendText("<<箱号:" + inputValue.Text + "错误,不存在\n", Color.Red); return; } //doc = lbl.Documents.Open(PrintLabel.Text); if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "大箱标", "-1", out errorMessage)) { //判断通过,打印 OperateResult.AppendText("<<打印成功\n", Color.Green); } else { OperateResult.AppendText(errorMessage + "\n", Color.Red); } //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "大箱标签补打印,箱号:" + inputValue.Text, "补打印成功", inputValue.Text, ""); //如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN //if (mapB.Rows[0]["pa_downstatus"].ToString() == "0") //{ // dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update"); // //插入MakeDown表 // putInfo2MakeDown(); //} } else if (Pallte.Checked) { //select pa_downstatus from package where pa_outboxcode=? 输入值code mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select"); //无值提示用户箱号错误,不存在。 if (mapB.Rows.Count == 0) { OperateResult.AppendText("<<栈板号:" + inputValue.Text + "错误,不存在\n", Color.Red); return; } if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "栈板标", "-1", out errorMessage)) { //判断通过,打印 OperateResult.AppendText("<<打印成功\n", Color.Green); } else { OperateResult.AppendText(errorMessage + "\n", Color.Red); } //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板标签补打印,栈板号:" + inputValue.Text, "补打印成功", inputValue.Text, ""); } } /// /// 插入表MAKEDOWN /// private void putInfo2MakeDown() { //插入数据至表MAKEDOWN string md_code = ""; LogicHandler.GetSerialNumByCaller("MakeDown", out md_code); sql.Clear(); sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_LINECODE,MD_SCCODE,MD_STEPCODE,"); sql.Append((CartonBox.Checked ? "MD_OUTBOXCODE" : "MD_SNCODE") + ",MD_PRODCODE,MD_MACODE, MD_DOWNREASON, MD_CODE,"); sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) values (MAKEDOWN_seq.nextval,'" + User.UserLineCode + "','" + User.UserSourceCode + "',"); sql.Append("'" + User.CurrentStepCode + "','" + inputValue.Text + "','" + pr_code.Text + "','" + ms_makecode.Text + "','补打标签','" + md_code + "',sysdate,'" + User.UserCode + "','-1')"); dh.ExecuteSql(sql.GetString(), "insert"); } private void rePrintCheck_KeyDown(object sender, KeyEventArgs e) { } /// /// 清除信息 /// private void clearAll() { //清除输入值、工单代码、产品编号,名称、打印模板、核对第一次输入的SN inputValue.Text = ""; ms_makecode.Text = ""; pr_code.Text = ""; pr_detail.Text = ""; if (listA != null) { listA.Clear(); } } } }