章政 6 years ago
parent
commit
2a9f9c5d89

+ 22 - 1
UAS-出货标签管理(贸易版)/PublicMethod/DataHelper.cs

@@ -940,9 +940,30 @@ namespace UAS_LabelMachine
             command.ArrayBindCount = names[1].Length;
             //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
             //将第一个数组的下标固定为0作为循环添加的参数的名称
+            //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
+            //将第一个数组的下标固定为0作为循环添加的参数的名称
             for (int i = 1; i <= names[0].Length; i++)
             {
-                command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
+                if (names[0][i - 1].ToString().ToUpper().Contains("DATE") && !names[0][i - 1].ToString().ToUpper().Contains("DATECODE"))
+                {
+                    DateTime[] time = new DateTime[names[i].Length];
+                    try
+                    {
+                        for (int j = 0; j < names[i].Length; j++)
+                        {
+                            time[j] = Convert.ToDateTime(names[i][j]);
+                        }
+                        command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Date, time, ParameterDirection.Input));
+                    }
+                    catch (Exception)
+                    {
+                        command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
+                    }
+                }
+                else
+                {
+                    command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
+                }
             }
             command.ExecuteNonQuery();
             command.Dispose();

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

@@ -502,6 +502,7 @@ namespace UAS_LabelMachine
         {
             object result = null;
             command = new SQLiteCommand(SQL, this._odcConnection);
+            Console.WriteLine(SQL);
             Reconnect(command);
             switch (Type.ToUpper())
             {

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

@@ -318,7 +318,7 @@
             this.SaveGrid.Name = "SaveGrid";
             this.SaveGrid.Size = new System.Drawing.Size(68, 26);
             this.SaveGrid.TabIndex = 59;
-            this.SaveGrid.Text = "保存明细";
+            this.SaveGrid.Text = "上传条码";
             this.SaveGrid.UseVisualStyleBackColor = true;
             this.SaveGrid.Click += new System.EventHandler(this.SaveGrid_Click);
             // 

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

@@ -94,7 +94,6 @@ namespace UAS_LabelMachine
 
         Dictionary<string, string> CollectData;
         //缓存单盘数据数据的DataTable
-        DataTable SingleBoxCacheData;
         /// <summary>
         /// 存放单盘的ID
         /// </summary>
@@ -106,7 +105,6 @@ namespace UAS_LabelMachine
         /// <summary>
         /// 中盒缓存数据
         /// </summary>
-        DataTable MidBoxCacheData;
         /// <summary>
         /// 存放中盒的ID和盒号
         /// </summary>
@@ -184,8 +182,6 @@ namespace UAS_LabelMachine
             CloumnCount = LabelInf.Columns.Count;
             pi_inoutno.Focus();
             //将本地读取的打印机设置进Combox,并选中默认打印机
-            MidBoxCacheData = new DataTable();
-            SingleBoxCacheData = new DataTable();
             sg_code.FormName = Name;
             sg_code.SetValueField = new string[] { "sg_code" };
             sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
@@ -297,7 +293,6 @@ namespace UAS_LabelMachine
             DataTable savedt = (LabelInf.DataSource as DataTable);
             if (savedt != null && savedt.GetChanges() != null)
             {
-                MidSource.EndEdit();
                 dh.SaveDataTable(savedt.GetChanges(), "ProdioBarCode", "pib_id");
                 MessageBox.Show("保存成功!");
             }
@@ -370,12 +365,6 @@ namespace UAS_LabelMachine
                     return;
                 }
                 CollectInputData();
-                DataTable savedt = (LabelInf.DataSource as DataTable);
-                if (savedt != null && savedt.GetChanges() != null)
-                {
-                    MidSource.EndEdit();
-                    dh.SaveDataTable(savedt.GetChanges(), "ProdioBarCode", "pib_id");
-                }
             }
         }
 
