Bläddra i källkod

ProductEdit: add feature to generate Product Repository

Dalibor Votruba 1 år sedan
förälder
incheckning
403500eeb5
7 ändrade filer med 121 tillägg och 27 borttagningar
  1. 3 3
      App.config
  2. 26 1
      FormProductEdit.Designer.cs
  3. 62 5
      FormProductEdit.cs
  4. 13 1
      FormProductEdit.resx
  5. 13 13
      Properties/AppSettings.Designer.cs
  6. 3 4
      Properties/AppSettings.settings
  7. 1 0
      README.md

+ 3 - 3
App.config

@@ -62,9 +62,6 @@
             <setting name="MapColProductFormat" serializeAs="String">
                 <value>prod_var_type</value>
             </setting>
-            <setting name="LabelTemplate" serializeAs="String">
-                <value>^^18^**Objednávka: {order_no}**^^{cr}^^14^**{prod_cat}**^^{cr}{prod_var_type}{cr}Počet: {qty}</value>
-            </setting>
             <setting name="LabelWidth" serializeAs="String">
                 <value>200</value>
             </setting>
@@ -77,6 +74,9 @@
             <setting name="LabelPerCol" serializeAs="String">
                 <value>8</value>
             </setting>
+            <setting name="LabelTemplate" serializeAs="String">
+                <value>^^18^**Objednávka: {order_no}**^^{cr}^^14^**{prod_cat}**^^{cr}{prod_var_type}{cr}Počet: {qty}</value>
+            </setting>
         </qdr.app.studiou.orders2printpack.Properties.AppSettings>
     </userSettings>
 </configuration>

+ 26 - 1
FormProductEdit.Designer.cs

@@ -39,6 +39,8 @@
             tbbutSave = new ToolStripButton();
             toolStripSeparator1 = new ToolStripSeparator();
             tbbutImport = new ToolStripButton();
+            toolStripSeparator11 = new ToolStripSeparator();
+            tbbutGenerateRepo = new ToolStripButton();
             splitContainer1 = new SplitContainer();
             lvProducts = new ListView();
             colprdCat = new ColumnHeader();
@@ -111,6 +113,7 @@
             dlgOpenFile = new OpenFileDialog();
             dlgOpenDir = new FolderBrowserDialog();
             dlgSaveFile = new SaveFileDialog();
+            dlgDirSelect = new FolderBrowserDialog();
             ssMain.SuspendLayout();
             tsMain.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
@@ -162,7 +165,7 @@
             // 
             // tsMain
             // 
-            tsMain.Items.AddRange(new ToolStripItem[] { tbbutNew, tbbutOpen, tbbutSave, toolStripSeparator1, tbbutImport });
+            tsMain.Items.AddRange(new ToolStripItem[] { tbbutNew, tbbutOpen, tbbutSave, toolStripSeparator1, tbbutImport, toolStripSeparator11, tbbutGenerateRepo });
             tsMain.Location = new Point(0, 0);
             tsMain.Name = "tsMain";
             tsMain.Size = new Size(1117, 25);
@@ -214,6 +217,21 @@
             tbbutImport.Text = "Import";
             tbbutImport.Click += tbbutImport_Click;
             // 
+            // toolStripSeparator11
+            // 
+            toolStripSeparator11.Name = "toolStripSeparator11";
+            toolStripSeparator11.Size = new Size(6, 25);
+            // 
+            // tbbutGenerateRepo
+            // 
+            tbbutGenerateRepo.DisplayStyle = ToolStripItemDisplayStyle.Text;
+            tbbutGenerateRepo.Image = (Image)resources.GetObject("tbbutGenerateRepo.Image");
+            tbbutGenerateRepo.ImageTransparentColor = Color.Magenta;
+            tbbutGenerateRepo.Name = "tbbutGenerateRepo";
+            tbbutGenerateRepo.Size = new Size(108, 22);
+            tbbutGenerateRepo.Text = "Generuj repository";
+            tbbutGenerateRepo.Click += tbbutGenerateRepo_Click;
+            // 
             // splitContainer1
             // 
             splitContainer1.Dock = DockStyle.Fill;
@@ -832,6 +850,10 @@
             dlgSaveFile.DefaultExt = "*.csv";
             dlgSaveFile.Filter = "CSV files|*.csv";
             // 
+            // dlgDirSelect
+            // 
+            dlgDirSelect.Description = "Vyberte adresář do kterého se vygeneruje struktura repository";
+            // 
             // FormProductEdit
             // 
             AutoScaleDimensions = new SizeF(7F, 15F);
@@ -962,5 +984,8 @@
         private FolderBrowserDialog dlgOpenDir;
         private ColumnHeader colprdSku;
         private SaveFileDialog dlgSaveFile;
