Browse Source

打印时取消任务后重新打印不会再去从数据库取数据,会继续从之前的缓存数据中查询

章政 8 years ago
parent
commit
53832ee725

+ 24 - 24
UAS-出货标签管理/UAS_出货标签管理.Designer.cs

@@ -782,7 +782,7 @@
             // 
             this.Capacity.AutoSize = true;
             this.Capacity.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Capacity.Location = new System.Drawing.Point(80, 80);
+            this.Capacity.Location = new System.Drawing.Point(80, 79);
             this.Capacity.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.Capacity.Name = "Capacity";
             this.Capacity.Size = new System.Drawing.Size(0, 20);
@@ -792,7 +792,7 @@
             // 
             this.Process_midboxcode.AutoSize = true;
             this.Process_midboxcode.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Process_midboxcode.Location = new System.Drawing.Point(80, 135);
+            this.Process_midboxcode.Location = new System.Drawing.Point(80, 134);
             this.Process_midboxcode.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.Process_midboxcode.Name = "Process_midboxcode";
             this.Process_midboxcode.Size = new System.Drawing.Size(18, 20);
@@ -803,7 +803,7 @@
             // 
             this.Process_outboxcode.AutoSize = true;
             this.Process_outboxcode.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Process_outboxcode.Location = new System.Drawing.Point(80, 105);
+            this.Process_outboxcode.Location = new System.Drawing.Point(80, 104);
             this.Process_outboxcode.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.Process_outboxcode.Name = "Process_outboxcode";
             this.Process_outboxcode.Size = new System.Drawing.Size(18, 20);
@@ -815,7 +815,7 @@
             this.TotalCount.AutoSize = true;
             this.TotalCount.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.TotalCount.ForeColor = System.Drawing.Color.Blue;
-            this.TotalCount.Location = new System.Drawing.Point(125, 20);
+            this.TotalCount.Location = new System.Drawing.Point(125, 19);
             this.TotalCount.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.TotalCount.Name = "TotalCount";
             this.TotalCount.Size = new System.Drawing.Size(18, 20);
@@ -826,7 +826,7 @@
             // 
             this.label17.AutoSize = true;
             this.label17.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label17.Location = new System.Drawing.Point(108, 20);
+            this.label17.Location = new System.Drawing.Point(108, 19);
             this.label17.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label17.Name = "label17";
             this.label17.Size = new System.Drawing.Size(15, 20);
@@ -838,7 +838,7 @@
             this.CollectedCount.AutoSize = true;
             this.CollectedCount.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.CollectedCount.ForeColor = System.Drawing.Color.Red;
-            this.CollectedCount.Location = new System.Drawing.Point(84, 20);
+            this.CollectedCount.Location = new System.Drawing.Point(84, 19);
             this.CollectedCount.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.CollectedCount.Name = "CollectedCount";
             this.CollectedCount.Size = new System.Drawing.Size(18, 20);
@@ -849,7 +849,7 @@
             // 
             this.label14.AutoSize = true;
             this.label14.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label14.Location = new System.Drawing.Point(13, 106);
+            this.label14.Location = new System.Drawing.Point(13, 105);
             this.label14.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label14.Name = "label14";
             this.label14.Size = new System.Drawing.Size(39, 20);
@@ -860,7 +860,7 @@
             // 
             this.label11.AutoSize = true;
             this.label11.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label11.Location = new System.Drawing.Point(13, 135);
+            this.label11.Location = new System.Drawing.Point(13, 134);
             this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label11.Name = "label11";
             this.label11.Size = new System.Drawing.Size(39, 20);
@@ -871,7 +871,7 @@
             // 
             this.label13.AutoSize = true;
             this.label13.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label13.Location = new System.Drawing.Point(13, 55);
+            this.label13.Location = new System.Drawing.Point(13, 54);
             this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label13.Name = "label13";
             this.label13.Size = new System.Drawing.Size(54, 20);
@@ -882,7 +882,7 @@
             // 
             this.Installed.AutoSize = true;
             this.Installed.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Installed.Location = new System.Drawing.Point(80, 55);
+            this.Installed.Location = new System.Drawing.Point(80, 54);
             this.Installed.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.Installed.Name = "Installed";
             this.Installed.Size = new System.Drawing.Size(0, 20);
@@ -892,7 +892,7 @@
             // 
             this.Process.AutoSize = true;
             this.Process.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Process.Location = new System.Drawing.Point(13, 20);
+            this.Process.Location = new System.Drawing.Point(13, 19);
             this.Process.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.Process.Name = "Process";
             this.Process.Size = new System.Drawing.Size(54, 20);
