소스 검색

打印参数获取调整

章政 7 년 전
부모
커밋
e57c021e74
1개의 변경된 파일113개의 추가작업 그리고 81개의 파일을 삭제
  1. 113 81
      UAS-出货标签管理/UAS_出货标签管理.cs

+ 113 - 81
UAS-出货标签管理/UAS_出货标签管理.cs

@@ -86,6 +86,10 @@ namespace UAS_LabelMachine
         //每个不同序号存在的
         object[] ItemData;
 
+        DataTable SingleLabelParam;
+        DataTable MidLabelParam;
+        DataTable OutLabelParam;
+
         Dictionary<string, string> CollectData;
         //缓存单盘数据数据的DataTable
         DataTable SingleBoxCacheData;
@@ -586,7 +590,9 @@ namespace UAS_LabelMachine
                                 string la_id = SingleLabelCombox.SelectedValue.ToString().Split('#')[0];
                                 string cl_labelname = SingleLabelCombox.Text;
                                 string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
+                                Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                                 AutoPrintSingleLabel(la_id, LabelUrl);
+                                Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                             }
                             else
                             {
@@ -661,57 +667,58 @@ namespace UAS_LabelMachine
 
         private void AutoPrintSingleLabel(string la_id, string LabelUrl)
         {
-            //获取维护的变量名称和SQL
-            dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
-            DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql  from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
+            string[] arg = SingleBoxArgument.ToArray();
             //用标签本身的变量作为最外层的循环条件去匹配;
-            dt.Merge(Attach);
             for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
             {
                 //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < dt.Rows.Count; k++)
+                StringBuilder ParamLog = new StringBuilder();
+                for (int k = 0; k < SingleLabelParam.Rows.Count; k++)
                 {
                     //名称相等的时候,取SQL进行值的查询
-                    if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() == dt.Rows[k]["lp_name"].ToString().ToLower())
+                    if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() == SingleLabelParam.Rows[k]["lp_name"].ToString().ToLower())
                     {
-                        //获取打印执行的SQL
-                        string sql = dt.Rows[k]["lp_sql"].ToString();
-                        if (sql.IndexOf("{") == 0)
+                        string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
+                        DataRow[] dr = SingleBoxCacheData.Select("pib_id=" + pib_id);
+                        if (arg.Contains(SingleDoc.Variables.FreeVariables.Item(j + 1).Name))
+                            SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dr[0][SingleDoc.Variables.FreeVariables.Item(j + 1).Name].ToString();
+                        if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower().Contains("datecode1"))
                         {
-                            SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
-                            LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
+                            if (LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode1"].Value != null)
+                                SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode1"].Value.ToString();
                         }
-                        else
+                        else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower().Contains("lotno"))
                         {
-                            sql = sql.Substring(0, sql.IndexOf("{"));
-                            //获取对应行的pib_id
-                            string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
-                            if (sql.ToLower().Contains("pib_lotno"))
+                            if (LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value != null)
                                 SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
-                            else if (sql.ToLower().Contains("pib_datecode"))
+                        }
+                        else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower().Contains("datecode"))
+                        {
+                            if (LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value != null)
                                 SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
-                            else if (sql.ToLower().Contains("pib_madein"))
+                        }
+                        else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower().Contains("产地"))
+                        {
+                            if (LabelInf.Rows[CurrentRowIndex].Cells["pib_madein"].Value != null)
                                 SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_madein"].Value.ToString();
-                            else if (sql.ToLower().Contains("pib_cusbarcode"))
+                        }
+                        else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower().Contains("pib_cusbarcode"))
+                        {
+                            if (LabelInf.Rows[CurrentRowIndex].Cells["pib_cusbarcode"].Value != null)
                                 SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_cusbarcode"].Value.ToString();
-                            else if (sql.ToLower().Contains("pib_cusoutboxcode"))
-                                SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_cusoutboxcode"].Value.ToString();
-                            else
-                                SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
-                            if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
+                        }
+                        if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
+                        {
+                            try
+                            {
+                                SingleDoc.Variables.FreeVariables.Item(j + 1).Value = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                            }
+                            catch (Exception)
                             {
-                                try
-                                {
-                                    SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
-
-                                }
-                                catch (Exception)
-                                {
 
-                                }
                             }
-                            LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + pib_id + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
                         }
+                        ParamLog.AppendLine("pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString() + ",SingleDoc打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
                     }
                     else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
                     {
@@ -719,6 +726,7 @@ namespace UAS_LabelMachine
                             SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode1"].Value.ToString();
                     }
                 }
+                LogManager.DoLog(ParamLog.ToString());
             }
             //保存参数打印
             SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
@@ -1056,6 +1064,7 @@ namespace UAS_LabelMachine
         private void GetInOutInfAndLabelFile()
         {
             ComBoxClickChangeLabelDoc = false;
+            DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql  from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
             sql.Clear();
             sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS')  la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
             sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
@@ -1077,7 +1086,11 @@ namespace UAS_LabelMachine
                         BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
                 }
             if (SingleLabelCombox.Text != "")
