55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
#if !NET472
|
||
using System.Runtime.Versioning;
|
||
#endif
|
||
|
||
namespace RhSolutions.AddIn;
|
||
|
||
#if !NET472
|
||
[SupportedOSPlatform("windows")]
|
||
#endif
|
||
public class RhSolutionsFunction
|
||
{
|
||
[ExcelFunction(Description = "Распознать артикул и попробовать найти его в прайс-листе")]
|
||
public static object RHSOLUTIONS([ExcelArgument(Name = "\"Строка с названием материала\"")] string line)
|
||
{
|
||
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
||
|
||
Sku.TryParse(line, out var skus);
|
||
|
||
if (ExcelAsyncUtil.Run("Database request", line, delegate
|
||
{
|
||
return databaseClient.GetProducts(line)
|
||
.GetAwaiter()
|
||
.GetResult();
|
||
}) is not IEnumerable<Product> requestResult)
|
||
{
|
||
if (skus.Any())
|
||
{
|
||
return $"{skus.First()} ...";
|
||
}
|
||
else
|
||
{
|
||
return "Загрузка...";
|
||
}
|
||
}
|
||
|
||
else
|
||
{
|
||
if (!requestResult.Any() && !skus.Any())
|
||
{
|
||
return ExcelError.ExcelErrorNA;
|
||
}
|
||
|
||
else if (!requestResult.Any())
|
||
{
|
||
return $"{skus.First()}";
|
||
}
|
||
|
||
else
|
||
{
|
||
var firstProduct = requestResult.First();
|
||
return $"{firstProduct.ProductSku} {firstProduct.Name}";
|
||
}
|
||
}
|
||
}
|
||
} |