Преглед на файлове

处理程序崩溃异常

章政 преди 6 години
родител
ревизия
c2e0d6482b

+ 14 - 36
UAS-出货标签管理(吉利通)/PublicMethod/AccessDBHelper.cs

@@ -108,7 +108,7 @@ namespace UAS_LabelMachine
             OleDbDataAdapter ad = new OleDbDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            command.Dispose();
+            
             return dt;
         }
 
@@ -137,7 +137,7 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            command.Dispose();
+            
             if (dt.Rows.Count > 0)
             {
                 return dt.Rows[0][0];
@@ -167,7 +167,7 @@ namespace UAS_LabelMachine
             {
 
             }
-            command.Dispose();
+            
         }
 
         public void DeleleFile(string accessFile)
@@ -259,7 +259,7 @@ namespace UAS_LabelMachine
                 tx.Rollback();
                 throw new Exception(E.Message);
             }
-            command.Dispose();
+            
             //string[][] param_array = new string[dt.Columns.Count][];
             //for (int i = 0; i < dt.Columns.Count; i++)
             //{
@@ -319,7 +319,7 @@ namespace UAS_LabelMachine
             OleDbDataAdapter ad = new OleDbDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            command.Dispose();
+            
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -335,10 +335,8 @@ namespace UAS_LabelMachine
             command = new OleDbCommand(sql, this._odcConnection);
             Reconnect(command);
             OleDbDataAdapter ad = new OleDbDataAdapter(command);
-
             ad.Fill(dt);
             ad.Dispose();
-            command.Dispose();
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -368,26 +366,9 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            command.Dispose();
             return dt;
         }
 
-        /// <summary>
-        /// 将DataTable导入到指定的表中
-        /// </summary>
-        /// <param name="DataTable"></param>
-        /// <param name="TableName"></param>
-        public void InsertDataTable(DataTable DataTable, string TableName)
-        {
-            for (int i = 0; i < DataTable.Rows.Count; i++)
-            {
-                for (int j = 0; j < DataTable.Columns.Count; j++)
-                {
-
-                }
-            }
-        }
-
         /// <summary>
         /// 按分页获取数据
         /// </summary>
@@ -421,7 +402,6 @@ namespace UAS_LabelMachine
             OleDbDataAdapter ad = new OleDbDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            command.Dispose();
             dt.Columns.RemoveAt(0);
             foreach (DataColumn dc in dt.Columns)
             {
@@ -458,7 +438,6 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            command.Dispose();
             return dt;
         }
 
@@ -489,7 +468,6 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            command.Dispose();
             return dt;
         }
 
@@ -561,7 +539,7 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            command.Dispose();
+            
             return int.Parse(dt.Rows[0][0].ToString()) > 0;
         }
 
@@ -659,7 +637,7 @@ namespace UAS_LabelMachine
                     }
                     break;
             }
-            command.Dispose();
+            
             return result;
         }
 
@@ -672,7 +650,7 @@ namespace UAS_LabelMachine
             SQL = SQL.Replace("?", ":Param");
             command = new OleDbCommand(SQL, this._odcConnection);
             command.ExecuteNonQuery();
-            command.Dispose();
+            
         }
 
         public int GetDistinctRowCount(string TableName, string Field)
@@ -696,7 +674,7 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            command.Dispose();
+            
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -819,7 +797,7 @@ namespace UAS_LabelMachine
                 command.Connection.Open();
                 Rowcount = command.ExecuteNonQuery();
             }
-            command.Dispose();
+            
             return Rowcount;
         }
 
@@ -849,7 +827,7 @@ namespace UAS_LabelMachine
             }
             for (int i = 0; i < command.Parameters.Count; i++)
                 param[i] = command.Parameters[i].Value.ToString();
-            command.Dispose();
+            
         }
 
         /// <summary>
@@ -888,7 +866,7 @@ namespace UAS_LabelMachine
                 tx.Rollback();
                 throw new Exception(E.Message);
             }
-            command.Dispose();
+            
         }
 
         /// <summary>
@@ -958,12 +936,12 @@ namespace UAS_LabelMachine
             if (dt.Rows.Count > 0)
             {
                 ad.Dispose();
-                command.Dispose();
+                
                 return dt.Rows[0][0];
             }
             else
             {
-                command.Dispose();
+                
                 return "";
             }
         }

+ 29 - 0
UAS-出货标签管理(吉利通)/UAS_出货标签管理.Designer.cs

@@ -92,6 +92,8 @@
             this.LogMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
             this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
             this.UploadData = new System.Windows.Forms.Button();
+            this.PageSizeNum = new System.Windows.Forms.NumericUpDown();
+            this.label28 = new System.Windows.Forms.Label();
             this.front_sg_separator = new UAS_LabelMachine.CustomControl.EnterTextBox();
             this.FrontCollect = new UAS_LabelMachine.CustomControl.EnterTextBox();
             this.CollectionProcess = new UAS_LabelMachine.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder();
@@ -236,6 +238,7 @@
             this.pib_outboxcode1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.pib_outboxcode2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.LogMenu.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.PageSizeNum)).BeginInit();
             this.CollectionProcess.SuspendLayout();
             this.groupBox2.SuspendLayout();
             this.groupBox1.SuspendLayout();
@@ -826,6 +829,26 @@
             this.UploadData.UseVisualStyleBackColor = true;
             this.UploadData.Click += new System.EventHandler(this.UploadData_Click);
             // 
