From dcad42e7c00871e816e4196732aead7cb7c560c2 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周五, 16 5月 2025 11:21:41 +0800
Subject: [PATCH] //是否要事先清理文件夹

---
 Weben_CMS专用代码生成器/Code/MainForm.cs                    |   12 ++++++
 Weben_CMS专用代码生成器/Code/MainForm.Designer.cs           |   18 ++++++++
 Weben_CMS专用代码生成器/Code/Utility/FileHelper.cs          |   71 +++++++++++++++++++++++++++++++++++
 Weben_CMS专用代码生成器/Code/GenerateCode_WeiBen_CMS.csproj |    1 
 4 files changed, 101 insertions(+), 1 deletions(-)

diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj"
index f57c03d..695e495 100644
--- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj"
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj"
@@ -273,6 +273,7 @@
       <DependentUpon>MainForm.cs</DependentUpon>
     </Compile>
     <Compile Include="Utility\StructStrHelper.cs" />
+    <Compile Include="Utility\FileHelper.cs" />
     <Compile Include="Utility\TextHelper.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.Designer.cs" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.Designer.cs"
index d0ab2c9..442d677 100644
--- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.Designer.cs"
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.Designer.cs"
@@ -79,13 +79,14 @@
             this.tb_FilePath = new System.Windows.Forms.TextBox();
             this.btn_SelectFile = new System.Windows.Forms.Button();
             this.button1 = new System.Windows.Forms.Button();
+            this.ck_IsDeletefile = new System.Windows.Forms.CheckBox();
             this.groupBox1.SuspendLayout();
             this.groupBox2.SuspendLayout();
             this.SuspendLayout();
             // 
             // btnPath
             // 
-            this.btnPath.Location = new System.Drawing.Point(453, 723);
+            this.btnPath.Location = new System.Drawing.Point(425, 720);
             this.btnPath.Name = "btnPath";
             this.btnPath.Size = new System.Drawing.Size(97, 23);
             this.btnPath.TabIndex = 1;
@@ -564,11 +565,25 @@
             this.button1.UseVisualStyleBackColor = true;
             this.button1.Click += new System.EventHandler(this.button1_Click_1);
             // 
+            // ck_IsDeletefile
+            // 
+            this.ck_IsDeletefile.AutoSize = true;
+            this.ck_IsDeletefile.Checked = true;
+            this.ck_IsDeletefile.CheckState = System.Windows.Forms.CheckState.Checked;
+            this.ck_IsDeletefile.Location = new System.Drawing.Point(561, 724);
+            this.ck_IsDeletefile.Name = "ck_IsDeletefile";
+            this.ck_IsDeletefile.Size = new System.Drawing.Size(192, 16);
+            this.ck_IsDeletefile.TabIndex = 50;
+            this.ck_IsDeletefile.Text = "鐢熸垚鍓嶆槸鍚﹀厛娓呯悊鏂囦欢澶圭殑鏂囦欢";
+            this.ck_IsDeletefile.UseVisualStyleBackColor = true;
+            this.ck_IsDeletefile.CheckedChanged += new System.EventHandler(this.ck_IsDeletefile_CheckedChanged);
+            // 
             // MainForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1402, 831);
+            this.Controls.Add(this.ck_IsDeletefile);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.btn_SelectFile);
             this.Controls.Add(this.tb_FilePath);
@@ -645,6 +660,7 @@
         private System.Windows.Forms.Button btn_SelectFile;
         private System.Windows.Forms.Button button1;
         private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.CheckBox ck_IsDeletefile;
     }
 }
 
diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs"
index 5867a50..de76ad1 100644
--- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs"
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs"
@@ -283,6 +283,13 @@
                 //CreateModelFile(columnList, tableName, filePrefixName, wcf_NameSpacePath, createPerson, chinaComment, entityName, modulelogo);
                 //CreateModelParamFile(columnList, tableName, filePrefixName, wcf_NameSpacePath, createPerson, chinaComment, entityName, modulelogo);
                 genCodeRootPath = tbPath.Text + @"\" + tb_WCF_NameSpacePath.Text.Trim();
