Browse Source

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

Hcsy 7 years ago
parent
commit
d04e7dc82c

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

@@ -28,6 +28,7 @@
         /// </summary>
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UAS_出货标签打印));
             this.pi_inoutno_label = new System.Windows.Forms.Label();
             this.label1 = new System.Windows.Forms.Label();
@@ -61,7 +62,7 @@
             this.CleanInputAfterCollect = new System.Windows.Forms.CheckBox();
             this.AllCollected = new System.Windows.Forms.Button();
             this.PowerSetting = new System.Windows.Forms.Button();
-            this.RefreshDBConnect = new System.Windows.Forms.Timer();
+            this.RefreshDBConnect = new System.Windows.Forms.Timer(this.components);
             this.GetGridOnly = new System.Windows.Forms.CheckBox();
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -89,12 +90,17 @@
             this.dataGridViewTextBoxColumn21 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.dataGridViewTextBoxColumn22 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.dataGridViewTextBoxColumn23 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.MidSource = new System.Windows.Forms.BindingSource();
+            this.MidSource = new System.Windows.Forms.BindingSource(this.components);
             this.ChooseAll = new System.Windows.Forms.Button();
             this.ExportFileDialog = new System.Windows.Forms.FolderBrowserDialog();
             this.AttachInfo = new System.Windows.Forms.Button();
             this.pi_date = new System.Windows.Forms.Label();
+            this.label19 = new System.Windows.Forms.Label();
+            this.GridPrcode = new UAS_LabelMachine.CustomControl.DataGridViewWithSerialNum();
+            this.pd_prodcode = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.groupBoxWithBorder1 = new UAS_LabelMachine.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder();
+            this.SetPrintStatus_label = new System.Windows.Forms.Label();
+            this.SetPrintStatus = new System.Windows.Forms.Button();
             this.ExportData = new System.Windows.Forms.Button();
             this.label18 = new System.Windows.Forms.Label();
             this.MidBoxEnd = new UAS_LabelMachine.CustomControl.EnterTextBox();
@@ -184,6 +190,7 @@
             this.OutBoxCombox = new System.Windows.Forms.ComboBox();
             ((System.ComponentModel.ISupportInitialize)(this.Si_ItemDGV)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MidSource)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.GridPrcode)).BeginInit();
             this.groupBoxWithBorder1.SuspendLayout();
             this.CollectionProcess.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.LabelInf)).BeginInit();
@@ -488,7 +495,7 @@
             // 
             this.label3.AutoSize = true;
             this.label3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label3.Location = new System.Drawing.Point(2, 582);
+            this.label3.Location = new System.Drawing.Point(276, 587);
             this.label3.Name = "label3";
             this.label3.Size = new System.Drawing.Size(74, 21);
             this.label3.TabIndex = 29;
@@ -531,10 +538,6 @@
             this.PowerSetting.Visible = false;
             this.PowerSetting.Click += new System.EventHandler(this.PowerSetting_Click);
             // 
-            // RefreshDBConnect
-            // 
-            this.RefreshDBConnect.Tick += new System.EventHandler(this.RefreshDBConnect_Tick);
-            // 
             // GetGridOnly
             // 
             this.GetGridOnly.AutoSize = true;
@@ -786,8 +789,43 @@
             this.pi_date.TabIndex = 86;
             this.pi_date.Visible = false;
             // 
+            // label19
+            // 
+            this.label19.AutoSize = true;
+            this.label19.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label19.Location = new System.Drawing.Point(4, 584);
+            this.label19.Name = "label19";
+            this.label19.Size = new System.Drawing.Size(74, 21);
+            this.label19.TabIndex = 87;
+            this.label19.Text = "物料资料";
+            // 
+            // GridPrcode
+            // 
+            this.GridPrcode.AllowUserToAddRows = false;
+            this.GridPrcode.BackgroundColor = System.Drawing.SystemColors.Control;
+            this.GridPrcode.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.GridPrcode.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+            this.pd_prodcode});
+            this.GridPrcode.GridColor = System.Drawing.SystemColors.Control;
+            this.GridPrcode.Location = new System.Drawing.Point(9, 610);
+            this.GridPrcode.Name = "GridPrcode";
+            this.GridPrcode.ReadOnly = true;
+            this.GridPrcode.RowTemplate.Height = 23;
+            this.GridPrcode.Size = new System.Drawing.Size(263, 97);
+            this.GridPrcode.TabIndex = 88;
+            this.GridPrcode.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.GridPrcode_CellClick);
+            // 
+            // pd_prodcode
+            // 
+            this.pd_prodcode.DataPropertyName = "pib_prodcode";
+            this.pd_prodcode.HeaderText = "物料编号";
+            this.pd_prodcode.Name = "pd_prodcode";
+            this.pd_prodcode.ReadOnly = true;
+            // 
             // groupBoxWithBorder1
             // 
