From da29243d1d661a6e304018e3317c2ca4ea495db8 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sat, 1 Apr 2023 15:24:04 +0300 Subject: [PATCH] Add Pricelist Headers to configuration --- RhSolutions.AddIn/Models/PriceListHeaders.cs | 11 -- RhSolutions.AddIn/Models/SourcePriceList.cs | 13 +- RhSolutions.AddIn/Models/TargetPriceList.cs | 15 +- .../Models/WorksheetExtensions.cs | 14 +- .../Services/AddInConfiguration.cs | 128 +++++++++++++----- .../Services/IAddInConfiguration.cs | 18 +-- 6 files changed, 131 insertions(+), 68 deletions(-) delete mode 100644 RhSolutions.AddIn/Models/PriceListHeaders.cs diff --git a/RhSolutions.AddIn/Models/PriceListHeaders.cs b/RhSolutions.AddIn/Models/PriceListHeaders.cs deleted file mode 100644 index c9a8370..0000000 --- a/RhSolutions.AddIn/Models/PriceListHeaders.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RhSolutions.Models -{ - internal static class PriceListHeaders - { - public static readonly string Amount = "Кол-во"; - public static readonly string OldSku = "Прежний материал"; - public static readonly string Sku = "Актуальный материал"; - public static readonly string Group = "Программа"; - public static readonly string Name = "Наименование"; - } -} \ No newline at end of file diff --git a/RhSolutions.AddIn/Models/SourcePriceList.cs b/RhSolutions.AddIn/Models/SourcePriceList.cs index d6c2cfe..db691ec 100644 --- a/RhSolutions.AddIn/Models/SourcePriceList.cs +++ b/RhSolutions.AddIn/Models/SourcePriceList.cs @@ -1,4 +1,5 @@ -using System.IO; +using RhSolutions.AddIn; +using System.IO; namespace RhSolutions.Models; @@ -16,12 +17,14 @@ internal class SourcePriceList : PriceListBase Sheet = workbook.ActiveSheet; Name = Path.GetFileNameWithoutExtension(workbook.FullName); + var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters(); + Range[] cells = new[] { - AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount), - SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku), - GroupCell = Sheet.Cells.Find(PriceListHeaders.Group), - NameCell = Sheet.Cells.Find(PriceListHeaders.Name) + AmountCell = Sheet.Cells.Find(pricelistParameters["Amount"]), + SkuCell = Sheet.Cells.Find(pricelistParameters["Sku"]), + GroupCell = Sheet.Cells.Find(pricelistParameters["Group"]), + NameCell = Sheet.Cells.Find(pricelistParameters["Name"]) }; if (cells.Any(x => x == null)) diff --git a/RhSolutions.AddIn/Models/TargetPriceList.cs b/RhSolutions.AddIn/Models/TargetPriceList.cs index 254b5b0..15ba066 100644 --- a/RhSolutions.AddIn/Models/TargetPriceList.cs +++ b/RhSolutions.AddIn/Models/TargetPriceList.cs @@ -1,4 +1,5 @@ -using System.IO; +using RhSolutions.AddIn; +using System.IO; namespace RhSolutions.Models; @@ -17,15 +18,17 @@ internal class TargetPriceList : PriceListBase Sheet = workbook.ActiveSheet; Name = Path.GetFileNameWithoutExtension(workbook.FullName); + var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters(); + Range[] cells = new[] { - AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount), - SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku), - GroupCell = Sheet.Cells.Find(PriceListHeaders.Group), - NameCell = Sheet.Cells.Find(PriceListHeaders.Name) + AmountCell = Sheet.Cells.Find(pricelistParameters["Amount"]), + SkuCell = Sheet.Cells.Find(pricelistParameters["Sku"]), + GroupCell = Sheet.Cells.Find(pricelistParameters["Group"]), + NameCell = Sheet.Cells.Find(pricelistParameters["Name"]) }; - OldSkuCell = Sheet.Cells.Find(PriceListHeaders.OldSku); + OldSkuCell = Sheet.Cells.Find(pricelistParameters["OldSku"]); if (cells.Any(x => x == null)) { diff --git a/RhSolutions.AddIn/Models/WorksheetExtensions.cs b/RhSolutions.AddIn/Models/WorksheetExtensions.cs index 24968e2..da38203 100644 --- a/RhSolutions.AddIn/Models/WorksheetExtensions.cs +++ b/RhSolutions.AddIn/Models/WorksheetExtensions.cs @@ -1,4 +1,6 @@ -namespace RhSolutions.Services; +using RhSolutions.AddIn; + +namespace RhSolutions.Services; public static class WorksheetExtensions { @@ -9,12 +11,14 @@ public static class WorksheetExtensions Range groupCell; Range nameCell; + var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters(); + Range[] cells = new[] { - amountCell = worksheet.Cells.Find(PriceListHeaders.Amount), - skuCell = worksheet.Cells.Find(PriceListHeaders.Sku), - groupCell = worksheet.Cells.Find(PriceListHeaders.Group), - nameCell = worksheet.Cells.Find(PriceListHeaders.Name) + amountCell = worksheet.Cells.Find(pricelistParameters["Amount"]), + skuCell = worksheet.Cells.Find(pricelistParameters["Sku"]), + groupCell = worksheet.Cells.Find(pricelistParameters["Group"]), + nameCell = worksheet.Cells.Find(pricelistParameters["Name"]) }; return cells.All(x => x != null); diff --git a/RhSolutions.AddIn/Services/AddInConfiguration.cs b/RhSolutions.AddIn/Services/AddInConfiguration.cs index 6b4be5f..970cf52 100644 --- a/RhSolutions.AddIn/Services/AddInConfiguration.cs +++ b/RhSolutions.AddIn/Services/AddInConfiguration.cs @@ -1,39 +1,103 @@ -using System; -using System.Configuration; +using System.Configuration; using System.IO; -namespace RhSolutions.Services +namespace RhSolutions.Services; + +public class AddInConfiguration : ApplicationSettingsBase, IAddInConfiguration { - public class AddInConfiguration : ApplicationSettingsBase, IAddInConfiguration + private Dictionary _priceListParameters; + + public AddInConfiguration() { - [UserScopedSetting] - public string PriceListPath + _priceListParameters = new Dictionary() { - get - { - return (string)this[nameof(PriceListPath)]; - } - set - { - this[nameof(PriceListPath)] = value; - } - } - - public event SettingChangingEventHandler OnSettingsChange - { - add - { - base.SettingChanging += value; - } - remove - { - base.SettingChanging -= value; - } - } - - public string GetPriceListFileName() => Path.GetFileName(PriceListPath); - public string GetPriceListPath() => PriceListPath; - public void SetPriceListPath(string value) => PriceListPath = value; - public void SaveSettings() => base.Save(); + ["Amount"] = AmountHeader, + ["OldSku"] = OldSkuHeader, + ["Sku"] = SkuHeader, + ["Group"] = GroupHeader, + ["Name"] = NameHeader + }; } + + [UserScopedSetting] + [DefaultSettingValue("Кол-во")] + public string AmountHeader + { + get + { + return (string)this[nameof(AmountHeader)]; + } + } + + [UserScopedSetting] + [DefaultSettingValue("Прежний материал")] + public string OldSkuHeader + { + get + { + return (string)this[nameof(OldSkuHeader)]; + } + } + + + [UserScopedSetting] + [DefaultSettingValue("Актуальный материал")] + public string SkuHeader + { + get + { + return (string)this[nameof(SkuHeader)]; + } + } + + [UserScopedSetting] + [DefaultSettingValue("Программа")] + public string GroupHeader + { + get + { + return (string)this[nameof(GroupHeader)]; + } + } + + [UserScopedSetting] + [DefaultSettingValue("Наименование")] + public string NameHeader + { + get + { + return (string)this[nameof(NameHeader)]; + } + } + + [UserScopedSetting] + public string PriceListPath + { + get + { + return (string)this[nameof(PriceListPath)]; + } + set + { + this[nameof(PriceListPath)] = value; + } + } + + public event SettingChangingEventHandler OnSettingsChange + { + add + { + base.SettingChanging += value; + } + remove + { + base.SettingChanging -= value; + } + } + + public string GetPriceListFileName() => Path.GetFileName(PriceListPath); + public string GetPriceListPath() => PriceListPath; + public void SetPriceListPath(string value) => PriceListPath = value; + public void SaveSettings() => base.Save(); + public Dictionary GetPriceListParameters() => _priceListParameters; } diff --git a/RhSolutions.AddIn/Services/IAddInConfiguration.cs b/RhSolutions.AddIn/Services/IAddInConfiguration.cs index c6bed6a..3c09007 100644 --- a/RhSolutions.AddIn/Services/IAddInConfiguration.cs +++ b/RhSolutions.AddIn/Services/IAddInConfiguration.cs @@ -1,13 +1,13 @@ using System.Configuration; -namespace RhSolutions.Services +namespace RhSolutions.Services; + +public interface IAddInConfiguration { - public interface IAddInConfiguration - { - public string GetPriceListPath(); - public string GetPriceListFileName(); - public event SettingChangingEventHandler OnSettingsChange; - public void SetPriceListPath(string value); - public void SaveSettings(); - } + public string GetPriceListPath(); + public string GetPriceListFileName(); + public Dictionary GetPriceListParameters(); + public event SettingChangingEventHandler OnSettingsChange; + public void SetPriceListPath(string value); + public void SaveSettings(); } \ No newline at end of file