@@ -511,71 +500,75 @@ namespace UAS_LabelMachine
                 if (CollectVeProdCodePass && CollectQTYPass)
                 {
                     //如果按盒号采集,所有的此盒的均更新为
-                    DataTable dt = (DataTable)MidSource.DataSource;
+                    DataTable dt = (DataTable)LabelInf.DataSource;
+                    StringBuilder pibid1 = new StringBuilder();
                     if (CollectionUnit.Text == "盒")
                     {
-                        string la_id = "";
-                        if (SingleLabelCombox.SelectedValue != null)
-                        {
-                            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();
+                        string lotno = "";
+                        string datecode = "";
                         for (int i = 0; i < LabelInf.RowCount; i++)
                         {
                             if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
                             {
-                                dt.Rows[i]["pib_lotno"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
-                                dt.Rows[i]["pib_datecode"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
+                                lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
+                                datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
+                                string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
+                                dt.Rows[i]["pib_lotno"] = lotno;
+                                dt.Rows[i]["pib_datecode"] = datecode;
                                 LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
                                 LabelInf.Rows[i].Cells["Choose"].Value = true;
+                                pibid1.Append(pibid + ",");
                                 LabelInf.Invalidate();
                                 //当前行的索引随循环增长
                                 CurrentRowIndex = i;
                                 if (SingleLabelAutoPrint.Checked)
                                 {
-                                    if (la_id != "")
-                                        AutoPrintSingleLabel(la_id);
-                                    else
-                                    {
-                                        MessageBox.Show("未维护单盘标签");
-                                        return;
-                                    }
+                                    AutoPrintSingleLabel(pibid);
                                 }
                                 if (MidLabelAutoPrint.Checked)
                                     AutoPrintMidLabel();
                                 SetOutBoxCode2(true);
                             }
                         }
+                        pibid1.Append("1");
+                        sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + pib_datecode + "' where pib_id in (" + pibid1 + ")", "update");
                     }
                     else if (CollectionUnit.Text == "全部")
                     {
+                        string lotno = "";
+                        string datecode = "";
                         for (int i = 0; i < LabelInf.RowCount; i++)
                         {
-                            dt.Rows[i]["pib_lotno"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
-                            dt.Rows[i]["pib_datecode"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
+                            lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
+                            datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
+                            string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
+                            dt.Rows[i]["pib_lotno"] = lotno;
+                            dt.Rows[i]["pib_datecode"] = datecode;
                             CurrentRowIndex = i;
                             LabelInf.Refresh();
                             LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
                             LabelInf.Rows[i].Cells["Choose"].Value = true;
+                            pibid1.Append(pibid + ",");
                             LabelInf.Invalidate();
                             SetOutBoxCode2(true);
                         }
+                        pibid1.Append("1");
+                        sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + pib_datecode + "' where pib_id in (" + pibid1 + ")", "update");
                     }
                     else
                     {
+                        string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
+                        string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
                         LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
+                        sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + pib_datecode + "' where pib_id in (" + pibid1 + ")", "update");
                         LabelInf.Invalidate();
                         //勾选了单盘自动打印
                         if (SingleLabelAutoPrint.Checked)
                         {
                             if (SingleLabelCombox.SelectedValue != null)
                             {
-                                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();
-                                AutoPrintSingleLabel(la_id);
+                                AutoPrintSingleLabel(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
                             }
                             else
                             {
@@ -805,7 +798,7 @@ namespace UAS_LabelMachine
                         string MatchResult = "";
                         if (kind != "MPN" && kind != "QTY" && kind != "品牌")
                         {
-                            DataTable dt = (DataTable)MidSource.DataSource;
+                            DataTable dt = (DataTable)LabelInf.DataSource;
                             cell.Value = Matchstr;
                             MatchResult = "成功";
                         }
@@ -1010,7 +1003,7 @@ namespace UAS_LabelMachine
             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 = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
                 for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
                 {
                     SingleParam.Add(SingleDoc.Variables.FreeVariables.Item(i + 1).Name);
@@ -1039,7 +1032,7 @@ namespace UAS_LabelMachine
             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 = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
             }
             //缓存中盒参数
             sql.Clear();
@@ -1096,11 +1089,7 @@ namespace UAS_LabelMachine
                     LoadGridData(sender, e);
                     //重新输入单号后清除缓存
                     MidBoxArgument.Clear();
-                    MidBoxCacheData.Clear();
-                    BaseUtil.CleanDataTable(MidBoxCacheData);
                     SingleBoxArgument.Clear();
-                    SingleBoxCacheData.Clear();
-                    BaseUtil.CleanDataTable(SingleBoxCacheData);
                     MidIDAndOutboxcode.Clear();
                     SingleID.Clear();
                     //刷新采集进度
@@ -1220,8 +1209,7 @@ namespace UAS_LabelMachine
                                     {
                                         if (MidLabelCombox.SelectedValue != null)
                                         {
-                                            string la_id_mid = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
-                                            MidBoxCodePrint(la_id_mid, CurrentRowIndex);
+                                            MidBoxCodePrint(CurrentRowIndex);
                                         }
                                     }
                                 }
@@ -1233,8 +1221,6 @@ namespace UAS_LabelMachine
                     }
                 }
                 dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
-                MidBoxCacheData.Clear();
-                BaseUtil.CleanDataTable(MidBoxCacheData);
                 if (CheckedRowCount == 0)
                     MessageBox.Show("未勾选打印明细!");
                 else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
@@ -1332,11 +1318,8 @@ namespace UAS_LabelMachine
                     }
                 }
                 MidBoxArgument.Clear();
-                MidBoxCacheData.Clear();
-                BaseUtil.CleanDataTable(MidBoxCacheData);
                 List<int> MidOutBoxCode = new List<int>();
                 List<int> MidOutBoxCodeIndex = new List<int>();
-                string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
                 for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
                 {
                     if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
@@ -1349,19 +1332,14 @@ namespace UAS_LabelMachine
                 }
                 for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
                 {
-                    MidBoxCodePrint(la_id, MidOutBoxCodeIndex[i]);
+                    MidBoxCodePrint(MidOutBoxCodeIndex[i]);
                 }
                 MidBoxArgument.Clear();
-                MidBoxCacheData.Clear();
-                BaseUtil.CleanDataTable(MidBoxCacheData);
                 return;
             }
             bool FindMidLabel = false;
             if (MidLabelCombox.SelectedValue != null)
             {
-                string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
-                string cl_labelname = MidLabelCombox.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();
                 //中盒号所在的行
                 int MidLabelRowIndex = 0;
                 //查找是否存在该中盒号
@@ -1379,7 +1357,7 @@ namespace UAS_LabelMachine
                 }
                 //找到了指定的盒号
                 if (FindMidLabel)
-                    MidBoxCodePrint(la_id, MidLabelRowIndex, MidRowIndex.ToArray());
+                    MidBoxCodePrint(MidLabelRowIndex);
                 else
                     MessageBox.Show("该出入库单未找到该中盒号!");
             }
