RhSolutions-AddIn/RhSolutions.AddIn/AddIn/Functions.cs
2023-03-27 13:55:58 +03:00

58 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ExcelDna.Integration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Office.Interop.Excel;
using RhSolutions.Services;
using System.Linq;
namespace RhSolutions.AddIn
{
public class Functions
{
[ExcelFunction(Description = "Распознать артикул и попробовать найти его в прайс-листе")]
public static object RHSOLUTIONS([ExcelArgument(Name = "\"Строка с названием материала\"")] string line)
{
object result;
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
result = ExcelAsyncUtil.Run("Database request", line, delegate
{
return databaseClient.GetProduct(line).GetAwaiter().GetResult();
});
string parsedSku = Sku.TryParse(line, out var skus)
? skus.First().ToString() : string.Empty;
if (result == null)
{
if (string.IsNullOrEmpty(parsedSku))
{
return ExcelError.ExcelErrorNA;
}
else
{
return skus.First().ToString();
}
}
if (result.Equals(ExcelError.ExcelErrorNA))
{
if (string.IsNullOrEmpty(parsedSku))
{
return "Загрузка...";
}
else
{
return skus.First().ToString();
}
}
return result;
}
[ExcelFunction]
public static void _ResetStatusBar()
{
RhSolutionsAddIn.Excel.StatusBar = false;
}
}
}