@@ -1178,7 +1178,7 @@
             // 
             this.ViVoPlate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
             this.ViVoPlate.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ViVoPlate.Location = new System.Drawing.Point(94, 204);
+            this.ViVoPlate.Location = new System.Drawing.Point(102, 203);
             this.ViVoPlate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.ViVoPlate.Name = "ViVoPlate";
             this.ViVoPlate.Size = new System.Drawing.Size(91, 33);
@@ -1200,7 +1200,7 @@
             // 
             this.SingleLabelPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
             this.SingleLabelPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.SingleLabelPrint.Location = new System.Drawing.Point(94, 251);
+            this.SingleLabelPrint.Location = new System.Drawing.Point(102, 250);
             this.SingleLabelPrint.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.SingleLabelPrint.Name = "SingleLabelPrint";
             this.SingleLabelPrint.Size = new System.Drawing.Size(91, 33);
@@ -1213,7 +1213,7 @@
             // 
             this.SingleLabelAutoPrint.AutoSize = true;
             this.SingleLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.SingleLabelAutoPrint.Location = new System.Drawing.Point(9, 138);
+            this.SingleLabelAutoPrint.Location = new System.Drawing.Point(9, 137);
             this.SingleLabelAutoPrint.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.SingleLabelAutoPrint.Name = "SingleLabelAutoPrint";
             this.SingleLabelAutoPrint.Size = new System.Drawing.Size(91, 24);
@@ -1271,7 +1271,7 @@
             // 
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label5.Location = new System.Drawing.Point(8, 206);
+            this.label5.Location = new System.Drawing.Point(8, 205);
             this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(39, 20);
@@ -1282,7 +1282,7 @@
             // 
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label4.Location = new System.Drawing.Point(7, 168);
+            this.label4.Location = new System.Drawing.Point(7, 167);
             this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label4.Name = "label4";
             this.label4.Size = new System.Drawing.Size(39, 20);
@@ -1302,7 +1302,7 @@
             // 
             this.label15.AutoSize = true;
             this.label15.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label15.Location = new System.Drawing.Point(119, 170);
+            this.label15.Location = new System.Drawing.Point(119, 169);
             this.label15.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label15.Name = "label15";
             this.label15.Size = new System.Drawing.Size(24, 20);
@@ -1334,7 +1334,7 @@
             // 
             this.MidLabelAutoPrint.AutoSize = true;
             this.MidLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.MidLabelAutoPrint.Location = new System.Drawing.Point(12, 138);
+            this.MidLabelAutoPrint.Location = new System.Drawing.Point(12, 137);
             this.MidLabelAutoPrint.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.MidLabelAutoPrint.Name = "MidLabelAutoPrint";
             this.MidLabelAutoPrint.Size = new System.Drawing.Size(91, 24);
@@ -1384,7 +1384,7 @@
             // LogingOut
             // 
             this.LogingOut.AutoSize = true;
-            this.LogingOut.Location = new System.Drawing.Point(166, 7);
+            this.LogingOut.Location = new System.Drawing.Point(166, 6);
             this.LogingOut.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.LogingOut.Name = "LogingOut";
             this.LogingOut.Size = new System.Drawing.Size(52, 27);
@@ -1422,7 +1422,7 @@
             // 
             this.label10.AutoSize = true;
             this.label10.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label10.Location = new System.Drawing.Point(11, 210);
+            this.label10.Location = new System.Drawing.Point(11, 209);
             this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label10.Name = "label10";
             this.label10.Size = new System.Drawing.Size(39, 20);
@@ -1446,7 +1446,7 @@
             // 
             this.label9.AutoSize = true;
             this.label9.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label9.Location = new System.Drawing.Point(120, 250);
+            this.label9.Location = new System.Drawing.Point(120, 249);
             this.label9.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label9.Name = "label9";
             this.label9.Size = new System.Drawing.Size(39, 20);
@@ -1470,7 +1470,7 @@
             // 
             this.label8.AutoSize = true;
             this.label8.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label8.Location = new System.Drawing.Point(11, 250);
+            this.label8.Location = new System.Drawing.Point(11, 249);
             this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label8.Name = "label8";
             this.label8.Size = new System.Drawing.Size(39, 20);
@@ -1481,7 +1481,7 @@
             // 
             this.label6.AutoSize = true;
             this.label6.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label6.Location = new System.Drawing.Point(8, 166);
+            this.label6.Location = new System.Drawing.Point(8, 165);
             this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label6.Name = "label6";
             this.label6.Size = new System.Drawing.Size(39, 20);