@@ -1404,9 +1382,6 @@ namespace UAS_LabelMachine
         {
             List<string> Outboxcode = new List<string>();
             //如果未勾选箱号则对勾选的数据的箱号进行整合
-            string la_id = OutBoxCombox.SelectedValue.ToString().Split('#')[0];
-            string cl_labelname = OutBoxCombox.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();
             if (OutBoxNum.Text == "")
             {
                 for (int i = 0; i < LabelInf.RowCount; i++)
@@ -1432,7 +1407,7 @@ namespace UAS_LabelMachine
                             {
                                 if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
                                 {
-                                    OutBoxCodePrint(la_id, h);
+                                    OutBoxCodePrint(h);
                                     break;
                                 }
                             }
@@ -1464,7 +1439,7 @@ namespace UAS_LabelMachine
                     }
                     //找到了指定的盒号
                     if (FindMidLabel)
-                        OutBoxCodePrint(la_id, OutBoxLabelRowIndex);
+                        OutBoxCodePrint(OutBoxLabelRowIndex);
                     else
                         MessageBox.Show("该出入库单未找到该外箱号!");
                 }
@@ -1473,186 +1448,137 @@ namespace UAS_LabelMachine
             Outboxcode.Clear();
         }
 
-        private void MidBoxCodePrint(string la_id, int rowindex)
+        private void MidBoxCodePrint(int rowindex)
         {
-            if (MidBoxCacheData.Rows.Count == 0)
+            //获取对应行的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();
+
+            //查询参数名称相同的获取到取值字段
+            for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
             {
-                MidIDAndOutboxcode.Add(LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString());
+                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() + ",");
+                }
             }