+            this.groupBoxWithBorder1.Controls.Add(this.SetPrintStatus_label);
+            this.groupBoxWithBorder1.Controls.Add(this.SetPrintStatus);
             this.groupBoxWithBorder1.Controls.Add(this.ExportData);
             this.groupBoxWithBorder1.Controls.Add(this.label18);
             this.groupBoxWithBorder1.Controls.Add(this.MidBoxEnd);
@@ -806,11 +844,35 @@
             this.groupBoxWithBorder1.TabStop = false;
             this.groupBoxWithBorder1.Text = " 打印参数设置";
             // 
+            // SetPrintStatus_label
+            // 
+            this.SetPrintStatus_label.AutoSize = true;
+            this.SetPrintStatus_label.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.SetPrintStatus_label.ForeColor = System.Drawing.Color.Green;
+            this.SetPrintStatus_label.Location = new System.Drawing.Point(11, 202);
+            this.SetPrintStatus_label.Name = "SetPrintStatus_label";
+            this.SetPrintStatus_label.Size = new System.Drawing.Size(58, 21);
+            this.SetPrintStatus_label.TabIndex = 76;
+            this.SetPrintStatus_label.Text = "可打印";
+            // 
+            // SetPrintStatus
+            // 
+            this.SetPrintStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.SetPrintStatus.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.SetPrintStatus.Location = new System.Drawing.Point(78, 200);
+            this.SetPrintStatus.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.SetPrintStatus.Name = "SetPrintStatus";
+            this.SetPrintStatus.Size = new System.Drawing.Size(68, 26);
+            this.SetPrintStatus.TabIndex = 92;
+            this.SetPrintStatus.Text = "打印状态";
+            this.SetPrintStatus.UseVisualStyleBackColor = true;
+            this.SetPrintStatus.Click += new System.EventHandler(this.SetPrintStatus_Click);
+            // 
             // ExportData
             // 
             this.ExportData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
             this.ExportData.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ExportData.Location = new System.Drawing.Point(76, 200);
+            this.ExportData.Location = new System.Drawing.Point(78, 165);
             this.ExportData.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.ExportData.Name = "ExportData";
             this.ExportData.Size = new System.Drawing.Size(68, 26);
@@ -823,7 +885,7 @@
             // 
             this.label18.AutoSize = true;
             this.label18.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label18.Location = new System.Drawing.Point(68, 147);
+            this.label18.Location = new System.Drawing.Point(69, 128);
             this.label18.Name = "label18";
             this.label18.Size = new System.Drawing.Size(13, 17);
             this.label18.TabIndex = 90;
@@ -832,7 +894,7 @@
             // MidBoxEnd
             // 
             this.MidBoxEnd.ID = null;
-            this.MidBoxEnd.Location = new System.Drawing.Point(88, 148);
+            this.MidBoxEnd.Location = new System.Drawing.Point(88, 127);
             this.MidBoxEnd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.MidBoxEnd.Name = "MidBoxEnd";
             this.MidBoxEnd.Size = new System.Drawing.Size(50, 21);
@@ -844,7 +906,7 @@
             // MidBoxBegin
             // 
             this.MidBoxBegin.ID = null;
-            this.MidBoxBegin.Location = new System.Drawing.Point(13, 148);
+            this.MidBoxBegin.Location = new System.Drawing.Point(13, 127);
             this.MidBoxBegin.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.MidBoxBegin.Name = "MidBoxBegin";
             this.MidBoxBegin.Size = new System.Drawing.Size(50, 21);
@@ -857,7 +919,7 @@
             // 
             this.label16.AutoSize = true;
             this.label16.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label16.Location = new System.Drawing.Point(67, 74);