+            {
                 SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
+                SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
+                SingleLabelParam.Merge(Attach);
+            }
             sql.Clear();
             sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS')  la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
             sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
@@ -1099,7 +1112,12 @@ namespace UAS_LabelMachine
                         BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
                 }
             if (MidLabelCombox.Text != "")
+            {
                 MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
+                MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
+                MidLabelParam.Merge(Attach);
+            }
+            //缓存中盒参数
             sql.Clear();
             sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS')  la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
             sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
@@ -1123,8 +1141,13 @@ namespace UAS_LabelMachine
             if (OutBoxCombox.Text != "")
             {
                 OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
+                OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0], "select");
+                OutLabelParam.Merge(Attach);
             }
+            //缓存外箱参数
             ComBoxClickChangeLabelDoc = true;
+            GetSingleBoxData(SingleLabelCombox.SelectedValue.ToString().Split('#')[0]);
+            GetMidBoxData();
         }
 
         /// <summary>
@@ -1211,7 +1234,7 @@ namespace UAS_LabelMachine
             string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
             //查询该模板维护的所有参数
             dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
-            if (dt.Rows.Count > 0 && LabelInf.Rows.Count > 0)
+            if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
             {
                 //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
                 MidIDAndOutboxcode.Clear();
@@ -1220,18 +1243,18 @@ namespace UAS_LabelMachine
                 Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
                 //判断所有盒号为该盒的是否勾选已采集
                 outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
-                for (int i = 0; i < LabelInf.Rows.Count; i++)
-                {
-                    SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
-                    if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
-                    {
-                        //如果不存在中盒号则进行添加
-                        if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
-                        {
-                            MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
-                        }
-                    }
-                }
+                //for (int i = 0; i < LabelInf.Rows.Count; i++)
+                //{
+                //    SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
+                //    if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
+                //    {
+                //        //如果不存在中盒号则进行添加
+                //        if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
+                //        {
+                //            MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
+                //        }
+                //    }
+                //}
                 if (SingleID.ToArray().Length == 0)
                 {
                     MessageBox.Show("选择的行未勾选采集或者已打印");
@@ -1239,11 +1262,9 @@ namespace UAS_LabelMachine
                 }
                 //打印的时候如果不存在数据开始缓存
                 if (SingleBoxCacheData.Rows.Count == 0)
-                    GetSingleBoxData();
+                    GetSingleBoxData(la_id);
                 if (MidBoxCacheData.Rows.Count == 0)
-                {
                     GetMidBoxData();
-                }
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
                     if (i + 1 < LabelInf.RowCount)
@@ -1265,10 +1286,6 @@ namespace UAS_LabelMachine
                 //用于判断用户是否勾选了行
                 int CheckedRowCount = 0;
                 string[] arg = SingleBoxArgument.ToArray();
-                //打印所有的选中行
-                DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql  from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
-                //用标签本身的变量作为最外层的循环条件去匹配;
-                dt.Merge(Attach);
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
                     //勾选了并且未打印
@@ -1315,8 +1332,7 @@ namespace UAS_LabelMachine
                                 {
                                     try
                                     {
-                                        SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
-
+                                        SingleDoc.Variables.FreeVariables.Item(j + 1).Value = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
                                     }
                                     catch (Exception)
                                     {
@@ -1369,8 +1385,19 @@ namespace UAS_LabelMachine
         /// <summary>
         /// 缓存单盘的数据
         /// </summary>
-        private void GetSingleBoxData()
+        private void GetSingleBoxData(string la_id)
         {
+            if (SingleDoc == null)
+                return;
+            for (int i = 0; i < LabelInf.Rows.Count; i++)
+            {
+                SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
+                //如果不存在中盒号则进行添加
+                if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
+                {
+                    MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
+                }
+            }
             //id数组
             string[] pib_id_arr = SingleID.ToArray();
             //将所有的列存在在这里
@@ -1384,14 +1411,14 @@ namespace UAS_LabelMachine
             for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
             {
                 //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < dt.Rows.Count; k++)
+                for (int k = 0; k < SingleLabelParam.Rows.Count; k++)
                 {
-                    if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
+                    if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == SingleLabelParam.Rows[k]["lp_name"].ToString())
                     {
                         DataColumn dc = new DataColumn(SingleDoc.Variables.FreeVariables.Item(j + 1).Name);
                         SingleBoxCacheData.Columns.Add(dc);
                         SingleBoxArgument.Add(SingleDoc.Variables.FreeVariables.Item(j + 1).Name);
-                        string sql = dt.Rows[k]["lp_sql"].ToString();
+                        string sql = SingleLabelParam.Rows[k]["lp_sql"].ToString();
                         sql = sql.Substring(0, sql.IndexOf("{"));
                         sql = sql.Substring(0, sql.LastIndexOf("="));
                         DataTable temp = dh.getFieldsDatasByCondition(sql.Replace(" from ", " ,pib_id PIBID from ") + " in (select pib_id from PRODIOBARCODE where pib_inoutno='" + pi_inoutno.Text + "') ORDER by pib_id");
@@ -1421,8 +1448,18 @@ namespace UAS_LabelMachine
         /// </summary>
         private void GetMidBoxData()
         {
+            if (MidDoc == null)
+                return;
             StringBuilder pib_condition_string = new StringBuilder();
             StringBuilder pib_qtycondition_string = new StringBuilder();
+            for (int i = 0; i < LabelInf.Rows.Count; i++)
+            {
+                //如果不存在中盒号则进行添加
+                if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
+                {
+                    MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
+                }
+            }
             //id数组
             string[] pib_id_arr = MidIDAndOutboxcode.Keys.ToArray();
             string[] pib_outbox_arr = MidIDAndOutboxcode.Values.ToArray();
@@ -1449,18 +1486,17 @@ namespace UAS_LabelMachine
                 return;
             }
             string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
-            DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
             for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
             {
                 //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < dt.Rows.Count; k++)
+                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
                 {
-                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
+                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == MidLabelParam.Rows[k]["lp_name"].ToString())
                     {
                         DataColumn dc = new DataColumn(MidDoc.Variables.FreeVariables.Item(j + 1).Name);
                         MidBoxCacheData.Columns.Add(dc);
                         MidBoxArgument.Add(MidDoc.Variables.FreeVariables.Item(j + 1).Name);
-                        string sql = dt.Rows[k]["lp_sql"].ToString();
+                        string sql = MidLabelParam.Rows[k]["lp_sql"].ToString();
                         //如果打印的含有数量
                         if (sql.ToLower().Contains("pib_qty"))
                         {
@@ -1739,16 +1775,16 @@ namespace UAS_LabelMachine
             for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
             {
                 //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < dt.Rows.Count; k++)
+                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
                 {
                     //名称相等的时候,取SQL进行值的查询
-                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
+                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == MidLabelParam.Rows[k]["lp_name"].ToString())
                     {
                         //获取对应行的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
-                        string sql = dt.Rows[k]["lp_sql"].ToString();
+                        string sql = MidLabelParam.Rows[k]["lp_sql"].ToString();
                         try
                         {
                             //获取打印执行的SQL
@@ -1786,7 +1822,7 @@ namespace UAS_LabelMachine
                                 {
                                     try
                                     {
-                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
                                     }
                                     catch (Exception)
                                     {
@@ -1811,23 +1847,19 @@ namespace UAS_LabelMachine
 
         private void MidBoxCodePrint(string la_id, int rowindex, int[] midindex)
         {
-            DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
-            DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql  from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
-            //用标签本身的变量作为最外层的循环条件去匹配;
-            dt.Merge(Attach);
             for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
             {
                 //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < dt.Rows.Count; k++)
+                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
                 {
                     //名称相等的时候,取SQL进行值的查询
-                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
+                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == MidLabelParam.Rows[k]["lp_name"].ToString())
                     {
                         //获取对应行的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
-                        string sql = dt.Rows[k]["lp_sql"].ToString();
+                        string sql = MidLabelParam.Rows[k]["lp_sql"].ToString();
                         try
                         {
                             //获取打印执行的SQL
@@ -1872,7 +1904,7 @@ namespace UAS_LabelMachine
                                 {
                                     try
                                     {
-                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
                                     }
                                     catch (Exception)
                                     {
@@ -1909,18 +1941,18 @@ namespace UAS_LabelMachine
                 for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
                 {
                     //将维护的模板参数和模板本身的参数名称进行比对
-                    for (int k = 0; k < dt.Rows.Count; k++)
+                    for (int k = 0; k < OutLabelParam.Rows.Count; k++)
                     {
                         //名称相等的时候,取SQL进行值的查询
-                        if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
+                        if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == OutLabelParam.Rows[k]["lp_name"].ToString())
                         {
                             //如果毛重填写的是毛重或者净重
-                            if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "GW")
+                            if (OutLabelParam.Rows[k]["lp_valuetype"].ToString() == "字符串" && OutLabelParam.Rows[k]["lp_sql"].ToString() == "GW")
                             {
                                 OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightGross.Text;
                                 LogManager.DoLog("打印参数【毛重】赋值," + WeightGross.Text);
                             }
-                            else if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "NW")
+                            else if (OutLabelParam.Rows[k]["lp_valuetype"].ToString() == "字符串" && OutLabelParam.Rows[k]["lp_sql"].ToString() == "NW")
                             {
                                 OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightNet.Text;
                                 LogManager.DoLog("打印参数【净重】赋值," + WeightNet.Text);
@@ -1931,7 +1963,7 @@ namespace UAS_LabelMachine
                                 string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
                                 string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
                                 //获取打印执行的SQL
-                                string sql = dt.Rows[k]["lp_sql"].ToString();
+                                string sql = OutLabelParam.Rows[k]["lp_sql"].ToString();
                                 //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
                                 try
                                 {
@@ -1956,7 +1988,7 @@ namespace UAS_LabelMachine
                                     {
                                         try
                                         {
-                                            OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                            OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
                                         }
                                         catch (Exception)
                                         {