-            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");
-            string[] arg = MidBoxArgument.ToArray();
-            for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
+            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++)
             {
-                //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
+                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() == "字符串")
                 {
-                    //名称相等的时候,取SQL进行值的查询
-                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == MidLabelParam.Rows[k]["lp_name"].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++)
                     {
-                        //获取对应行的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 = MidLabelParam.Rows[k]["lp_sql"].ToString();
-                        try
+                        for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++)
                         {
-                            //获取打印执行的SQL
-                            if (sql.IndexOf("{") == 0)
+                            if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
                             {
-                                MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
-                                LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
+                                MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
                             }
-                            else
+                            //使用SN开头的参数赋值SN1,SN2,SN3等参数
+                            if (MidDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
                             {
-                                DataRow[] dr = MidBoxCacheData.Select("pib_outboxcode1='" + pib_outboxcode1 + "'");
-                                if (arg.Contains(MidDoc.Variables.FreeVariables.Item(j + 1).Name))
-                                {
-                                    if (dr.Length > 0)
-                                    {
-                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = dr[0][MidDoc.Variables.FreeVariables.Item(j + 1).Name].ToString();
-                                    }
-                                }
-                                if (MidDoc.Variables.FreeVariables.Item(j + 1).Value == "")
-                                {
-                                    DataRow[] dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'");
-                                    if (dr1.Length > 0)
-                                    {
-                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
-                                    }
-                                }
-                                LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
+                                MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
                             }
                         }
-                        catch (Exception)
-                        {
-                            LogManager.DoLog("SQL维护不正确,请检查SQL语句\n" + sql);
-                            return;
-                        }
                     }
                 }
+                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 MidBoxCodePrint(string la_id, int rowindex, int[] midindex)
+        private void OutBoxCodePrint(int rowindex)
         {
-            for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
+            //获取对应行的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++)
             {
-                //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
+                DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
+                if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
                 {
-                    //名称相等的时候,取SQL进行值的查询
-                    if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == MidLabelParam.Rows[k]["lp_name"].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() == "字符串")
                     {
-                        //获取对应行的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 = MidLabelParam.Rows[k]["lp_sql"].ToString();
-                        try
+                        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++)
                         {
-                            //获取打印执行的SQL
-                            if (sql.IndexOf("{") == 0)
-                            {
-                                MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
-                                LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
-                            }
-                            else
+                            for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++)
                             {
-                                if (sql.ToLower().Contains("pib_qty"))
+                                if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
                                 {
-                                    sql = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
-                                    sql = sql.Substring(0, sql.LastIndexOf("=")) + "='" + pib_outboxcode1 + "' group by pib_outboxcode1";
+                                    OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
                                 }
-                                else
+                                //使用SN开头的参数赋值SN1,SN2,SN3等参数
+                                if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
                                 {
-                                    sql = sql.Substring(0, sql.IndexOf("{"));
-                                    sql = sql.Substring(0, sql.LastIndexOf("="));
-                                    sql = sql + " in (select distinct pib_outboxcode1 from PRODIOBARCODE where pib_inoutno='" + pi_inoutno.Text + "')" + " and pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'";
+                                    OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
                                 }
-                                MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
-                                if (MidDoc.Variables.FreeVariables.Item(j + 1).Value == "")
+                                if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
                                 {
-                                    DataRow[] dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'");
-                                    if (dr1.Length > 0)
-                                    {
-                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
-                                    }
+                                    string date = dt1.Rows[0][0].ToString();
                                 }
-                                LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
                             }
                         }
-                        catch (Exception)
-                        {
-                            LogManager.DoLog("SQL维护不正确,请检查SQL语句\n" + sql);
-                            return;
-                        }
                     }