@@ -1539,7 +1539,7 @@
             // 
             this.OutBoxLabelAutoPrint.AutoSize = true;
             this.OutBoxLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.OutBoxLabelAutoPrint.Location = new System.Drawing.Point(12, 126);
+            this.OutBoxLabelAutoPrint.Location = new System.Drawing.Point(10, 135);
             this.OutBoxLabelAutoPrint.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.OutBoxLabelAutoPrint.Name = "OutBoxLabelAutoPrint";
             this.OutBoxLabelAutoPrint.Size = new System.Drawing.Size(91, 24);

+ 130 - 99
UAS-出货标签管理/UAS_出货标签管理.cs

@@ -11,7 +11,6 @@ using LabelManager2;
 using UAS_LabelMachine.PublicMethod;
 using UAS_LabelMachine.Entity;
 using UAS_特殊解析规则;
-using System.Globalization;
 using UAS_LabelMachine.CustomControl.GroupBoxWithBorder;
 using UAS_LabelMachine.PublicForm;
 using System.Threading;
@@ -37,10 +36,6 @@ namespace UAS_LabelMachine
         List<string> PrintedVivoOutboxCode = new List<string>();
         StringBuilder sql = new StringBuilder();
         /// <summary>
-        /// 中盒缓存数据
-        /// </summary>
-        DataTable MidBoxCacheData;
-        /// <summary>
         /// CodeSoft新建打印机引擎
         /// </summary>
         ApplicationClass lbl;
@@ -96,9 +91,29 @@ namespace UAS_LabelMachine
         object[] ItemData;
 
         Dictionary<string, string> CollectData;
-
+        //缓存单盘数据数据的DataTable
+        DataTable SingleBoxCacheData;
+        /// <summary>
+        /// 存放单盘的ID
+        /// </summary>
+        List<string> SingleID = new List<string>();
+        /// <summary>
+        /// 单盘的打印参数
+        /// </summary>
+        List<string> SingleBoxArgument = new List<string>();
+        /// <summary>
+        /// 中盒缓存数据
+        /// </summary>
+        DataTable MidBoxCacheData;
+        /// <summary>
+        /// 存放中盒的ID和盒号
+        /// </summary>
         Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
         /// <summary>
+        /// 中盒的打印参数
+        /// </summary>
+        List<string> MidBoxArgument = new List<string>();
+        /// <summary>
         /// 全部采集
         /// </summary>
         bool AllCollect = false;
@@ -112,7 +127,6 @@ namespace UAS_LabelMachine
         bool GetPackingCode = false;
         /*用于存放采集项目的Grid信息*/
         Dictionary<string, Dictionary<string, string>> SiItem;
-
         int CloumnCount = 0;
         /*需要重绘的Cell*/
         Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
@@ -120,7 +134,7 @@ namespace UAS_LabelMachine
         ArrayList<ArrayList<string>> ScanData;
         ArrayList<string> GetData;
 
-        List<string> MidBoxArgument = new List<string>();
+
 
         public UAS_出货标签打印()
         {
@@ -161,6 +175,7 @@ namespace UAS_LabelMachine
                 PowerSetting.Visible = true;
             }
             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 # 分隔符";
@@ -1068,6 +1083,13 @@ namespace UAS_LabelMachine
                     pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
                     PI_ID = dt.Rows[0]["pi_id"].ToString();
                     LoadGridData(sender, e);
+                    //重新输入单号后清除缓存
+                    MidBoxArgument.Clear();
+                    MidBoxCacheData.Clear();
+                    BaseUtil.CleanDataTable(MidBoxCacheData);
+                    SingleBoxArgument.Clear();
+                    SingleBoxCacheData.Clear();
+                    BaseUtil.CleanDataTable(SingleBoxCacheData);
                     //刷新采集进度
                     RefreshProcessData();
                     //设置当前的最大箱号
@@ -1104,104 +1126,33 @@ namespace UAS_LabelMachine
             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)
             {
-                MidIDAndOutboxcode.Clear(); 
+                //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
+                MidIDAndOutboxcode.Clear();
+                SingleID.Clear();
                 //获取全部的中盒号
                 Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
                 //判断所有盒号为该盒的是否勾选已采集
                 outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
-                List<string> pib_id_list = new List<string>();
                 for (int i = 0; i < LabelInf.Rows.Count; i++)
                 {
                     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")
-                        pib_id_list.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());
+                    {
+                        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());
+                    }  
                 }
-                if (pib_id_list.ToArray().Length == 0)
+                if (SingleID.ToArray().Length == 0)
                 {
                     MessageBox.Show("选择的行未勾选采集或者已打印");
                     return;
                 }
