RhSolutions-AddIn/src/AddIn/Functions.cs

56 lines
1.5 KiB
C#
Raw Normal View History

using ExcelDna.Integration;
using RhSolutions.Models;
2022-12-20 12:41:46 +03:00
using RhSolutions.Services;
using System.Linq;
2021-11-11 16:33:40 +03:00
2022-12-20 12:41:46 +03:00
namespace RhSolutions.AddIn
2021-11-11 16:33:40 +03:00
{
2021-11-29 15:50:24 +03:00
public class Functions
2021-11-11 16:33:40 +03:00
{
2022-12-19 09:13:14 +03:00
[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;
2022-12-19 09:13:14 +03:00
if (result == null)
{
if (string.IsNullOrEmpty(parsedSku))
{
return ExcelError.ExcelErrorNA;
}
else
{
return skus.First().ToString();
}
2022-12-19 09:13:14 +03:00
}
if (result.Equals(ExcelError.ExcelErrorNA))
{
if (string.IsNullOrEmpty(parsedSku))
{
return "Загрузка...";
}
else
{
return skus.First().ToString();
}
2022-12-19 09:13:14 +03:00
}
return result;
}
[ExcelFunction]
2022-12-28 15:28:29 +03:00
public static void _ResetStatusBar()
{
RhSolutionsAddIn.Excel.StatusBar = false;
}
2022-12-19 09:13:14 +03:00
}
2021-11-11 16:33:40 +03:00
}