55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Win32;
|
|
using System.IO;
|
|
|
|
namespace RhSolutions.Services;
|
|
|
|
public class AddInConfiguration : IAddInConfiguration
|
|
{
|
|
private IConfiguration _configuration;
|
|
private RegistryKey _rootKey;
|
|
private string _priceListPath;
|
|
private Dictionary<string, string> settingsValues;
|
|
|
|
public string this[string key]
|
|
{
|
|
get => _configuration[key];
|
|
}
|
|
|
|
public event IAddInConfiguration.SettingsHandler OnSettingsChange;
|
|
|
|
public AddInConfiguration()
|
|
{
|
|
_configuration = new ConfigurationBuilder()
|
|
.AddUserSecrets<RhSolutionsAddIn>()
|
|
.AddEnvironmentVariables("RHS_ADDIN__")
|
|
.Build();
|
|
|
|
_rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");
|
|
_priceListPath = (string)_rootKey.GetValue("PriceListPath");
|
|
settingsValues = new()
|
|
{
|
|
["Amount"] = "Кол-во",
|
|
["OldSku"] = "Прежний материал",
|
|
["Sku"] = "Актуальный материал",
|
|
["ProductLine"] = "Программа",
|
|
["Name"] = "Наименование",
|
|
["Measure"] = "Ед. изм."
|
|
};
|
|
}
|
|
|
|
public string GetPriceListFileName() => Path.GetFileName(_priceListPath);
|
|
public Dictionary<string, string> GetPriceListHeaders() => settingsValues;
|
|
public string GetPriceListPath() => _priceListPath;
|
|
|
|
public void SaveSettings()
|
|
{
|
|
_rootKey.SetValue("PriceListPath", _priceListPath);
|
|
OnSettingsChange.Invoke();
|
|
}
|
|
|
|
public void SetPriceListPath(string value)
|
|
{
|
|
_priceListPath = value;
|
|
}
|
|
} |