Browse Source

添加数据库压缩

章政 7 years ago
parent
commit
3e64fdf257

+ 2 - 0
UAS-出货标签管理(吉利通)/Login.cs

@@ -31,6 +31,8 @@ namespace UAS_LabelMachine
         private void Login_Load(object sender, EventArgs e)
         {
             dh = new DataHelper();
+            //启动时压缩数据库
+            BaseUtil.CompactAccessDB("LabelPrint.accdb");
             adh = new AccessDBHelper("LabelPrint.accdb");
             SystemInf.dh = dh;
             SystemInf.adh = adh;

+ 19 - 1
UAS-出货标签管理(吉利通)/PublicMethod/BaseUtil.cs

@@ -9,6 +9,7 @@ using UAS_LabelMachine.CustomControl.GroupBoxWithBorder;
 using static System.Windows.Forms.Control;
 using System.Text.RegularExpressions;
 using UAS_LabelMachine.CustomControl.RichText;
+using System.IO;
 
 namespace UAS_LabelMachine
 {
@@ -17,6 +18,23 @@ namespace UAS_LabelMachine
 
         static string SysDisc;
 
+        public static void CompactAccessDB(string dbFileName)
+        {
+            string tempFile = Path.Combine(Path.GetDirectoryName(dbFileName), Path.GetRandomFileName() + Path.GetExtension(dbFileName));
+            var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();
+            try
+            {
+                dbe.CompactDatabase(dbFileName, tempFile);
+                FileInfo temp = new FileInfo(tempFile);
+                temp.CopyTo(dbFileName, true);
+                temp.Delete();
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine("Error: " + e.Message);
+            }
+        }
+
         public static string SysDisc1
         {
             get
@@ -224,7 +242,7 @@ namespace UAS_LabelMachine
                                     {
                                         (collection[i] as CheckBox).Checked = dt.Rows[0][j].ToString() == "-1" ? true : false;
                                     }
-                                   else if (collection[i] is NumericUpDown)
+                                    else if (collection[i] is NumericUpDown)
                                     {
                                         (collection[i] as NumericUpDown).Value = int.Parse(dt.Rows[0][j].ToString());
                                     }

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

@@ -2014,7 +2014,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(170, 42);
+            this.label9.Location = new System.Drawing.Point(170, 41);
             this.label9.Name = "label9";
             this.label9.Size = new System.Drawing.Size(32, 17);
             this.label9.TabIndex = 98;
@@ -2108,10 +2108,10 @@
             // 
             this.OutBoxNum.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.OutBoxNum.ID = null;
-            this.OutBoxNum.Location = new System.Drawing.Point(212, 99);
+            this.OutBoxNum.Location = new System.Drawing.Point(211, 99);
             this.OutBoxNum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.OutBoxNum.Name = "OutBoxNum";
-            this.OutBoxNum.Size = new System.Drawing.Size(37, 23);
+            this.OutBoxNum.Size = new System.Drawing.Size(38, 23);
             this.OutBoxNum.Str = null;
             this.OutBoxNum.Str1 = null;
             this.OutBoxNum.Str2 = null;
@@ -2121,7 +2121,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(170, 101);
+            this.label10.Location = new System.Drawing.Point(170, 102);
             this.label10.Name = "label10";
             this.label10.Size = new System.Drawing.Size(32, 17);
             this.label10.TabIndex = 90;

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

@@ -172,6 +172,7 @@ namespace UAS_LabelMachine
             OutBoxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
             asc.controllInitializeSize(this);
             asc.controlAutoSize(this);
+          
             //实例化打印进程
             try
             {