+
+                //鏄惁瑕佷簨鍏堟竻鐞嗘枃浠跺す
+                if (this.ck_IsDeletefile.Checked)
+                {
+                    FileHelper.ClearFolder(genCodeRootPath); // 閫掑綊鍒犻櫎
+                }
+
                 //var webFolerPath = (tb_WCF_NameSpacePath.Text.Trim() + "_Web").ToLower();
                 var webFolerPath = _tb_VueRootFolerName;
                 #region 瀹炰綋绫�
@@ -825,5 +832,10 @@
         {
             this.tb_FilePath.Text = "";
         }
+
+        private void ck_IsDeletefile_CheckedChanged(object sender, EventArgs e)
+        {
+           
+        }
     }
 }
diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Utility/FileHelper.cs" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Utility/FileHelper.cs"
new file mode 100644
index 0000000..dbab47a
--- /dev/null
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Utility/FileHelper.cs"
@@ -0,0 +1,71 @@
+锘�
+using GenerateCode_GEBrilliantFactory;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GenerateCode_GEBrilliantFactory
+{
+    public class FileHelper
+    {
+
+        public static void DeleteAllContentsInFolder(string folderPath)
+        {
+            try
+            {
+                if (Directory.Exists(folderPath))
+                {
+                    // 鍒犻櫎鎵�鏈夋枃浠跺拰瀛愭枃浠跺す锛堝寘鎷瓙鏂囦欢澶逛腑鐨勬枃浠讹級
+                    foreach (string file in Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories))
+                    {
+                        File.Delete(file);
+                        Console.WriteLine($"宸插垹闄ゆ枃浠�: {file}");
+                    }
+
+                    // 鍒犻櫎鎵�鏈夊瓙鏂囦欢澶癸紙姝ゆ椂鏂囦欢澶瑰凡绌猴紝鍙互瀹夊叏鍒犻櫎锛�
+                    foreach (string dir in Directory.GetDirectories(folderPath, "*", SearchOption.AllDirectories))
+                    {
+                        Directory.Delete(dir); // 涓嶉渶瑕侀�掑綊锛屽洜涓烘枃浠跺凡琚垹闄�
+                        Console.WriteLine($"宸插垹闄ゆ枃浠跺す: {dir}");
+                    }
+
+                    Console.WriteLine($"鎴愬姛娓呯┖鏂囦欢澶� '{folderPath}' 涓嬬殑鎵�鏈夊唴瀹广��");
+                }
+                else
+                {
+                    Console.WriteLine($"鏂囦欢澶逛笉瀛樺湪: {folderPath}");
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine($"鍒犻櫎鏂囦欢/鏂囦欢澶规椂鍑洪敊: {ex.Message}");
+            }
+        }
+
+
+        public static void ClearFolder(string folderPath)
+        {
+            try
+            {
+                if (Directory.Exists(folderPath))
+                {
+                    // 鍒犻櫎鎵�鏈夋枃浠跺拰瀛愭枃浠跺す锛堝寘鎷瓙鏂囦欢澶逛腑鐨勬枃浠讹級
+                    Directory.Delete(folderPath, true); // true 琛ㄧず閫掑綊鍒犻櫎
+                    Directory.CreateDirectory(folderPath); // 閲嶆柊鍒涘缓绌烘枃浠跺す
+                    Console.WriteLine($"宸叉竻绌哄苟閲嶅缓鏂囦欢澶� '{folderPath}'銆�");
+                }
+                else
+                {
+                    Console.WriteLine($"鏂囦欢澶逛笉瀛樺湪: {folderPath}");
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine($"娓呯┖鏂囦欢澶规椂鍑洪敊: {ex.Message}");
+            }
+        }
+    }
+}

--
Gitblit v1.9.3