2 İşlemeler 29188537af ... 49593e14a1

Yazar SHA1 Mesaj Tarih
  宝臣 王 49593e14a1 Merge branch 'master' of https://git.xxb.lttc.cn/wangbc/UniformMaterialManagementSystem 2 ay önce
  宝臣 王 8152c918fe 修复数据包导入导出BUG 2 ay önce

+ 14 - 22
UniformMaterialManagementSystem/Utils/DataBaseUtil.cs

@@ -19,7 +19,7 @@ namespace UniformMaterialManagementSystem.Utils
         private const string Password = "88384e6a-07e0-47e9-8214-4470a16e78da";
         private static readonly string SourcePath = $"{DataBasePath}\\UniformMaterialManagementSystem.db";
 
-        public static async Task ExportData()
+        public static async Task<bool> ExportData()
         {
             // 创建 SaveFileDialog 实例
             var saveFileDialog = new SaveFileDialog
@@ -31,26 +31,16 @@ namespace UniformMaterialManagementSystem.Utils
                 FileName = "被装数据包" // 设置默认文件名
             };
 
-            var targetPath = string.Empty;
             // 显示对话框并检查用户是否选择了文件
-            if (saveFileDialog.ShowDialog() == true)
-            {
-                // 获取选中的文件路径
-                targetPath = saveFileDialog.FileName;
-            }
+            if (saveFileDialog.ShowDialog() == false)
+                return false;
 
-            // 手动合并数据库
-            await using var connection = new SqliteConnection($"Data Source={SourcePath}");
-            connection.Open();
-            
-            await using (var command = connection.CreateCommand())
-            {
-                command.CommandText = "PRAGMA wal_checkpoint(FULL);";
-                command.ExecuteNonQuery();
-            }
-            connection.Close();
+            // 获取选中的文件路径
+            var targetPath = saveFileDialog.FileName;
 
             EncryptFile(SourcePath, targetPath);
+
+            return true;
         }
 
         public static async void ExportTable<T>(IEnumerable<T> sourceData, string tableName, bool isExecMigrate = false) where T : class?
@@ -119,6 +109,7 @@ namespace UniformMaterialManagementSystem.Utils
             }
 
             connection.Close();
+            SqliteConnection.ClearAllPools();
         }
 
         public static string ImportData()
@@ -134,11 +125,11 @@ namespace UniformMaterialManagementSystem.Utils
             var sourcePath = string.Empty;
 
             // 显示对话框并检查用户是否选择了文件
-            if (openFileDialog.ShowDialog() == true)
-            {
-                // 获取选中的文件路径
-                sourcePath = openFileDialog.FileName;
-            }
+            if (openFileDialog.ShowDialog() == false)
+                return sourcePath;
+
+            // 获取选中的文件路径
+            sourcePath = openFileDialog.FileName;
 
             CreateExportFolder();
 
@@ -202,6 +193,7 @@ namespace UniformMaterialManagementSystem.Utils
             }
 
             connection.Close();
+            SqliteConnection.ClearAllPools();
         }
 
         public static async Task<IEnumerable<T>> QueryAll<T>(string path, Func<IQueryable<T>, IQueryable<T>>? includeFunc = null) where T : class