+            this.label16.Location = new System.Drawing.Point(68, 55);
             this.label16.Name = "label16";
             this.label16.Size = new System.Drawing.Size(13, 17);
             this.label16.TabIndex = 87;
@@ -866,7 +928,7 @@
             // SingleBoxEnd
             // 
             this.SingleBoxEnd.ID = null;
-            this.SingleBoxEnd.Location = new System.Drawing.Point(87, 75);
+            this.SingleBoxEnd.Location = new System.Drawing.Point(87, 54);
             this.SingleBoxEnd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.SingleBoxEnd.Name = "SingleBoxEnd";
             this.SingleBoxEnd.Size = new System.Drawing.Size(50, 21);
@@ -878,7 +940,7 @@
             // SingleBoxBegin
             // 
             this.SingleBoxBegin.ID = null;
-            this.SingleBoxBegin.Location = new System.Drawing.Point(12, 75);
+            this.SingleBoxBegin.Location = new System.Drawing.Point(12, 54);
             this.SingleBoxBegin.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.SingleBoxBegin.Name = "SingleBoxBegin";
             this.SingleBoxBegin.Size = new System.Drawing.Size(50, 21);
@@ -891,7 +953,7 @@
             // 
             this.label12.AutoSize = true;
             this.label12.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label12.Location = new System.Drawing.Point(12, 111);
+            this.label12.Location = new System.Drawing.Point(12, 94);
             this.label12.Name = "label12";
             this.label12.Size = new System.Drawing.Size(56, 17);
             this.label12.TabIndex = 77;
@@ -901,7 +963,7 @@
             // 
             this.label7.AutoSize = true;
             this.label7.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label7.Location = new System.Drawing.Point(12, 38);
+            this.label7.Location = new System.Drawing.Point(12, 21);
             this.label7.Name = "label7";
             this.label7.Size = new System.Drawing.Size(56, 17);
             this.label7.TabIndex = 76;
@@ -1122,10 +1184,10 @@
             // MessageLog
             // 
             this.MessageLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.MessageLog.Location = new System.Drawing.Point(0, 610);
+            this.MessageLog.Location = new System.Drawing.Point(278, 610);
             this.MessageLog.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.MessageLog.Name = "MessageLog";
-            this.MessageLog.Size = new System.Drawing.Size(1253, 74);
+            this.MessageLog.Size = new System.Drawing.Size(975, 97);
             this.MessageLog.TabIndex = 28;
             this.MessageLog.Text = "";
             // 
@@ -1444,6 +1506,8 @@
             // SingleLabelAutoPrint
             // 
             this.SingleLabelAutoPrint.AutoSize = true;
+            this.SingleLabelAutoPrint.Checked = true;
+            this.SingleLabelAutoPrint.CheckState = System.Windows.Forms.CheckState.Checked;
             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(8, 107);
             this.SingleLabelAutoPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
@@ -1563,6 +1627,8 @@
             // MidLabelAutoPrint
             // 
             this.MidLabelAutoPrint.AutoSize = true;
+            this.MidLabelAutoPrint.Checked = true;
+            this.MidLabelAutoPrint.CheckState = System.Windows.Forms.CheckState.Checked;
             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(9, 106);
             this.MidLabelAutoPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
@@ -1790,7 +1856,9 @@
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(233)))), ((int)(((byte)(206)))));
-            this.ClientSize = new System.Drawing.Size(1257, 686);
+            this.ClientSize = new System.Drawing.Size(1257, 711);
+            this.Controls.Add(this.GridPrcode);
+            this.Controls.Add(this.label19);
             this.Controls.Add(this.pi_date);
             this.Controls.Add(this.AttachInfo);
             this.Controls.Add(this.groupBoxWithBorder1);
@@ -1843,26 +1911,27 @@
             this.SizeChanged += new System.EventHandler(this.贴标机条码打印_SizeChanged);
             ((System.ComponentModel.ISupportInitialize)(this.Si_ItemDGV)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.MidSource)).EndInit();
-            this.groupBoxWithBorder1.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)(this.GridPrcode)).EndInit();
+            this.groupBoxWithBorder1.ResumeLayout(true);
             this.groupBoxWithBorder1.PerformLayout();
