2021-12-03 12:57:22 +03:00
|
|
|
|
using ExcelDna.Integration;
|
2021-12-08 14:45:14 +03:00
|
|
|
|
using RehauSku.Assistant;
|
2021-11-11 16:33:40 +03:00
|
|
|
|
|
2021-12-08 14:45:14 +03:00
|
|
|
|
namespace RehauSku
|
2021-11-11 16:33:40 +03:00
|
|
|
|
{
|
2021-11-29 15:50:24 +03:00
|
|
|
|
public class Functions
|
2021-11-11 16:33:40 +03:00
|
|
|
|
{
|
2021-12-22 08:26:54 +03:00
|
|
|
|
[ExcelFunction(description: "Получение названия первого продукта в поиске")]
|
|
|
|
|
public static object RAUNAME([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
|
2021-12-13 20:39:41 +03:00
|
|
|
|
=> MakeRequest(request, ProductField.Name);
|
2021-12-03 14:15:16 +03:00
|
|
|
|
|
2021-12-22 08:26:54 +03:00
|
|
|
|
[ExcelFunction(Description = "Получение артикула первого продукта в поиске")]
|
|
|
|
|
public static object RAUSKU([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
|
2021-12-13 20:39:41 +03:00
|
|
|
|
=> MakeRequest(request, ProductField.Id);
|
2021-12-03 14:15:16 +03:00
|
|
|
|
|
2021-12-22 08:26:54 +03:00
|
|
|
|
[ExcelFunction(Description = "Получение цены первого продукта в поиске")]
|
|
|
|
|
public static object RAUPRICE([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
|
2021-12-13 20:39:41 +03:00
|
|
|
|
=> MakeRequest(request, ProductField.Price);
|
|
|
|
|
|
|
|
|
|
private static object MakeRequest(string request, ProductField field)
|
|
|
|
|
{
|
|
|
|
|
object result;
|
|
|
|
|
|
|
|
|
|
if (request.IsCached())
|
|
|
|
|
result = request.GetFromCache();
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = ExcelAsyncUtil.Run("Request", request, delegate
|
|
|
|
|
{
|
|
|
|
|
return request.RequestAndCache().GetAwaiter().GetResult();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
|
return "Не найдено :(";
|
|
|
|
|
|
|
|
|
|
if (result.Equals(ExcelError.ExcelErrorNA))
|
|
|
|
|
return "Загрузка...";
|
|
|
|
|
|
|
|
|
|
IProduct product = result as IProduct;
|
|
|
|
|
|
|
|
|
|
switch (field)
|
|
|
|
|
{
|
|
|
|
|
case ProductField.Name:
|
|
|
|
|
return product.Name;
|
|
|
|
|
case ProductField.Id:
|
|
|
|
|
return product.Id;
|
|
|
|
|
case ProductField.Price:
|
|
|
|
|
return double.Parse(product.Price, System.Globalization.CultureInfo.InvariantCulture);
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-11 16:33:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|