Jelajahi Sumber

- Úprava mapování na sloupečky CSV, nastavení defaultů
- Přidáno nastavení pro promazání výstupního adresáře, včetně nastavení

Dalibor Votruba 1 tahun lalu
induk
melakukan
133d3e0f96

+ 9 - 6
App.config

@@ -8,22 +8,22 @@
     <userSettings>
         <qdr.app.studiou.orders2printpack.Properties.AppSettings>
             <setting name="CSVDelimiter" serializeAs="String">
-                <value>,</value>
+                <value>;</value>
             </setting>
             <setting name="LastOutputDir" serializeAs="String">
                 <value />
             </setting>
             <setting name="MapColOrderNo" serializeAs="String">
-                <value>Order No</value>
+                <value>order_no</value>
             </setting>
             <setting name="MapColProductCat" serializeAs="String">
-                <value>Prod Cat</value>
+                <value>prod_cat</value>
             </setting>
             <setting name="MapColUri" serializeAs="String">
-                <value>Prod Img Url</value>
+                <value>prod_img_url</value>
             </setting>
             <setting name="MapColQuantity" serializeAs="String">
-                <value>Qty</value>
+                <value>qty</value>
             </setting>
             <setting name="SourceSearchPattern" serializeAs="String">
                 <value>*.jpg</value>
@@ -32,7 +32,7 @@
                 <value>{prod_var}_{prod_cat}_{order_no}_{ordinal}{ext}</value>
             </setting>
             <setting name="MapColProductFormat" serializeAs="String">
-                <value>Prod Var</value>
+                <value>prod_var</value>
             </setting>
             <setting name="LastSourceDir" serializeAs="String">
                 <value />
@@ -40,6 +40,9 @@
             <setting name="RemoveFromUri" serializeAs="String">
                 <value>_tn</value>
             </setting>
+            <setting name="CleanupOutputDir" serializeAs="String">
+                <value>True</value>
+            </setting>
         </qdr.app.studiou.orders2printpack.Properties.AppSettings>
     </userSettings>
 </configuration>

+ 46 - 4
FormMain.cs

@@ -121,8 +121,8 @@ namespace qdr.app.studiou.orders2printpack
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
         private void tsbProtocol_Click(object sender, EventArgs e)
         {
-           var dlg = new dlgProtocol();
-           if (dlg.ShowDialog(this) == DialogResult.OK)
+            var dlg = new dlgProtocol();
+            if (dlg.ShowDialog(this) == DialogResult.OK)
                 GenerateProtocol(dlg.ExternalOrder, dlg.ExternalOrderDate, dlg.ProtocolFile);
         }
 
@@ -312,6 +312,12 @@ namespace qdr.app.studiou.orders2printpack
                 rows = _source.AsEnumerable();
                 //var colNames = _source.Columns.Cast<DataColumn>().Select(x => NormalizeColumnName(x.ColumnName)).ToArray();
 
+                if (AppSettings.Default.CleanupOutputDir)
+                {
+                    Log($"Čistím složku výstupu '{_outputPath}' ...");
+                    CleanupDirectory(_outputPath);
+                }
+
                 ssProgress.Maximum = rows.Count();
                 var outputFileNameBuilder = new ParameterizedString(AppSettings.Default.OutputFileMask, CS_TAG_LB, CS_TAG_RB);
 
@@ -350,14 +356,14 @@ namespace qdr.app.studiou.orders2printpack
             BlockErrorHandled(() =>
             {
                 Log($"Nastavuji číslo externí objednávky: {externalOrder} a datum: {externalOrderDate.ToShortDateString()} ...");
-                foreach(var row in _source.AsEnumerable())
+                foreach (var row in _source.AsEnumerable())
                 {
                     row.SetField(_sourceColOrdinals[CS_COL_EXTERNALORDER], externalOrder);
                     row.SetField(_sourceColOrdinals[CS_COL_EXTERNALORDERDATE], externalOrderDate.ToFileUtcString());
                 }
                 Log($"Generuji protokol ...");
                 CsvHelper.DataTableToCsv(_fs, _source, protocolFile, AppSettings.Default.CSVDelimiter);
-                Log($"Protokol uložen do souboru '{protocolFile}'.");   
+                Log($"Protokol uložen do souboru '{protocolFile}'.");
             });
         }
 
@@ -399,7 +405,43 @@ namespace qdr.app.studiou.orders2printpack
         }
         #endregion
 
+        #region **** Support opperations ****
+        public static void CleanupDirectory(string directoryPath)
+        {
+            if (string.IsNullOrWhiteSpace(directoryPath))
+                throw new ArgumentException("Directory path cannot be null or empty.", nameof(directoryPath));
+
+
+            if (!Directory.Exists(directoryPath))
+                throw new DirectoryNotFoundException($"Directory not found: {directoryPath}");
+
+
+            try
+            {
+                var di = new DirectoryInfo(directoryPath);
+
+                foreach (var file in di.GetFiles())
+                {
+                    try{
+                        file.Delete();
+                    }
+                    catch{}
+                }
 
+                foreach (var dir in di.GetDirectories())
+                {
+                    try{
+                        dir.Delete(true);
+                    }
+                    catch{}
+                }
+            }
+            catch (Exception)
+            {
+                throw;
+            }
+        }
+        #endregion
 
         #endregion
 

