123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- 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();
- }
- }
- }
- }
- }
|