-            this.CollectionProcess.ResumeLayout(false);
+            this.CollectionProcess.ResumeLayout(true);
             this.CollectionProcess.PerformLayout();
             ((System.ComponentModel.ISupportInitialize)(this.LabelInf)).EndInit();
-            this.SingleLabel.ResumeLayout(false);
+            this.SingleLabel.ResumeLayout(true);
             this.SingleLabel.PerformLayout();
-            this.MidLabel.ResumeLayout(false);
+            this.MidLabel.ResumeLayout(true);
             this.MidLabel.PerformLayout();
             ((System.ComponentModel.ISupportInitialize)(this.MidBoxCapacity)).EndInit();
-            this.OutBoxLabel.ResumeLayout(false);
+            this.OutBoxLabel.ResumeLayout(true);
             this.OutBoxLabel.PerformLayout();
             ((System.ComponentModel.ISupportInitialize)(this.OutboxCapacity)).EndInit();
-            this.ResumeLayout(false);
+            this.ResumeLayout(true);
             this.PerformLayout();
 
         }
 
         #endregion
-        private UAS_LabelMachine.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder OutBoxLabel;
+        private CustomControl.GroupBoxWithBorder.GroupBoxWithBorder OutBoxLabel;
         private CustomControl.EnterTextBox OutBoxNum;
         private System.Windows.Forms.Label label10;
         private CustomControl.EnterTextBox WeightNet;
@@ -2015,5 +2084,10 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn pr_spec;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode1;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode2;
+        private System.Windows.Forms.Label label19;
+        private CustomControl.DataGridViewWithSerialNum GridPrcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_prodcode;
+        private System.Windows.Forms.Button SetPrintStatus;
+        private System.Windows.Forms.Label SetPrintStatus_label;
     }
 }

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

@@ -15,6 +15,7 @@ using UAS_LabelMachine.PublicForm;
 using System.Threading;
 using System.IO;
 using System.Globalization;
+using System.Threading.Tasks;
 
 namespace UAS_LabelMachine
 {
@@ -86,6 +87,10 @@ namespace UAS_LabelMachine
         //每个不同序号存在的
         object[] ItemData;
 
+        DataTable SingleLabelParam;
+        DataTable MidLabelParam;
+        DataTable OutLabelParam;
+
         Dictionary<string, string> CollectData;
         //缓存单盘数据数据的DataTable
         DataTable SingleBoxCacheData;
@@ -134,6 +139,12 @@ namespace UAS_LabelMachine
         /// </summary>
         bool ComBoxClickChangeLabelDoc = false;
 
+        List<string> SingleParam = new List<string>();
+
+        List<string> MidParam = new List<string>();
+
+        List<string> OutParam = new List<string>();
+
         public UAS_出货标签打印(string Master)
         {
             InitializeComponent();
@@ -159,7 +170,7 @@ namespace UAS_LabelMachine
             }
             //用计时器重置数据库链接
             LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
-            dh = new DataHelper();
+            dh = SystemInf.dh;
             CheckForIllegalCrossThreadCalls = false;
             CloumnCount = LabelInf.Columns.Count;
             pi_inoutno.Focus();
@@ -231,9 +242,15 @@ namespace UAS_LabelMachine
             BaseUtil.SetFormValue(this.Controls, dt);
         }
 
+        //只执行一次窗体自适应
+        bool AutoSized = false;
         private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
         {
-            asc.controlAutoSize(this);
+            if (!AutoSized)
+            {
+                asc.controlAutoSize(this);
+                AutoSized = true;
+            }
         }
 
         private void GenerateBarCode_Click(object sender, EventArgs e)
@@ -294,17 +311,6 @@ namespace UAS_LabelMachine
             }
         }
 
