2021-12-03 12:57:22 +03:00
|
|
|
|
using ExcelDna.Integration;
|
2023-03-27 13:55:58 +03:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
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;
|
2023-03-27 13:55:58 +03:00
|
|
|
|
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
2022-12-19 09:13:14 +03:00
|
|
|
|
|
|
|
|
|
result = ExcelAsyncUtil.Run("Database request", line, delegate
|
|
|
|
|
{
|
2023-03-27 13:55:58 +03:00
|
|
|
|
return databaseClient.GetProduct(line).GetAwaiter().GetResult();
|
2022-12-19 09:13:14 +03:00
|
|
|
|
});
|
|
|
|
|
|
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()
|
2023-03-27 13:55:58 +03:00
|
|
|
|
{
|
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
|
|
|
|
}
|