Save Configuration to registry
This commit is contained in:
parent
02d0b21a58
commit
e6546254ba
@ -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)];
|
||||
}
|
||||
}
|
||||
|
||||
[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 string GetPriceListFileName() => Path.GetFileName(_priceListPath);
|
||||
public Dictionary<string, string> GetPriceListHeaders() => _priceListHeaders;
|
||||
public string GetPriceListPath() => _priceListPath;
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
_rootKey.SetValue("PriceListPath", _priceListPath);
|
||||
OnSettingsChange.Invoke();
|
||||
}
|
||||
|
||||
public void SetPriceListPath(string value)
|
||||
{
|
||||
_priceListPath = value;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -1,18 +1,15 @@
|
||||
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()
|
||||
{
|
||||
RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
|
||||
@ -44,9 +41,8 @@ namespace RhSolutions.Tools
|
||||
RibbonController.RefreshControl("export");
|
||||
}
|
||||
|
||||
private static void RefreshSettingTitle(object sender, SettingChangingEventArgs e)
|
||||
private static void RefreshSettingTitle()
|
||||
{
|
||||
RibbonController.RefreshControl("setPriceList");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user