-        private void SaveGridData()
-        {
-            DataTable savedt = (LabelInf.DataSource as DataTable);
-            if (LabelInf.DataSource != null && savedt.GetChanges() != null)
-            {
-                dh.UpDateTableByCondition(savedt, "ProdioBarCode", "pib_id");
-                LoadGridData(new object(), new EventArgs());
-                MessageBox.Show("保存成功!");
-            }
-        }
-
         //放大镜选择后出发的事件
         private void sg_code_UserControlTextChanged(object sender, EventArgs e)
         {
@@ -655,45 +661,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");
             //用标签本身的变量作为最外层的循环条件去匹配;
-            dt.Merge(Attach);
+            string[] arg = SingleBoxArgument.ToArray();
+            StringBuilder ParamLog = new StringBuilder();
             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++)
                 {
                     //名称相等的时候,取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 == 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.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.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.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.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.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();
-                            LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + pib_id + ",取到值" + 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)
+                            {
+
+                            }
+                        }
+                        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")
                     {
@@ -702,10 +721,13 @@ namespace UAS_LabelMachine
                     }
                 }
             }
+            LogManager.DoLog(ParamLog.ToString());
             //保存参数打印
-            SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
-            SingleDoc.PrintDocument();
-            LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
+            if (EnablePrint)
+            {
+                SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
+                SingleDoc.PrintDocument();
+            }
             LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
         }
 
@@ -962,7 +984,7 @@ namespace UAS_LabelMachine
                             else
                                 str = str.Substring(int.Parse(SiItem[item]["si_index"]));
                         }
-                        catch (Exception e) { LogManager.DoLog(e.Message); }
+                        catch (Exception e) { LogManager.DoLog(e.StackTrace); }
                     }
                     break;
                 case "索引字符":
@@ -978,7 +1000,7 @@ namespace UAS_LabelMachine
                                 str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
                         }
                     }
-                    catch (Exception e) { LogManager.DoLog(e.Message); }
+                    catch (Exception e) { LogManager.DoLog(e.StackTrace); }
                     break;
                 case "二次解析":
                     if (SiItem[item]["si_indexstring"] != "")
@@ -1038,6 +1060,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 + "' ");
@@ -1059,7 +1082,15 @@ 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);
+                for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
+                {
+                    SingleParam.Add(SingleDoc.Variables.FreeVariables.Item(i + 1).Name);
+                }
+            }
             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 + "' ");
@@ -1081,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 + "' ");
@@ -1105,8 +1141,12 @@ 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;
+            Parallel.Invoke(GetSingleBoxData, GetMidBoxData);
         }
 
         /// <summary>
@@ -1139,6 +1179,8 @@ namespace UAS_LabelMachine
                     SingleBoxArgument.Clear();
                     SingleBoxCacheData.Clear();
                     BaseUtil.CleanDataTable(SingleBoxCacheData);
+                    MidIDAndOutboxcode.Clear();
+                    SingleID.Clear();
                     //刷新采集进度
                     RefreshProcessData();
                     //设置当前的最大箱号
@@ -1153,6 +1195,7 @@ namespace UAS_LabelMachine
                         //if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
                         //    MaxOutBoxCode = int.Parse(outboxcode);
                     }
+                    LoadPrcodeData();
                     thread = new Thread(GetInOutInfAndLabelFile);
                     stw = new SetLoadingWindow(thread, "正在获取打印标签");
                     BaseUtil.SetFormCenter(stw);
@@ -1192,7 +1235,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();
@@ -1203,7 +1246,8 @@ namespace UAS_LabelMachine
                 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 (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
+                        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")
                     {
                         //如果不存在中盒号则进行添加
@@ -1222,9 +1266,7 @@ namespace UAS_LabelMachine
                 if (SingleBoxCacheData.Rows.Count == 0)
                     GetSingleBoxData();
                 if (MidBoxCacheData.Rows.Count == 0)
-                {
                     GetMidBoxData();
-                }
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
                     if (i + 1 < LabelInf.RowCount)
@@ -1246,10 +1288,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++)
                 {
                     //勾选了并且未打印
@@ -1294,14 +1332,23 @@ namespace UAS_LabelMachine
                                 }
                                 if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
                                 {
-                                    SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                    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)
+                                    {
+
+                                    }
                                 }
                                 ParamLog.AppendLine("pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",SingleDoc打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
                             }
                             LogManager.DoLog(ParamLog.ToString());
                             //保存参数打印