+            // PageSizeNum
+            // 
+            this.PageSizeNum.Location = new System.Drawing.Point(399, 609);
+            this.PageSizeNum.Name = "PageSizeNum";
+            this.PageSizeNum.Size = new System.Drawing.Size(63, 21);
+            this.PageSizeNum.TabIndex = 104;
+            this.PageSizeNum.Visible = false;
+            this.PageSizeNum.ValueChanged += new System.EventHandler(this.PageSizeNum_ValueChanged);
+            // 
+            // label28
+            // 
+            this.label28.AutoSize = true;
+            this.label28.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label28.Location = new System.Drawing.Point(322, 609);
+            this.label28.Name = "label28";
+            this.label28.Size = new System.Drawing.Size(74, 21);
+            this.label28.TabIndex = 105;
+            this.label28.Text = "每页数量";
+            this.label28.Visible = false;
+            // 
             // front_sg_separator
             // 
             this.front_sg_separator.Enabled = false;
@@ -2230,6 +2253,7 @@
             this.pib_id1.DataPropertyName = "pib_id";
             this.pib_id1.HeaderText = "pib_id";
             this.pib_id1.Name = "pib_id1";
+            this.pib_id1.Visible = false;
             this.pib_id1.Width = 66;
             // 
             // rownum
@@ -2458,6 +2482,8 @@
             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(1389, 729);
+            this.Controls.Add(this.label28);
+            this.Controls.Add(this.PageSizeNum);
             this.Controls.Add(this.UploadData);
             this.Controls.Add(this.PageNum);
             this.Controls.Add(this.LastPage);
@@ -2503,6 +2529,7 @@
             this.Load += new System.EventHandler(this.贴标机条码打印_Load);
             this.SizeChanged += new System.EventHandler(this.贴标机条码打印_SizeChanged);
             this.LogMenu.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)(this.PageSizeNum)).EndInit();
             this.CollectionProcess.ResumeLayout(false);
             this.CollectionProcess.PerformLayout();
             this.groupBox2.ResumeLayout(false);
@@ -2711,6 +2738,8 @@
         private System.Windows.Forms.LinkLabel SingleDocRefresh;
         private System.Windows.Forms.LinkLabel MidDocRefresh;
         private System.Windows.Forms.LinkLabel OutDocRefresh;
+        private System.Windows.Forms.NumericUpDown PageSizeNum;
+        private System.Windows.Forms.Label label28;
         private System.Windows.Forms.DataGridViewCheckBoxColumn Choose;
         private System.Windows.Forms.DataGridViewTextBoxColumn pd_id;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_id1;

+ 15 - 7
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -208,7 +208,6 @@ namespace UAS_LabelMachine
                 byte[] readBuffer = new byte[len];
                 port.Read(readBuffer, 0, len); //将数据读入缓存
                 string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号
-                string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
                 int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
                 if (DetailRange.Checked)
                 {
@@ -269,7 +268,7 @@ namespace UAS_LabelMachine
                         break;
                     case "BackendCheck":
                         BackCheck.Text = msg;
-                        if (BackendCheckFunction(msg, pib_id, out ErrorMsg))
+                        if (BackendCheckFunction(msg, out ErrorMsg))
                         {
                             LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass);
                             BaseUtil.PlaySound("Confirm.Finish.wav");
@@ -594,7 +593,7 @@ namespace UAS_LabelMachine
         //中盒条码号
         string MidBoxBarCode = "";
 
-        private bool BackendCheckFunction(string msg, string pib_id, out string ErrorMsg)
+        private bool BackendCheckFunction(string msg, out string ErrorMsg)
         {
             ErrorMsg = "";
             DataTable dtt = LabelInf.DataSource as DataTable;
@@ -1455,7 +1454,7 @@ namespace UAS_LabelMachine
             LoadGridData(new object(), new EventArgs());
         }
         int CurrentPage = 1;
-        int PageSize = 10;
+        int PageSize = 500;
         int DataSize = 0;
         int MaxPageSize = 0;
         DataTable LabelInfDataTable;
@@ -1534,6 +1533,10 @@ namespace UAS_LabelMachine
                     CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
                     break;
                 }
+                else
+                {
+                    CurrentRowIndex = LabelInf.RowCount - 1;
+                }
             }
         }
 
@@ -1733,7 +1736,7 @@ namespace UAS_LabelMachine
         {
             ExportFileDialog.Description = "选择导出的路径";
             DialogResult result = ExportFileDialog.ShowDialog();
-            DataTable dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='"+pi_inoutno.Text+"'", "select");
+            DataTable dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select");
             if (result == DialogResult.OK)
             {
                 ExcelHandler eh = new ExcelHandler();
@@ -1945,9 +1948,8 @@ namespace UAS_LabelMachine
         private void ButtonRecheckPass_Click(object sender, EventArgs e)
         {
             string ErrorMsg = "";
-            string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
             int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
-            BackendCheckFunction("", pib_id, out ErrorMsg);
+            BackendCheckFunction("", out ErrorMsg);
         }
 
         private void ButtonSetMidBox_Click(object sender, EventArgs e)
@@ -2100,5 +2102,11 @@ namespace UAS_LabelMachine
                     break;
             }
         }
+
+        private void PageSizeNum_ValueChanged(object sender, EventArgs e)
+        {
+            PageSize = int.Parse(PageSizeNum.Value.ToString());
+            LoadGridData();
+        }
     }
 }