+        private ToolStripSeparator toolStripSeparator11;
+        private ToolStripButton tbbutGenerateRepo;
+        private FolderBrowserDialog dlgDirSelect;
     }
 }

+ 62 - 5
FormProductEdit.cs

@@ -76,12 +76,21 @@ namespace qdr.app.studiou.orders2printpack
             _storage.AppendCategoriesFromString(AppSettings.Default.PredefinedCategories);
             _currentDetailProduct = null;
             if (dlgSaveFile.ShowDialog() == DialogResult.OK)
-               SaveProductFile(dlgSaveFile.FileName);
+                SaveProductFile(dlgSaveFile.FileName);
 
             ClearDetail();
             RefreshViews();
             RefreshTools();
         }
+
+        private void tbbutGenerateRepo_Click(object sender, EventArgs e)
+        {
+            if (dlgDirSelect.ShowDialog() == DialogResult.OK)
+            {
+                GenerateRepository(dlgDirSelect.SelectedPath);
+            }
+        }
+
         private void tbbutOpen_Click(object sender, EventArgs e)
         {
             if (dlgOpenFile.ShowDialog() == DialogResult.OK)
@@ -289,7 +298,7 @@ namespace qdr.app.studiou.orders2printpack
                 {
                     if (!data.IsValid)
                         lvItem.BackColor = Color.IndianRed;
-                    
+
                 });
                 lvProducts.RestoreSelection();
             });
@@ -343,6 +352,9 @@ namespace qdr.app.studiou.orders2printpack
                 _currentDetailCategory = category;
             }
         }
+
+
+
         #endregion
 
         #region *** Operations ***
@@ -537,12 +549,13 @@ namespace qdr.app.studiou.orders2printpack
                     return;
 
                 data.ProductName = tbdetName.Text;
-                if (!string.Equals(data.Sku,tbdetSku.Text,StringComparison.CurrentCultureIgnoreCase)){
+                if (!string.Equals(data.Sku, tbdetSku.Text, StringComparison.CurrentCultureIgnoreCase))
+                {
                     if (_storage.Products.Any(x => string.Equals(x.Sku, tbdetSku.Text, StringComparison.CurrentCultureIgnoreCase)))
                         throw new Exception($"Produkt se zadaným SKU '{tbdetSku.Text}' již existuje!");
                     if (!data.IsVariant)
                     {
-                        foreach(ProductDto item in _storage.Products.Where(x=>x.IsVariant && string.Equals(x.ParentName, data.Sku, StringComparison.CurrentCultureIgnoreCase)))
+                        foreach (ProductDto item in _storage.Products.Where(x => x.IsVariant && string.Equals(x.ParentName, data.Sku, StringComparison.CurrentCultureIgnoreCase)))
                         {
                             item.ParentName = tbdetSku.Text;
                         }
@@ -600,6 +613,49 @@ namespace qdr.app.studiou.orders2printpack
                 }
             });
         }
+
+        private void GenerateRepository(string selectedPath)
+        {
+            int skipedCnt = 0;
+            int createdCnt = 0;
+            BlockErrorHandled(() =>
+           {
+               if (!Directory.Exists(selectedPath))
+                   throw new Exception($"Složka '{selectedPath}' neexistuje.");
+
+
+
+               foreach (var category in _storage.Categories)
+               {
+                   var fullPath = Path.Combine(selectedPath, category.Name);
+                   if (!Directory.Exists(fullPath))
+                   {
+                       Directory.CreateDirectory(fullPath);
+                       createdCnt++;
+                   }
+                   else
+                   {
+                       skipedCnt++;
+                   }
+
+                   foreach (var variant in _storage.Variants)
+                   {
+                       var variantPath = Path.Combine(fullPath, variant.Name);
+                       if (!Directory.Exists(variantPath))
+                       {
+                           Directory.CreateDirectory(variantPath);
+                           createdCnt++;
+                       }
+                       else
+                       {
+                           skipedCnt++;
+                       }
+                   }
+               }
+           });
+
+            MessageBox.Show($"Bylo vytvořeno {createdCnt} složek, {skipedCnt} již existovalo.", "Hotovo", MessageBoxButtons.OK, MessageBoxIcon.Information);
+        }
         private void AddNewVariant()
         {
             BlockErrorHandled(() =>
@@ -733,7 +789,7 @@ namespace qdr.app.studiou.orders2printpack
                 var fsrch = new FileSearch(selectedPath, true);
                 var filesCache = new List<string>();
 
-                var files = fsrch.Search(new[] {AppSettings.Default.SourceSearchPattern , "*" });
+                var files = fsrch.Search(new[] { AppSettings.Default.SourceSearchPattern, "*" });
                 if (files.Length == 0)
                     throw new Exception($"Nenalezeny žádné soubory pro zpracování ve složce '{selectedPath}'.");
                 // construct list of files
@@ -815,6 +871,7 @@ namespace qdr.app.studiou.orders2printpack
         }
         #endregion
 
+
     }
 
 }