-                            SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
-                            SingleDoc.PrintDocument();
+                            if (EnablePrint) {
+                                SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
+                                SingleDoc.PrintDocument();
+                            }
                             if (MidLabelAutoPrint.Checked)
                             {
                                 //判断当前行的盒号和下一行不相等或者已经是最后一行了
@@ -1344,6 +1391,16 @@ namespace UAS_LabelMachine
         /// </summary>
         private void GetSingleBoxData()
         {
+            if (SingleDoc == null)
+                return;
+            for (int i = 0; i < LabelInf.Rows.Count; i++)
+            {
+                if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].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());
+            }
             //id数组
             string[] pib_id_arr = SingleID.ToArray();
             //将所有的列存在在这里
@@ -1357,14 +1414,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");
@@ -1394,8 +1451,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();
@@ -1422,18 +1489,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"))
                         {
@@ -1712,16 +1778,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
@@ -1755,6 +1821,17 @@ namespace UAS_LabelMachine
                                         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 == "")
+                                {
+                                    try
+                                    {
+                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                    }
+                                    catch (Exception)
+                                    {
+
+                                    }
+                                }
                                 LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
                             }
                         }
@@ -1767,29 +1844,27 @@ namespace UAS_LabelMachine
                 }
             }
             //保存参数打印
-            MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
-            MidDoc.PrintDocument();
+            if (EnablePrint) {
+                MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
+                MidDoc.PrintDocument();
+            }
         }
 
         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
@@ -1830,6 +1905,17 @@ namespace UAS_LabelMachine
                                     }
                                     MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
                                 }
+                                if (MidDoc.Variables.FreeVariables.Item(j + 1).Value == "")
+                                {
+                                    try
+                                    {
+                                        MidDoc.Variables.FreeVariables.Item(j + 1).Value = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                    }
+                                    catch (Exception)
+                                    {
+
+                                    }
+                                }
                                 LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
                             }
                         }
@@ -1842,8 +1928,10 @@ namespace UAS_LabelMachine
                 }
             }
             //保存参数打印
-            MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
-            MidDoc.PrintDocument();
+            if (EnablePrint) {
+                MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
+                MidDoc.PrintDocument();
+            }
         }
 
         /// <summary>
@@ -1860,18 +1948,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);
@@ -1882,7 +1970,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
                                 {
@@ -1903,6 +1991,17 @@ namespace UAS_LabelMachine
                                         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 == "")
+                                    {
+                                        try
+                                        {
+                                            OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "'")[0]["lp_sql"].ToString();
+                                        }
+                                        catch (Exception)
+                                        {
+
+                                        }
+                                    }
                                     LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value);
                                 }
                                 catch (Exception)
@@ -1923,8 +2022,10 @@ namespace UAS_LabelMachine
                     }
                 }
                 //保存参数打印
-                OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
-                OutBoxDoc.PrintDocument();
+                if (EnablePrint) {
+                    OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
+                    OutBoxDoc.PrintDocument();
+                }
                 LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString());
             }
             catch (Exception ex) { MessageBox.Show(ex.Message); }
@@ -2613,5 +2714,44 @@ namespace UAS_LabelMachine
         {
             dh.ExecuteSql("select count(1) from employee", "select");
         }
+
+        private void LoadPrcodeData()
+        {
+            GridPrcode.DataSource = (DataTable)dh.ExecuteSql("select distinct pib_prodcode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_prodcode", "select");
+        }
+
+        private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
+        {
+            //用户在重新勾选后重置采集项目的索引
+            if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
+            {
+                CurrentItemIndex = 0;
+                for (int i = 0; i < LabelInf.RowCount; i++)
+                {
+                    if (GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
+                    {
+                        CurrentRowIndex = i;
+                        break;
+                    }
+                }
+            }
+        }
+
+        private bool EnablePrint = true;
+
+        private void SetPrintStatus_Click(object sender, EventArgs e)
+        {
+            EnablePrint = !EnablePrint;
+            if (EnablePrint)
+            {
+                SetPrintStatus_label.ForeColor = Color.Green;
+                SetPrintStatus_label.Text = "可打印";
+            }
+            else
+            {
+                SetPrintStatus_label.ForeColor = Color.Red;
+                SetPrintStatus_label.Text = "暂停打印";
+            }
+        }
     }
 }

+ 3 - 0
UAS-出货标签管理/UAS_出货标签管理.resx

@@ -150,6 +150,9 @@
   <metadata name="ExportFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>294, 17</value>
   </metadata>
+  <metadata name="pd_prodcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
   <metadata name="pib_madein.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>