using LabelManager2; using Seagull.BarTender.Print; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using UAS_LabelMachine.Entity; namespace UAS_LabelMachine.PublicMethod { class Print { public class CodeSoft { public static void SinglePrint(Document SingleDoc, DataTable SingleLabelParam, string pib_id) { StringBuilder sql = new StringBuilder(); sql.Clear(); for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++) { DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0) { if (dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") sql.Append(dr1[0]["lp_sql"].ToString() + ","); } } sql.Append("1,"); DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select"); for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++) { DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值") { DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select"); if (dt1.Rows.Count > 0) { SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt1.Rows[0][0].ToString(); } } else if (dr1.Length > 0) { SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } if (SingleDoc.Variables.FormVariables.Item(j + 1).Value == "") { dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0) SingleDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString(); } } SingleDoc.PrintDocument(); } public static void MidPrint(Document MidDoc, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1) { StringBuilder sql = new StringBuilder(); //查询参数名称相同的获取到取值字段 for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++) { DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { sql.Append(dr1[0]["lp_sql"].ToString() + ","); } } sql.Append("1,"); DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode1=" + (pib_outboxcode1 == "" ? "0" : pib_outboxcode1), "select"); for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++) { DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { MidDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } //SQL判断多个值的时候 if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值") { DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select"); for (int i = 0; i < dt1.Rows.Count; i++) { for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++) { if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString()) { MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString(); } //使用SN开头的参数赋值SN1,SN2,SN3等参数 if (MidDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1))) { MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString(); } } } } if (MidDoc.Variables.FormVariables.Item(j + 1).Value == "") { dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0) MidDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString(); } } MidDoc.PrintDocument(); } public static void OutPrint(Document OutBoxDoc, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2, bool iCustProdCode, bool iCustPo, bool iDC, bool iLotNo, bool iOrderCode) { StringBuilder sql = new StringBuilder(); sql.Clear(); for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++) { DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { sql.Append(dr1[0]["lp_sql"].ToString() + ","); } } //界面设定的分组条件 string GroupByCondition = ""; if (iCustProdCode) { GroupByCondition += "pd_custprodcode,"; } if (iCustPo) { GroupByCondition += "pd_pocode,"; } if (iDC) { GroupByCondition += "pib_datecode,"; } if (iLotNo) { GroupByCondition += "pib_lotno,"; } if (iOrderCode) { GroupByCondition += "pd_ordercode,"; } if (iCustProdCode || iCustPo || iDC || iLotNo) { GroupByCondition = " group by " + (GroupByCondition.Substring(0, GroupByCondition.Length - 1)); } sql.Append("1,"); DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2) + GroupByCondition, "select"); if (dt.Rows.Count > 0) { for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++) { DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } //SQL判断多个值的时候 if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值") { DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select"); for (int i = 0; i < dt1.Rows.Count; i++) { for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++) { if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString()) { OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString(); } //使用SN开头的参数赋值SN1,SN2,SN3等参数 if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1))) { OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString(); } if (dr1[0]["lp_sql"].ToString().Contains("pib_year")) { string date = dt1.Rows[0][0].ToString(); } } } } if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "") { dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'"); if (dr1.Length > 0) OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString(); } } OutBoxDoc.PrintDocument(); } } } public class BarTender { public static void SinglePrint(LabelFormatDocument SingleFormat, DataTable SingleLabelParam, string pib_id) { StringBuilder sql = new StringBuilder(); sql.Clear(); for (int j = 0; j < SingleFormat.SubStrings.Count; j++) { DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { sql.Append(dr1[0]["lp_sql"].ToString() + ","); } } sql.Append("1,"); DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select"); for (int j = 0; j < SingleFormat.SubStrings.Count; j++) { DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值") { DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select"); if (dt1.Rows.Count > 0) { SingleFormat.SubStrings[j].Value = dt1.Rows[0][0].ToString(); } } else if (dr1.Length > 0) { SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } if (SingleFormat.SubStrings[j].Value == "") { DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'"); if (dr2.Length > 0) SingleFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString(); } //启用了校验Dc和LotNo不为空的设置 if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && SingleFormat.SubStrings[j].Value == "") { //如果SQL用到了DC和LotNo字段 if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode"))) { MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据"); return; } } } try { SingleFormat.PrintSetup.IdenticalCopiesOfLabel = 1; } catch (Exception) { } SingleFormat.Print(); } public static void MidPrint(LabelFormatDocument MidFormat, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1) { StringBuilder sql = new StringBuilder(); //查询参数名称相同的获取到取值字段 for (int j = 0; j < MidFormat.SubStrings.Count; j++) { DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { sql.Append(dr1[0]["lp_sql"].ToString() + ","); } } sql.Append("1,"); DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode1=" + (pib_outboxcode1 == "" ? "0" : pib_outboxcode1) + " limit 0,1", "select"); for (int j = 0; j < MidFormat.SubStrings.Count; j++) { DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { MidFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString(); } //SQL判断多个值的时候 if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值") { DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select"); for (int i = 0; i < dt1.Rows.Count; i++) { for (int k = 0; k < MidFormat.SubStrings.Count; k++) { if (i == 0 & MidFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString()) { MidFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString(); } //使用SN开头的参数赋值SN1,SN2,SN3等参数 if (MidFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1))) { MidFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString(); } } } } if (MidFormat.SubStrings[j].Value == "") { DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'"); if (dr2.Length > 0) MidFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString(); } //启用了校验Dc和LotNo不为空的设置 if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && MidFormat.SubStrings[j].Value == "") { //如果SQL用到了DC和LotNo字段 if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode"))) { MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据"); return; } } } try { MidFormat.PrintSetup.IdenticalCopiesOfLabel = 1; } catch (Exception) { } MidFormat.Print(); } public static void OutPrint(LabelFormatDocument OutFormat, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2, bool iCustProdCode, bool iCustPo, bool iDC, bool iLotNo, bool iOrderCode) { StringBuilder sql = new StringBuilder(); sql.Clear(); for (int j = 0; j < OutFormat.SubStrings.Count; j++) { DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { sql.Append(dr1[0]["lp_sql"].ToString() + ","); } } //界面设定的分组条件 string GroupByCondition = ""; if (iCustProdCode) { GroupByCondition += "pd_custprodcode,"; } if (iCustPo) { GroupByCondition += "pd_pocode,"; } if (iDC) { GroupByCondition += "pib_datecode,"; } if (iLotNo) { GroupByCondition += "pib_lotno,"; } if (iOrderCode) { GroupByCondition += "pd_ordercode,"; } if (iCustProdCode || iCustPo || iDC || iLotNo) { GroupByCondition = " group by " + (GroupByCondition.Substring(0, GroupByCondition.Length - 1)); } sql.Append("1,"); DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2) + GroupByCondition, "select"); for (int m = 0; m < dt.Rows.Count; m++) { for (int j = 0; j < OutFormat.SubStrings.Count; j++) { DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'"); if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "") { OutFormat.SubStrings[j].Value = dt.Rows[m][dr1[0]["lp_sql"].ToString()].ToString(); } //SQL判断多个值的时候 if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值") { DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select"); for (int i = 0; i < dt1.Rows.Count; i++) { for (int k = 0; k < OutFormat.SubStrings.Count; k++) { if (i == 0 & OutFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString()) { OutFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString(); } //使用SN开头的参数赋值SN1,SN2,SN3等参数 if (OutFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1))) { OutFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString(); } if (dr1[0]["lp_sql"].ToString().Contains("pib_year")) { string date = dt1.Rows[0][0].ToString(); } } } } if (OutFormat.SubStrings[j].Value == "") { DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'"); if (dr2.Length > 0) OutFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString(); } //启用了校验Dc和LotNo不为空的设置 if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && OutFormat.SubStrings[j].Value == "") { //如果SQL用到了DC和LotNo字段 if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode"))) { MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据"); return; } } } try { OutFormat.PrintSetup.IdenticalCopiesOfLabel = 1; } catch (Exception) { } OutFormat.Print(); } } } } }