-                //清除结构和数据
-                MidBoxArgument.Clear();
-                MidBoxCacheData.Clear();
-                BaseUtil.CleanDataTable(MidBoxCacheData);
-             
-                //开启一个进程获取中盒的数据
-                GetMidBoxData();
-                StringBuilder pib_id_string = new StringBuilder();
-                //id数组
-                string[] pib_id_arr = pib_id_list.ToArray();
-                //id个数
-                int pib_id_length = pib_id_arr.Length;
-                //将所有的列存在在这里
-                List<DataTable> AllSingleBoxCacheData = new List<DataTable>();
-                List<string> Argument = new List<string>();
-                //每五百条拼接一次条件
-                int fivehundred_count = pib_id_length / 500 + 1;
-                //当前打印的索引
-                int CurrentCount = 0;
-                for (int i = 0; i < fivehundred_count; i++)
-                {
-                    //本次循环的数量
-                    int count = 0;
-                    pib_id_string.Append("(");
-                    if (i + 1 == fivehundred_count)
-                        count = pib_id_length - i * 500;
-                    else
-                        count = 500;
-                    //当前执行的索引
-                    int LastCount = CurrentCount;
-                    for (int j = CurrentCount; j < LastCount + count - 1; j++)
-                    {
-                        pib_id_string.Append(pib_id_arr[j] + ",");
-                        CurrentCount = CurrentCount + 1;
-                    }
-                    pib_id_string.Append(pib_id_arr[CurrentCount]);
-                    pib_id_string.Append(")");
-                    if (i + 1 != fivehundred_count)
-                        pib_id_string.Append(" or pib_id in ");
-                }
-                //缓存数据的DataTable
-                DataTable CacheData = new DataTable();
-                //手动添加ID列
-                DataColumn datacolumn = new DataColumn("pib_id");
-                CacheData.Columns.Add(datacolumn);
-                //获取打印的SQL
-                for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
-                {
-                    //将维护的模板参数和模板本身的参数名称进行比对
-                    for (int k = 0; k < dt.Rows.Count; k++)
-                    {
-                        if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
-                        {
-                            DataColumn dc = new DataColumn(SingleDoc.Variables.FreeVariables.Item(j + 1).Name);
-                            CacheData.Columns.Add(dc);
-                            Argument.Add(SingleDoc.Variables.FreeVariables.Item(j + 1).Name);
-                            string sql = dt.Rows[k]["lp_sql"].ToString();
-                            sql = sql.Substring(0, sql.IndexOf("{"));
-                            sql = sql.Substring(0, sql.LastIndexOf("="));
-                            DataTable temp = dh.getFieldsDatasByCondition(sql + " in " + pib_id_string.ToString());
-                            temp.Columns[0].ColumnName = SingleDoc.Variables.FreeVariables.Item(j + 1).Name;
-                            AllSingleBoxCacheData.Add(temp);
-                        }
-                    }
-                }
-                DataTable[] Temp = AllSingleBoxCacheData.ToArray();
-                //将所有数据写入到CacheData中
-                if (Temp.Length > 0)
-                    for (int i = 0; i < Temp[0].Rows.Count; i++)
-                    {
-                        DataRow dr = CacheData.NewRow();
-                        dr["pib_id"] = pib_id_arr[i];
-                        //由于之前加了一个ID列,导致j从1开始
-                        for (int j = 1; j < CacheData.Columns.Count; j++)
-                        {
-                            dr[Temp[j - 1].Columns[0].ColumnName] = Temp[j - 1].Rows[i][0].ToString();
-                        }
-                        CacheData.Rows.Add(dr);
-                    }
+                //打印的时候如果不存在数据开始缓存
+                if (MidBoxCacheData.Rows.Count == 0)
+                    GetMidBoxData();
+                if (SingleBoxCacheData.Rows.Count == 0)
+                    GetSingleBoxData();
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
                     if (i + 1 < LabelInf.RowCount)
@@ -1222,7 +1173,7 @@ namespace UAS_LabelMachine
                 }
                 //用于判断用户是否勾选了行
                 int CheckedRowCount = 0;
-                string[] arg = Argument.ToArray();
+                string[] arg = SingleBoxArgument.ToArray();
                 //打印所有的选中行
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
@@ -1235,7 +1186,7 @@ namespace UAS_LabelMachine
                         try
                         {
                             string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
-                            DataRow[] dr = CacheData.Select("pib_id=" + pib_id);
+                            DataRow[] dr = SingleBoxCacheData.Select("pib_id=" + pib_id);
                             StringBuilder ParamLog = new StringBuilder();
                             for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
                             {
@@ -1263,7 +1214,6 @@ namespace UAS_LabelMachine
                             SingleDoc.Save();
                             SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
                             SingleDoc.PrintDocument();
-                            LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
                             //勾选为已打印
                             LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
                         }
@@ -1299,7 +1249,85 @@ namespace UAS_LabelMachine
         }
 
         /// <summary>
