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