2023-04-06 08:29:39 +03:00
|
|
|
|
#if !NET472
|
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
#endif
|
2021-11-11 16:33:40 +03:00
|
|
|
|
|
2023-04-06 08:29:39 +03:00
|
|
|
|
namespace RhSolutions.AddIn;
|
|
|
|
|
|
|
|
|
|
#if !NET472
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
|
#endif
|
2023-03-28 10:36:36 +03:00
|
|
|
|
public class RhSolutionsFunction
|
2021-11-11 16:33:40 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
[ExcelFunction(Description = "Распознать артикул и попробовать найти его в прайс-листе")]
|
|
|
|
|
public static object RHSOLUTIONS([ExcelArgument(Name = "\"Строка с названием материала\"")] string line)
|
2021-11-11 16:33:40 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
2023-04-06 08:29:39 +03:00
|
|
|
|
|
|
|
|
|
Sku.TryParse(line, out var skus);
|
|
|
|
|
|
|
|
|
|
if (ExcelAsyncUtil.Run("Database request", line, delegate
|
2022-12-19 09:13:14 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
return databaseClient.GetProducts(line)
|
|
|
|
|
.GetAwaiter()
|
|
|
|
|
.GetResult();
|
2023-04-06 08:29:39 +03:00
|
|
|
|
}) is not IEnumerable<Product> requestResult)
|
2023-03-28 10:36:36 +03:00
|
|
|
|
{
|
2023-04-06 08:29:39 +03:00
|
|
|
|
if (skus.Any())
|
2022-12-19 09:13:14 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
return $"{skus.First()} ...";
|
2022-12-19 09:13:14 +03:00
|
|
|
|
}
|
2023-03-27 15:52:28 +03:00
|
|
|
|
else
|
2022-12-19 09:13:14 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
return "Загрузка...";
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-27 15:52:28 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-06 08:29:39 +03:00
|
|
|
|
if (!requestResult.Any() && !skus.Any())
|
2023-03-28 10:36:36 +03:00
|
|
|
|
{
|
|
|
|
|
return ExcelError.ExcelErrorNA;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 08:29:39 +03:00
|
|
|
|
else if (!requestResult.Any())
|
2023-03-28 10:36:36 +03:00
|
|
|
|
{
|
|
|
|
|
return $"{skus.First()}";
|
|
|
|
|
}
|
2023-03-27 15:52:28 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var firstProduct = requestResult.First();
|
|
|
|
|
return $"{firstProduct.ProductSku} {firstProduct.Name}";
|
2022-12-19 09:13:14 +03:00
|
|
|
|
}
|
2022-12-23 21:10:43 +03:00
|
|
|
|
}
|
2022-12-19 09:13:14 +03:00
|
|
|
|
}
|
2021-11-11 16:33:40 +03:00
|
|
|
|
}
|