RhSolutions-AddIn/RhSolutions.AddIn/AddIn/Functions.cs
2023-03-22 08:36:13 +03:00

56 lines
1.6 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 RhSolutions.Models;
using RhSolutions.Services;
using System.Linq;
namespace RhSolutions.AddIn
{
public class Functions
{
[ExcelFunction(Description = "Распознать артикул и попробовать найти его в прайс-листе")]
public static object RHSOLUTIONS([ExcelArgument(Name = "\"Строка с названием материала\"")] string line)
{
object result;
result = ExcelAsyncUtil.Run("Database request", line, delegate
{
return RhDatabaseClient.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;
}
}
}