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-13 20:39:41 +03:00
|
|
|
|
[ExcelFunction(Description = "Получение названия первого продукта по запросу в интернет-магазин REHAU")]
|
|
|
|
|
public static object RAUNAME([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request)
|
|
|
|
|
=> MakeRequest(request, ProductField.Name);
|
2021-12-03 14:15:16 +03:00
|
|
|
|
|
2021-12-13 20:39:41 +03:00
|
|
|
|
[ExcelFunction(Description = "Получение артикула первого продукта по запросу в интернет-магазин REHAU")]
|
|
|
|
|
public static object RAUSKU([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request)
|
|
|
|
|
=> MakeRequest(request, ProductField.Id);
|
2021-12-03 14:15:16 +03:00
|
|
|
|
|
2021-12-13 20:39:41 +03:00
|
|
|
|
[ExcelFunction(Description = "Получение цены первого продукта по запросу в интернет-магазин REHAU")]
|
|
|
|
|
public static object RAUPRICE([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request)
|
|
|
|
|
=> 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
|
|
|
|
}
|
|
|
|
|
}
|