+ 18 - 6
Properties/AppSettings.Designer.cs

@@ -25,7 +25,7 @@ namespace qdr.app.studiou.orders2printpack.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute(",")]
+        [global::System.Configuration.DefaultSettingValueAttribute(";")]
         public string CSVDelimiter {
             get {
                 return ((string)(this["CSVDelimiter"]));
@@ -49,7 +49,7 @@ namespace qdr.app.studiou.orders2printpack.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Order No")]
+        [global::System.Configuration.DefaultSettingValueAttribute("order_no")]
         public string MapColOrderNo {
             get {
                 return ((string)(this["MapColOrderNo"]));
@@ -61,7 +61,7 @@ namespace qdr.app.studiou.orders2printpack.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Prod Cat")]
+        [global::System.Configuration.DefaultSettingValueAttribute("prod_cat")]
         public string MapColProductCat {
             get {
                 return ((string)(this["MapColProductCat"]));
@@ -73,7 +73,7 @@ namespace qdr.app.studiou.orders2printpack.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Prod Img Url")]
+        [global::System.Configuration.DefaultSettingValueAttribute("prod_img_url")]
         public string MapColUri {
             get {
                 return ((string)(this["MapColUri"]));
@@ -85,7 +85,7 @@ namespace qdr.app.studiou.orders2printpack.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Qty")]
+        [global::System.Configuration.DefaultSettingValueAttribute("qty")]
         public string MapColQuantity {
             get {
                 return ((string)(this["MapColQuantity"]));
@@ -121,7 +121,7 @@ namespace qdr.app.studiou.orders2printpack.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Prod Var")]
+        [global::System.Configuration.DefaultSettingValueAttribute("prod_var")]
         public string MapColProductFormat {
             get {
                 return ((string)(this["MapColProductFormat"]));
@@ -154,5 +154,17 @@ namespace qdr.app.studiou.orders2printpack.Properties {
                 this["RemoveFromUri"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("True")]
+        public bool CleanupOutputDir {
+            get {
+                return ((bool)(this["CleanupOutputDir"]));
+            }
+            set {
+                this["CleanupOutputDir"] = value;
+            }
+        }
     }
 }

+ 9 - 6
Properties/AppSettings.settings

@@ -3,22 +3,22 @@
   <Profiles />
   <Settings>
     <Setting Name="CSVDelimiter" Type="System.String" Scope="User">
-      <Value Profile="(Default)">,</Value>
+      <Value Profile="(Default)">;</Value>
     </Setting>
     <Setting Name="LastOutputDir" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
     <Setting Name="MapColOrderNo" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Order No</Value>
+      <Value Profile="(Default)">order_no</Value>
     </Setting>
     <Setting Name="MapColProductCat" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Prod Cat</Value>
+      <Value Profile="(Default)">prod_cat</Value>
     </Setting>
     <Setting Name="MapColUri" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Prod Img Url</Value>
+      <Value Profile="(Default)">prod_img_url</Value>
     </Setting>
     <Setting Name="MapColQuantity" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Qty</Value>
+      <Value Profile="(Default)">qty</Value>
     </Setting>
     <Setting Name="SourceSearchPattern" Type="System.String" Scope="User">
       <Value Profile="(Default)">*.jpg</Value>
@@ -27,7 +27,7 @@
       <Value Profile="(Default)">{prod_var}_{prod_cat}_{order_no}_{ordinal}{ext}</Value>
     </Setting>
     <Setting Name="MapColProductFormat" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Prod Var</Value>
+      <Value Profile="(Default)">prod_var</Value>
     </Setting>
     <Setting Name="LastSourceDir" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
@@ -35,5 +35,8 @@
     <Setting Name="RemoveFromUri" Type="System.String" Scope="User">
       <Value Profile="(Default)">_tn</Value>
     </Setting>
+    <Setting Name="CleanupOutputDir" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">True</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

+ 6 - 1
README.md

@@ -3,7 +3,12 @@
 Proprietální řešení zpracování WooCommerce objednávek pro online tiskovou službu (WinForm)
 
 ## Changelog
-### 1.0.0 (2024-09-27)
+
+### 1.0.2 (2024-10-05)
+- Úprava mapování na sloupečky CSV, nastavení defaultů
+- Přidáno nastavení pro promazání výstupního adresáře, včetně nastavení
+
+### 1.0.1 (2024-09-27)
 - Přidána podpora generování protokolu (.csv)
 - Rozšíření datové stuktury o položky, OutputFileName, ExternalOrder, ExternalOrderDate
 - Oprav chyb UI

+ 4 - 4
Setup/Setup.vdproj

@@ -198,15 +198,15 @@
         {
         "Name" = "8:Microsoft Visual Studio"
         "ProductName" = "8:Order2PrintPack"
-        "ProductCode" = "8:{15D775F7-1884-4BEA-A818-BE6FD4115761}"
-        "PackageCode" = "8:{957F30D6-34A6-487F-9148-366CDD7D4695}"
+        "ProductCode" = "8:{B2BD7791-A085-465B-9C18-B700E93A51F0}"
+        "PackageCode" = "8:{0CFB780F-8DAF-461B-812A-738949E18952}"
         "UpgradeCode" = "8:{38F8DC1E-8290-49ED-A3D2-32BC6DD74325}"
         "AspNetVersion" = "8:2.0.50727.0"
         "RestartWWWService" = "11:FALSE"
         "RemovePreviousVersions" = "11:TRUE"
         "DetectNewerInstalledVersion" = "11:TRUE"
         "InstallAllUsers" = "11:FALSE"
-        "ProductVersion" = "8:1.0.1"
+        "ProductVersion" = "8:1.0.2"
         "Manufacturer" = "8:Quadarax"
         "ARPHELPTELEPHONE" = "8:"
         "ARPHELPLINK" = "8:"
@@ -734,7 +734,7 @@
         {
             "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_401EDA760B6F46889C1BF580F3C37DBF"
             {
-            "SourcePath" = "8:..\\obj\\x86\\Release\\net8.0-windows\\apphost.exe"
+            "SourcePath" = "8:..\\obj\\x64\\Release\\net8.0-windows\\apphost.exe"
             "TargetName" = "8:"
             "Tag" = "8:"
             "Folder" = "8:_96DC0B7F01834A1BA713E7E8A0904D3E"

+ 13 - 0
dlgSettings.Designer.cs

@@ -37,6 +37,7 @@
             tbReplacement = new TextBox();
             label3 = new Label();
             butReset = new Button();
+            chbCleanupDir = new CheckBox();
             SuspendLayout();
             // 
             // butOk
@@ -117,12 +118,23 @@
             butReset.UseVisualStyleBackColor = true;
             butReset.Click += butReset_Click;
             // 
+            // chbCleanupDir
+            // 
+            chbCleanupDir.AutoSize = true;
+            chbCleanupDir.Location = new Point(12, 197);
+            chbCleanupDir.Name = "chbCleanupDir";
+            chbCleanupDir.Size = new Size(314, 24);
+            chbCleanupDir.TabIndex = 9;
+            chbCleanupDir.Text = "Promazat výstupní adresář před spuštěním.";
+            chbCleanupDir.UseVisualStyleBackColor = true;
+            // 
             // dlgSettings
             // 
             AutoScaleDimensions = new SizeF(8F, 20F);
             AutoScaleMode = AutoScaleMode.Font;
             ClientSize = new Size(581, 326);
             ControlBox = false;
+            Controls.Add(chbCleanupDir);
             Controls.Add(butReset);
             Controls.Add(tbReplacement);
             Controls.Add(label3);
@@ -155,5 +167,6 @@
         private TextBox tbReplacement;
         private Label label3;
         private Button butReset;
+        private CheckBox chbCleanupDir;
     }
 }

+ 2 - 0
dlgSettings.cs

@@ -19,6 +19,7 @@ namespace qdr.app.studiou.orders2printpack
             AppSettings.Default.OutputFileMask = tbMask.Text;
             AppSettings.Default.SourceSearchPattern = tbExt.Text;
             AppSettings.Default.RemoveFromUri = tbReplacement.Text;
+            AppSettings.Default.CleanupOutputDir = chbCleanupDir.Checked;
             AppSettings.Default.Save();
             Close();
         }
@@ -29,6 +30,7 @@ namespace qdr.app.studiou.orders2printpack
             tbMask.Text = AppSettings.Default.OutputFileMask;
             tbExt.Text = AppSettings.Default.SourceSearchPattern;
             tbReplacement.Text = AppSettings.Default.RemoveFromUri;
+            chbCleanupDir.Checked = AppSettings.Default.CleanupOutputDir;
 
         }
 

+ 3 - 3
qdr.app.studiou.orders2printpack.csproj

@@ -16,9 +16,9 @@
     <SignAssembly>True</SignAssembly>
     <AssemblyOriginatorKeyFile>bo_strong_key_pair.snk</AssemblyOriginatorKeyFile>
     <Platforms>AnyCPU;x86;x64</Platforms>
-    <AssemblyVersion>1.0.1.0</AssemblyVersion>
-    <FileVersion>1.0.1.0</FileVersion>
-    <Version>1.0.1</Version>
+    <AssemblyVersion>1.0.2.0</AssemblyVersion>
+    <FileVersion>1.0.2.0</FileVersion>
+    <Version>1.0.2</Version>
   </PropertyGroup>
 
   <ItemGroup>