2021-12-03 12:57:22 +03:00
|
|
|
|
using ExcelDna.Integration;
|
2022-12-28 15:26:41 +03:00
|
|
|
|
using RhSolutions.Models;
|
2022-12-20 12:41:46 +03:00
|
|
|
|
using RhSolutions.Services;
|
2022-12-28 15:26:41 +03:00
|
|
|
|
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-28 15:32:26 +03:00
|
|
|
|
[ExcelFunction(Description = "Распознать артикул и попробовать найти его в прайс-листе")]
|
|
|
|
|
public static object RHSOLUTIONS([ExcelArgument(Name = "\"Строка с названием материала\"")] string line)
|
2022-12-19 09:13:14 +03:00
|
|
|
|
{
|
|
|
|
|
object result;
|
|
|
|
|
|
|
|
|
|
result = ExcelAsyncUtil.Run("Database request", line, delegate
|
|
|
|
|
{
|
|
|
|
|
return RhDatabaseClient.GetProduct(line).GetAwaiter().GetResult();
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-28 15:26:41 +03:00
|
|
|
|
string parsedSku = Sku.TryParse(line, out var skus)
|
|
|
|
|
? skus.First().ToString() : string.Empty;
|
|
|
|
|
|
2022-12-19 09:13:14 +03:00
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
2022-12-28 15:26:41 +03:00
|
|
|
|
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))
|
|
|
|
|
{
|
2022-12-28 15:26:41 +03:00
|
|
|
|
if (string.IsNullOrEmpty(parsedSku))
|
|
|
|
|
{
|
|
|
|
|
return "Загрузка...";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return skus.First().ToString();
|
|
|
|
|
}
|
2022-12-19 09:13:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2022-12-23 21:10:43 +03:00
|
|
|
|
|
|
|
|
|
[ExcelFunction]
|
2022-12-28 15:28:29 +03:00
|
|
|
|
public static void _ResetStatusBar()
|
2022-12-23 21:10:43 +03:00
|
|
|
|
{
|
|
|
|
|
RhSolutionsAddIn.Excel.StatusBar = false;
|
|
|
|
|
}
|
2022-12-19 09:13:14 +03:00
|
|
|
|
}
|
2021-11-11 16:33:40 +03:00
|
|
|
|
}
|