Browse Source

封装CodeSoft打印

章政 6 năm trước cách đây
mục cha
commit
e4d67764d5

+ 186 - 0
UAS-出货标签管理(贸易版)/PublicMethod/Print.cs

@@ -0,0 +1,186 @@
+using LabelManager2;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+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() == "字符串")
+                            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() == "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() == "字符串")
+                    {
+                        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 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
+                    if (dr1.Length > 0 && dr1[0]["lp_valuetype"].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)
+            {
+                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() == "字符串")
+                    {
+                        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_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2), "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 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
+                        if (dr1.Length > 0 && dr1[0]["lp_valuetype"].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()
+            {
+
+            }
+            public static void MidPrint()
+            {
+
+            }
+            public static void OutPrint()
+            {
+
+            }
+        }
+    }
+}

+ 1 - 0
UAS-出货标签管理(贸易版)/UAS-出货标签管理(贸易版).csproj

@@ -243,6 +243,7 @@
     <Compile Include="PublicMethod\GlobalEventsHandler.cs" />
     <Compile Include="PublicMethod\HttpHandler.cs" />
     <Compile Include="PublicMethod\LogManager.cs" />
+    <Compile Include="PublicMethod\Print.cs" />
     <Compile Include="PublicMethod\SqliteDBHelper.cs" />
     <Compile Include="Service References\Vivo_BoxReelRelation\Reference.cs">
       <AutoGen>True</AutoGen>

+ 4 - 142
UAS-出货标签管理(贸易版)/UAS_出货标签管理.cs

@@ -142,7 +142,7 @@ namespace UAS_LabelMachine
 
         List<string> OutParam = new List<string>();
 
-        DataTable Attach;
+        public static DataTable Attach;
 
         public UAS_出货标签打印(string Master)
         {
@@ -643,42 +643,7 @@ namespace UAS_LabelMachine
 
         private void AutoPrintSingleLabel(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() == "字符串")
-                        sql.Append(dr1[0]["lp_sql"].ToString() + ",");
-                }
-            }
-            sql.Append("1,");
-            DataTable dt = (DataTable)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() == "SQL值")
-                {
-                    DataTable dt1 = (DataTable)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 = 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();
+            Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pib_id);
             LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
         }
 
@@ -1453,56 +1418,8 @@ namespace UAS_LabelMachine
             //获取对应行的pib_id
             string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
             string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
-            sql.Clear();
+            Print.CodeSoft.MidPrint(MidDoc, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
 
-            //查询参数名称相同的获取到取值字段
-            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() == "字符串")
-                {
-                    sql.Append(dr1[0]["lp_sql"].ToString() + ",");
-                }
-            }
-            sql.Append("1,");
-            DataTable dt = (DataTable)sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' 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 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
-                if (dr1.Length > 0 && dr1[0]["lp_valuetype"].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)sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno.Text + "'").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 = 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();
         }
 
         private void OutBoxCodePrint(int rowindex)
@@ -1510,62 +1427,7 @@ namespace UAS_LabelMachine
             //获取对应行的pib_id
             string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
             string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
-            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() == "字符串")
-                {
-                    sql.Append(dr1[0]["lp_sql"].ToString() + ",");
-                }
-            }
-            sql.Append("1,");
-            DataTable dt = (DataTable)sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2), "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 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
-                    if (dr1.Length > 0 && dr1[0]["lp_valuetype"].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)sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno.Text + "'").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 = 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();
-            }
+            Print.CodeSoft.OutPrint(OutBoxDoc, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2);
         }
 
         private void CleanDetail_Click(object sender, EventArgs e)