-        /// 获取中盒数据的线程
+        /// 缓存单盘的数据
+        /// </summary>
+        private void GetSingleBoxData()
+        {
+            StringBuilder pib_id_string = new StringBuilder();
+            //id数组
+            string[] pib_id_arr = SingleID.ToArray();
+            //id个数
+            int pib_id_length = pib_id_arr.Length;
+            //将所有的列存在在这里
+            List<DataTable> AllSingleBoxCacheData = new List<DataTable>();
+
+            //每五百条拼接一次条件
+            int fivehundred_count = pib_id_length / 500 + 1;
+            //当前打印的索引
+            int CurrentCount = 0;
+            for (int i = 0; i < fivehundred_count; i++)
+            {
+                //本次循环的数量
+                int count = 0;
+                pib_id_string.Append("(");
+                if (i + 1 == fivehundred_count)
+                    count = pib_id_length - i * 500;
+                else
+                    count = 500;
+                //当前执行的索引
+                int LastCount = CurrentCount;
+                for (int j = CurrentCount; j < LastCount + count - 1; j++)
+                {
+                    pib_id_string.Append(pib_id_arr[j] + ",");
+                    CurrentCount = CurrentCount + 1;
+                }
+                pib_id_string.Append(pib_id_arr[CurrentCount]);
+                pib_id_string.Append(")");
+                if (i + 1 != fivehundred_count)
+                    pib_id_string.Append(" or pib_id in ");
+            }
+
+            //手动添加ID列
+            DataColumn datacolumn = new DataColumn("pib_id");
+            SingleBoxCacheData.Columns.Add(datacolumn);
+            //获取打印的SQL
+            for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
+            {
+                //将维护的模板参数和模板本身的参数名称进行比对
+                for (int k = 0; k < dt.Rows.Count; k++)
+                {
+                    if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.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();
+                        sql = sql.Substring(0, sql.IndexOf("{"));
+                        sql = sql.Substring(0, sql.LastIndexOf("="));
+                        DataTable temp = dh.getFieldsDatasByCondition(sql + " in " + pib_id_string.ToString());
+                        temp.Columns[0].ColumnName = SingleDoc.Variables.FreeVariables.Item(j + 1).Name;
+                        AllSingleBoxCacheData.Add(temp);
+                    }
+                }
+            }
+            DataTable[] Temp = AllSingleBoxCacheData.ToArray();
+            //将所有数据写入到CacheData中
+            if (Temp.Length > 0)
+                for (int i = 0; i < Temp[0].Rows.Count; i++)
+                {
+                    DataRow dr = SingleBoxCacheData.NewRow();
+                    dr["pib_id"] = pib_id_arr[i];
+                    //由于之前加了一个ID列,导致j从1开始
+                    for (int j = 1; j < SingleBoxCacheData.Columns.Count; j++)
+                    {
+                        dr[Temp[j - 1].Columns[0].ColumnName] = Temp[j - 1].Rows[i][0].ToString();
+                    }
+                    SingleBoxCacheData.Rows.Add(dr);
+                }
+        }
+
+        /// <summary>
+        /// 缓存中盒的数据
         /// </summary>
         private void GetMidBoxData()
         {
@@ -1365,6 +1393,7 @@ namespace UAS_LabelMachine
                         {
                             sql = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
                             sql = sql.Substring(0, sql.LastIndexOf("=")) + " in " + pib_qtycondition_string.ToString() + sql.Substring(sql.LastIndexOf("}") + 1);
+                            Console.WriteLine(sql);
                         }
                         else
                         {
@@ -1558,6 +1587,7 @@ namespace UAS_LabelMachine
                             else
                             {
                                 DataRow[] dr = MidBoxCacheData.Select("pib_outboxcode1='" + pib_outboxcode1 + "'");
+                                Console.WriteLine(pib_outboxcode1);
                                 if (MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower().Contains("datecode1"))
                                 {
                                     if (LabelInf.Rows[rowindex].Cells["DateCode1"].Value != null)
@@ -1744,7 +1774,8 @@ namespace UAS_LabelMachine
             }
         }
 
-        private void LoadGridData() {
+        private void LoadGridData()
+        {
             LoadGridData(new object(), new EventArgs());
         }