Add Registry Util

This commit is contained in:
Sergey Chebotar 2021-12-22 08:26:54 +03:00
parent aaaa6b4585
commit f97d344f39
5 changed files with 31 additions and 67 deletions

View File

@ -16,9 +16,7 @@ namespace RehauSku
public class AddIn : IExcelAddIn public class AddIn : IExcelAddIn
{ {
public static readonly HttpClient httpClient = new HttpClient(); public static HttpClient httpClient = new HttpClient();
public static ResponseOrder StoreResponseOrder = RegistryUtil.StoreResponseOrder;
public static string PriceListPath = RegistryUtil.PriceListPath;
public void AutoOpen() public void AutoOpen()
{ {

View File

@ -5,16 +5,16 @@ namespace RehauSku
{ {
public class Functions public class Functions
{ {
[ExcelFunction(Description = "Получение названия первого продукта по запросу в интернет-магазин REHAU")] [ExcelFunction(description: "Получение названия первого продукта в поиске")]
public static object RAUNAME([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) public static object RAUNAME([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
=> MakeRequest(request, ProductField.Name); => MakeRequest(request, ProductField.Name);
[ExcelFunction(Description = "Получение артикула первого продукта по запросу в интернет-магазин REHAU")] [ExcelFunction(Description = "Получение артикула первого продукта в поиске")]
public static object RAUSKU([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) public static object RAUSKU([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
=> MakeRequest(request, ProductField.Id); => MakeRequest(request, ProductField.Id);
[ExcelFunction(Description = "Получение цены первого продукта по запросу в интернет-магазин REHAU")] [ExcelFunction(Description = "Получение цены первого продукта в поиске")]
public static object RAUPRICE([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) public static object RAUPRICE([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
=> MakeRequest(request, ProductField.Price); => MakeRequest(request, ProductField.Price);
private static object MakeRequest(string request, ProductField field) private static object MakeRequest(string request, ProductField field)

View File

@ -6,71 +6,37 @@ namespace RehauSku
{ {
public static string PriceListPath public static string PriceListPath
{ {
get get => (string)_RootKey.GetValue("PriceListPath");
{
_GetRootKey();
if (_RootKey == null)
{
return @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm";
}
else return (string)_RootKey.GetValue("PriceListPath");
}
private set
{
_GetRootKey();
if (_RootKey == null)
{
RegistryKey PriceListPath = Registry.CurrentUser
.CreateSubKey("SOFTWARE")
.CreateSubKey("REHAU")
.CreateSubKey("SkuAssist");
}
_RootKey.SetValue("PriceListPath", value);
}
} }
public static ResponseOrder StoreResponseOrder public static ResponseOrder StoreResponseOrder
{
get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder");
}
private static RegistryKey _RootKey
{ {
get get
{ {
_GetRootKey(); return _OpenRootKey() ?? _CreateRootKey();
if (_RootKey == null)
{
return ResponseOrder.Default;
}
return (ResponseOrder)_RootKey.GetValue("ResponseOrder");
}
private set
{
if (_RootKey == null)
{
RegistryKey PriceListPath = Registry.CurrentUser
.CreateSubKey("SOFTWARE")
.CreateSubKey("REHAU")
.CreateSubKey("SkuAssist");
}
_RootKey.SetValue("ResponseOrder", value);
} }
} }
private static RegistryKey _RootKey { get; set; } private static RegistryKey _OpenRootKey()
private static void _GetRootKey()
{ {
_RootKey = Registry return Registry.CurrentUser
.CurrentUser .OpenSubKey(@"SOFTWARE\REHAU\SkuAssist");
.OpenSubKey("SOFTWARE") }
.OpenSubKey("REHAU")
.OpenSubKey("SkuAssist"); private static RegistryKey _CreateRootKey()
{
RegistryKey key = Registry.CurrentUser
.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm");
key.SetValue("StoreResponseOrder", 0);
return key;
} }
} }
} }

View File

@ -28,7 +28,7 @@ namespace RehauSku.Assistant
baseUri.Path = "/catalogsearch/result/index/"; baseUri.Path = "/catalogsearch/result/index/";
string cleanedRequest = request.CleanRequest(); string cleanedRequest = request.CleanRequest();
switch (AddIn.StoreResponseOrder) switch (RegistryUtil.StoreResponseOrder)
{ {
case ResponseOrder.Relevance: case ResponseOrder.Relevance:
baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest; baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest;

View File

@ -76,7 +76,7 @@ namespace RehauSku.DataExport
public void FillPriceList() public void FillPriceList()
{ {
string exportFile = _GetExportFullPath(); string exportFile = _GetExportFullPath();
File.Copy(AddIn.PriceListPath, exportFile, true); File.Copy(RegistryUtil.PriceListPath, exportFile, true);
Workbook wb = xlApp.Workbooks.Open(exportFile); Workbook wb = xlApp.Workbooks.Open(exportFile);
Worksheet ws = wb.ActiveSheet; Worksheet ws = wb.ActiveSheet;
@ -94,7 +94,7 @@ namespace RehauSku.DataExport
private string _GetExportFullPath() private string _GetExportFullPath()
{ {
string fileExtension = Path.GetExtension(AddIn.PriceListPath); string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath);
return Path.GetTempFileName() + fileExtension; return Path.GetTempFileName() + fileExtension;
} }