2023-03-28 10:36:36 +03:00
|
|
|
|
namespace RhSolutions.AddIn;
|
2021-11-11 16:33:40 +03:00
|
|
|
|
|
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>();
|
|
|
|
|
IEnumerable<Product> requestResult = 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();
|
|
|
|
|
}) as IEnumerable<Product>;
|
2022-12-19 09:13:14 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
Sku.TryParse(line, out var skus);
|
2022-12-28 15:26:41 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
if (requestResult == null)
|
|
|
|
|
{
|
|
|
|
|
if (skus.Count() > 0)
|
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
|
|
|
|
|
{
|
|
|
|
|
if (requestResult.Count() == 0 && skus.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
return ExcelError.ExcelErrorNA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (requestResult.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|