+ 13 - 1
FormProductEdit.resx

@@ -158,6 +158,15 @@
         J/+f6DYF0yA+yQac6Db5f6hWCmwIiE+mC0wIu2DS2Vf/F1x6DefjwlgNyNr34r/0wkdgTMgQDAOQNRNj
         CIoBOg0rMTTDMLIhIHbriZeYBmDTiIxBGkEYxge5liQDsGGQqykyAISpZwAlmIEywMAAAAc1/Jwvt6sN
         AAAAAElFTkSuQmCC
+</value>
+  </data>
+  <data name="tbbutGenerateRepo.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+        YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACRSURBVDhPY/j27dt/SjDYACcnJ7IwigEf3n8kCZNswPNb
+        J/+f6DYF0yA+yQac6Db5f6hWCmwIiE+mC0wIu2DS2Vf/F1x6DefjwlgNyNr34r/0wkdgTMgQDAOQNRNj
+        CIoBOg0rMTTDMLIhIHbriZeYBmDTiIxBGkEYxge5liQDsGGQqykyAISpZwAlmIEywMAAAAc1/Jwvt6sN
+        AAAAAElFTkSuQmCC
 </value>
   </data>
   <metadata name="tsProducts.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -307,8 +316,11 @@
   <metadata name="dlgSaveFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>860, 23</value>
   </metadata>
+  <metadata name="dlgDirSelect.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 64</value>
+  </metadata>
   <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>58</value>
+    <value>135</value>
   </metadata>
   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>

+ 13 - 13
Properties/AppSettings.Designer.cs

@@ -240,19 +240,6 @@ namespace qdr.app.studiou.orders2printpack.Properties {
             }
         }
         
-        [global::System.Configuration.UserScopedSettingAttribute()]
-        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("^^18^**Objednávka: {order_no}**^^{cr}^^14^**{prod_cat}**^^{cr}{prod_var_type}{cr}" +
-            "Počet: {qty\r\n}")]
-        public string LabelTemplate {
-            get {
-                return ((string)(this["LabelTemplate"]));
-            }
-            set {
-                this["LabelTemplate"] = value;
-            }
-        }
-        
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("200")]
@@ -300,5 +287,18 @@ namespace qdr.app.studiou.orders2printpack.Properties {
                 this["LabelPerCol"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("^^18^**Objednávka: {order_no}**^^{cr}^^14^**{prod_cat}**^^{cr}{prod_var_type}{cr}" +
+            "Počet: {qty}")]
+        public string LabelTemplate {
+            get {
+                return ((string)(this["LabelTemplate"]));
+            }
+            set {
+                this["LabelTemplate"] = value;
+            }
+        }
     }
 }

+ 3 - 4
Properties/AppSettings.settings

@@ -57,10 +57,6 @@
     <Setting Name="MapColProductFormat" Type="System.String" Scope="User">
       <Value Profile="(Default)">prod_var_type</Value>
     </Setting>
-    <Setting Name="LabelTemplate" Type="System.String" Scope="User">
-      <Value Profile="(Default)">^^18^**Objednávka: {order_no}**^^{cr}^^14^**{prod_cat}**^^{cr}{prod_var_type}{cr}Počet: {qty
-}</Value>
-    </Setting>
     <Setting Name="LabelWidth" Type="System.String" Scope="User">
       <Value Profile="(Default)">200</Value>
     </Setting>
@@ -73,5 +69,8 @@
     <Setting Name="LabelPerCol" Type="System.String" Scope="User">
       <Value Profile="(Default)">8</Value>
     </Setting>
+    <Setting Name="LabelTemplate" Type="System.String" Scope="User">
+      <Value Profile="(Default)">^^18^**Objednávka: {order_no}**^^{cr}^^14^**{prod_cat}**^^{cr}{prod_var_type}{cr}Počet: {qty}</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

+ 1 - 0
README.md

@@ -7,6 +7,7 @@ Proprietální řešení zpracování WooCommerce objednávek pro online tiskovo
 ### 1.2.0 (2025-03-13)
 - Upgrade na .NET 9.0
 - Přidána podpora pro tisk štítků podle importovaného .CSV do xlsx (Excel)
+- Přidána funkce generování repository v Editaci Produktů
 
 ### 1.1.1 (2025-03-13)
 - Opraveno, Nový a Uložit otevře dialog pro uložení