-                }
-            }
-            MidDoc.PrintDocument();
-        }
-
-        /// <summary>
-        /// 执行打印外箱号
-        /// </summary>
-        private void OutBoxCodePrint(string la_id, int rowindex)
-        {
-            DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
-            try
-            {
-                for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
-                {
-                    //将维护的模板参数和模板本身的参数名称进行比对
-                    for (int k = 0; k < OutLabelParam.Rows.Count; k++)
+                    if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "")
                     {
-                        //名称相等的时候,取SQL进行值的查询
-                        if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == OutLabelParam.Rows[k]["lp_name"].ToString())
-                        {
-                            //获取对应行的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
-                            string sql = OutLabelParam.Rows[k]["lp_sql"].ToString();
-                            //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
-                            try
-                            {
-                                string ExeSQL = "";
-                                ExeSQL = sql.ToLower().Replace("{pib_id}", "'" + pib_id + "'");
-                                ExeSQL = ExeSQL.Replace("{pib_outboxcode2}", "'" + pib_outboxcode2 + "'");
-                                OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
-                                if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value == "")
-                                {
-                                    DataRow[] dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "'");
-                                    if (dr1.Length > 0)
-                                    {
-                                        OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
-                                    }
-                                }
-                                LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value);
-                            }
-                            catch (Exception)
-                            {
-                                LogManager.DoLog("SQL维护不正确,请检查SQL语句" + sql);
-                                MessageBox.Show("SQL维护不正确,请检查SQL语句\n" + sql);
-                                return;
-                            }
-                        }
+                        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();
-                LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString());
             }
-            catch (Exception ex) { MessageBox.Show(ex.Message); }
         }
 
         private void CleanDetail_Click(object sender, EventArgs e)
         {
             ArrayList<string> DeleteID = new ArrayList<string>();
+            StringBuilder pibid = new StringBuilder();
             for (int i = 0; i < LabelInf.RowCount; i++)
             {
                 if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
+                {
                     DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
+                    pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",");
+                }
             }
             //勾选了删除的明细之后
             if (DeleteID.ToArray().Length > 0)
@@ -1660,6 +1586,8 @@ namespace UAS_LabelMachine
                 string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
                 if (close.ToString() == "Yes")
                 {
+                    pibid.Append("1");
+                    sdh.ExecuteSql("delete from prodiobarcode where pib_id in(" + pibid + ")", "delete");
                     dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
                     MessageBox.Show("删除成功");
                     LoadGridData(sender, e);
@@ -1899,8 +1827,7 @@ namespace UAS_LabelMachine
             {
                 if (MidLabelCombox.SelectedValue != null)
                 {
-                    string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
-                    MidBoxCodePrint(la_id, CurrentRowIndex);
+                    MidBoxCodePrint(CurrentRowIndex);
                 }
                 else
                     MessageBox.Show("未维护中盒模板");
@@ -2110,24 +2037,31 @@ namespace UAS_LabelMachine
 
         private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
         {
+            StringBuilder pibid = new StringBuilder();
+            string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
             if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "盒")
             {
-                string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
+
                 string midbox = LabelInf.Rows[e.RowIndex].Cells["pib_outboxcode1"].Value.ToString();
                 for (int i = 0; i < LabelInf.Rows.Count; i++)
                 {
                     if (midbox == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
+                    {
                         LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
+                        pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
+                    }
                 }
             }
             if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "全部")
             {
-                string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
                 for (int i = 0; i < LabelInf.Rows.Count; i++)
                 {
                     LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
+                    pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
                 }
             }
+            pibid.Append("1");
+            sdh.ExecuteSql("update prodiobarcode set pib_madein='" + madein + "' where pib_id in (" + pibid + ")", "update");
         }
 
         private void ExportData_Click(object sender, EventArgs e)
@@ -2137,7 +2071,7 @@ namespace UAS_LabelMachine
             if (result == DialogResult.OK)
             {
                 ExcelHandler eh = new ExcelHandler();
-                DataTable dt = ((DataTable)MidSource.DataSource).Copy();
+                DataTable dt = ((DataTable)LabelInf.DataSource).Copy();
                 for (int i = dt.Columns.Count - 1; i >= 0; i--)
                 {
                     for (int j = 0; j < LabelInf.Columns.Count; j++)