aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2023-11-12 16:31:26 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2023-11-12 16:31:26 +0300
commite6546254baf8130638aa0dee12f247769da4e308 (patch)
tree74753e82634edbf417892460082ec11c7bb01440
parent02d0b21a5896ea3323511240652ba8c5fd9671c5 (diff)
Save Configuration to registry
-rw-r--r--RhSolutions.AddIn/Services/AddInConfiguration.cs121
-rw-r--r--RhSolutions.AddIn/Services/IAddInConfiguration.cs9
-rw-r--r--RhSolutions.AddIn/Tools/EventsUtil.cs74
3 files changed, 64 insertions, 140 deletions
diff --git a/RhSolutions.AddIn/Services/AddInConfiguration.cs b/RhSolutions.AddIn/Services/AddInConfiguration.cs
index 363c3f3..73b9a5b 100644
--- a/RhSolutions.AddIn/Services/AddInConfiguration.cs
+++ b/RhSolutions.AddIn/Services/AddInConfiguration.cs
@@ -1,114 +1,43 @@
-using System.Configuration;
+using Microsoft.Win32;
using System.IO;
namespace RhSolutions.Services;
-public class AddInConfiguration : ApplicationSettingsBase, IAddInConfiguration
+public class AddInConfiguration : IAddInConfiguration
{
- private readonly Dictionary<string, string> _priceListHeaders;
+ private RegistryKey _rootKey;
+ private string _priceListPath;
+ private Dictionary<string, string> _priceListHeaders;
+
+ public event IAddInConfiguration.SettingsHandler OnSettingsChange;
public AddInConfiguration()
{
- _priceListHeaders = new Dictionary<string, string>()
+ _rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");
+ _priceListPath = (string)_rootKey.GetValue("PriceListPath");
+ _priceListHeaders = new()
{
- ["Amount"] = AmountHeader,
- ["OldSku"] = OldSkuHeader,
- ["Sku"] = SkuHeader,
- ["ProductLine"] = ProductLineHeader,
- ["Name"] = NameHeader,
- ["Measure"] = MeasureHeader
+ ["Amount"] = "Кол-во",
+ ["OldSku"] = "Прежний материал",
+ ["Sku"] = "Актуальный материал",
+ ["ProductLine"] = "Программа",
+ ["Name"] = "Наименование",
+ ["Measure"] = "Ед. изм."
};
}
- [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 ProductLineHeader
- {
- get
- {
- return (string)this[nameof(ProductLineHeader)];
- }
- }
-
- [UserScopedSetting]
- [DefaultSettingValue("Наименование")]
- public string NameHeader
- {
- get
- {
- return (string)this[nameof(NameHeader)];
- }
- }
-
- [UserScopedSetting]
- [DefaultSettingValue("Ед. изм.")]
- public string MeasureHeader
- {
- get
- {
- return (string)this[nameof(MeasureHeader)];
- }
- }
+ public string GetPriceListFileName() => Path.GetFileName(_priceListPath);
+ public Dictionary<string, string> GetPriceListHeaders() => _priceListHeaders;
+ public string GetPriceListPath() => _priceListPath;
- [UserScopedSetting]
- public string PriceListPath
+ public void SaveSettings()
{
- get
- {
- return (string)this[nameof(PriceListPath)];
- }
- set
- {
- this[nameof(PriceListPath)] = value;
- }
+ _rootKey.SetValue("PriceListPath", _priceListPath);
+ OnSettingsChange.Invoke();
}
- public event SettingChangingEventHandler OnSettingsChange
+ public void SetPriceListPath(string value)
{
- add
- {
- base.SettingChanging += value;
- }
- remove
- {
- base.SettingChanging -= value;
- }
+ _priceListPath = 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<string, string> GetPriceListHeaders() => _priceListHeaders;
-}
+} \ No newline at end of file
diff --git a/RhSolutions.AddIn/Services/IAddInConfiguration.cs b/RhSolutions.AddIn/Services/IAddInConfiguration.cs
index 4eb79f1..e19da3d 100644
--- a/RhSolutions.AddIn/Services/IAddInConfiguration.cs
+++ b/RhSolutions.AddIn/Services/IAddInConfiguration.cs
@@ -1,13 +1,12 @@
-using System.Configuration;
-
-namespace RhSolutions.Services;
+namespace RhSolutions.Services;
public interface IAddInConfiguration
{
public string GetPriceListPath();
+ public void SetPriceListPath(string value);
public string GetPriceListFileName();
public Dictionary<string, string> GetPriceListHeaders();
- public event SettingChangingEventHandler OnSettingsChange;
- public void SetPriceListPath(string value);
+ public delegate void SettingsHandler();
+ public event SettingsHandler OnSettingsChange;
public void SaveSettings();
} \ No newline at end of file
diff --git a/RhSolutions.AddIn/Tools/EventsUtil.cs b/RhSolutions.AddIn/Tools/EventsUtil.cs
index e62de23..6723835 100644
--- a/RhSolutions.AddIn/Tools/EventsUtil.cs
+++ b/RhSolutions.AddIn/Tools/EventsUtil.cs
@@ -1,52 +1,48 @@
-using Microsoft.Office.Interop.Excel;
-using RhSolutions.AddIn;
-using RhSolutions.Controllers;
-using System.Configuration;
+using RhSolutions.Controllers;
#if !NET472
using System.Runtime.Versioning;
#endif
-namespace RhSolutions.Tools
-{
+namespace RhSolutions.Tools;
+
#if !NET472
- [SupportedOSPlatform("windows")]
+[SupportedOSPlatform("windows")]
#endif
- internal static class EventsUtil
+internal static class EventsUtil
+{
+ public static void Initialize()
{
- public static void Initialize()
- {
- RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
- RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
- RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
- RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
- }
+ RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
+ RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
+ RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
+ RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
+ }
- public static void Uninitialize()
- {
- RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
- RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
- RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
- RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
- }
+ public static void Uninitialize()
+ {
+ RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
+ RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
+ RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
+ RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
+ }
- private static void RefreshButtons(object sh)
- {
- RibbonController.UpdateWorkbookValidation();
- RibbonController.RefreshControl("convert");
- RibbonController.RefreshControl("dxfexport");
- RibbonController.RefreshControl("guess");
- RibbonController.RefreshControl("fillsleeves");
- RibbonController.RefreshControl("fillcouplings");
- }
+ private static void RefreshButtons(object sh)
+ {
+ RibbonController.UpdateWorkbookValidation();
+ RibbonController.RefreshControl("convert");
+ RibbonController.RefreshControl("dxfexport");
+ RibbonController.RefreshControl("guess");
+ RibbonController.RefreshControl("fillsleeves");
+ RibbonController.RefreshControl("fillcouplings");
+ }
- private static void RefreshExportButton(object sh, Range target)
- {
- RibbonController.RefreshControl("export");
- }
+ private static void RefreshExportButton(object sh, Range target)
+ {
+ RibbonController.RefreshControl("export");
+ }
- private static void RefreshSettingTitle(object sender, SettingChangingEventArgs e)
- {
- RibbonController.RefreshControl("setPriceList");
- }
+ private static void RefreshSettingTitle()
+ {
+ RibbonController.RefreshControl("setPriceList");
}
}