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;
|
using System.IO;
|
||||||
|
|
||||||
namespace RhSolutions.Services;
|
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()
|
public AddInConfiguration()
|
||||||
{
|
{
|
||||||
_priceListHeaders = new Dictionary<string, string>()
|
_rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");
|
||||||
|
_priceListPath = (string)_rootKey.GetValue("PriceListPath");
|
||||||
|
_priceListHeaders = new()
|
||||||
{
|
{
|
||||||
["Amount"] = AmountHeader,
|
["Amount"] = "Кол-во",
|
||||||
["OldSku"] = OldSkuHeader,
|
["OldSku"] = "Прежний материал",
|
||||||
["Sku"] = SkuHeader,
|
["Sku"] = "Актуальный материал",
|
||||||
["ProductLine"] = ProductLineHeader,
|
["ProductLine"] = "Программа",
|
||||||
["Name"] = NameHeader,
|
["Name"] = "Наименование",
|
||||||
["Measure"] = MeasureHeader
|
["Measure"] = "Ед. изм."
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[UserScopedSetting]
|
public string GetPriceListFileName() => Path.GetFileName(_priceListPath);
|
||||||
[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 Dictionary<string, string> GetPriceListHeaders() => _priceListHeaders;
|
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 interface IAddInConfiguration
|
||||||
{
|
{
|
||||||
public string GetPriceListPath();
|
public string GetPriceListPath();
|
||||||
|
public void SetPriceListPath(string value);
|
||||||
public string GetPriceListFileName();
|
public string GetPriceListFileName();
|
||||||
public Dictionary<string, string> GetPriceListHeaders();
|
public Dictionary<string, string> GetPriceListHeaders();
|
||||||
public event SettingChangingEventHandler OnSettingsChange;
|
public delegate void SettingsHandler();
|
||||||
public void SetPriceListPath(string value);
|
public event SettingsHandler OnSettingsChange;
|
||||||
public void SaveSettings();
|
public void SaveSettings();
|
||||||
}
|
}
|
@ -1,52 +1,48 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using RhSolutions.Controllers;
|
||||||
using RhSolutions.AddIn;
|
|
||||||
using RhSolutions.Controllers;
|
|
||||||
using System.Configuration;
|
|
||||||
#if !NET472
|
#if !NET472
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace RhSolutions.Tools
|
namespace RhSolutions.Tools;
|
||||||
{
|
|
||||||
#if !NET472
|
#if !NET472
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
#endif
|
#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.SheetSelectionChange += RefreshExportButton;
|
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
|
||||||
RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
|
RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
|
||||||
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
|
}
|
||||||
RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Uninitialize()
|
public static void Uninitialize()
|
||||||
{
|
{
|
||||||
RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
|
RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
|
||||||
RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
|
RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
|
||||||
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
|
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
|
||||||
RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
|
RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshButtons(object sh)
|
private static void RefreshButtons(object sh)
|
||||||
{
|
{
|
||||||
RibbonController.UpdateWorkbookValidation();
|
RibbonController.UpdateWorkbookValidation();
|
||||||
RibbonController.RefreshControl("convert");
|
RibbonController.RefreshControl("convert");
|
||||||
RibbonController.RefreshControl("dxfexport");
|
RibbonController.RefreshControl("dxfexport");
|
||||||
RibbonController.RefreshControl("guess");
|
RibbonController.RefreshControl("guess");
|
||||||
RibbonController.RefreshControl("fillsleeves");
|
RibbonController.RefreshControl("fillsleeves");
|
||||||
RibbonController.RefreshControl("fillcouplings");
|
RibbonController.RefreshControl("fillcouplings");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshExportButton(object sh, Range target)
|
private static void RefreshExportButton(object sh, Range target)
|
||||||
{
|
{
|
||||||
RibbonController.RefreshControl("export");
|
RibbonController.RefreshControl("export");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshSettingTitle(object sender, SettingChangingEventArgs e)
|
private static void RefreshSettingTitle()
|
||||||
{
|
{
|
||||||
RibbonController.RefreshControl("setPriceList");
|
RibbonController.RefreshControl("setPriceList");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user