Compare commits
5 Commits
6d3f2bf55c
...
a065c4c699
Author | SHA1 | Date | |
---|---|---|---|
a065c4c699 | |||
a73b2441b3 | |||
06e47d3135 | |||
5c50e6bc8e | |||
87f030e0f9 |
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@ -15,7 +15,8 @@
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
"stopAtEntry": false,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
|
@ -2,142 +2,155 @@
|
||||
|
||||
public static class RhSolutionsFunctions
|
||||
{
|
||||
private static readonly IDatabaseClient databaseClient =
|
||||
RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
||||
private static readonly ICurrencyClient currencyClient =
|
||||
RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
|
||||
private static readonly IDatabaseClient databaseClient =
|
||||
RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
||||
private static readonly ICurrencyClient currencyClient =
|
||||
RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
|
||||
|
||||
[ExcelFunction(Name = "РЕХАУ")]
|
||||
public static object ProductSearch(string query)
|
||||
{
|
||||
var functionName = nameof(ProductSearch);
|
||||
var parameters = new object[] { query };
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
return await databaseClient.GetProducts(query);
|
||||
}) is not IEnumerable<Product> products)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (!products.Any())
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
var product = products.First();
|
||||
return $"{product.Id} {product.Name}";
|
||||
}
|
||||
}
|
||||
[ExcelFunction(Name = "РЕХАУ")]
|
||||
public static object ProductSearch(object[,] values)
|
||||
{
|
||||
List<string> strings = new();
|
||||
int rows = values.GetLength(0);
|
||||
int columns = values.GetLength(1);
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
for (int column = 0; column < columns; column++)
|
||||
{
|
||||
object value = values[row, column];
|
||||
strings.Add(value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
string query = string.Join(" ", strings.ToArray());
|
||||
var functionName = nameof(ProductSearch);
|
||||
var parameters = new object[] { query };
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
return await databaseClient.GetProducts(query);
|
||||
}) is not IEnumerable<Product> products)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (!products.Any())
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
var product = products.First();
|
||||
return $"{product.Id} {product.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
[ExcelFunction(Name = "РЕХАУАРТИКУЛ")]
|
||||
public static object SkuSearch(string query)
|
||||
{
|
||||
if (ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return skus.First().Id;
|
||||
}
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
[ExcelFunction(Name = "РЕХАУАРТИКУЛ")]
|
||||
public static object SkuSearch(string query)
|
||||
{
|
||||
if (ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return skus.First().Id;
|
||||
}
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
|
||||
[ExcelFunction(Name = "РЕХАУИМЯ")]
|
||||
public static object GetProductName(string query)
|
||||
{
|
||||
if (!ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
var article = skus.First().Id;
|
||||
var functionName = nameof(GetProductName);
|
||||
var parameters = new object[] { query };
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
return await databaseClient.GetProducts(article);
|
||||
}) is not IEnumerable<Product> requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (!requestResult.Any())
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
var firstProduct = requestResult.First();
|
||||
return firstProduct.Name;
|
||||
}
|
||||
}
|
||||
[ExcelFunction(Name = "РЕХАУИМЯ")]
|
||||
public static object GetProductName(string query)
|
||||
{
|
||||
if (!ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
var article = skus.First().Id;
|
||||
var functionName = nameof(GetProductName);
|
||||
var parameters = new object[] { query };
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
return await databaseClient.GetProducts(article);
|
||||
}) is not IEnumerable<Product> requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (!requestResult.Any())
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
var firstProduct = requestResult.First();
|
||||
return firstProduct.Name;
|
||||
}
|
||||
}
|
||||
|
||||
[ExcelFunction(Name = "РЕХАУЦЕНА")]
|
||||
public static object GetProductPrice(string query)
|
||||
{
|
||||
if (!ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
var article = skus.First().Id;
|
||||
var functionName = nameof(GetProductPrice);
|
||||
var parameters = new object[] { article };
|
||||
[ExcelFunction(Name = "РЕХАУЦЕНА")]
|
||||
public static object GetProductPrice(string query)
|
||||
{
|
||||
if (!ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
var article = skus.First().Id;
|
||||
var functionName = nameof(GetProductPrice);
|
||||
var parameters = new object[] { article };
|
||||
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
return await databaseClient.GetProducts(article);
|
||||
}) is not IEnumerable<Product> requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (!requestResult.Any())
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
var firstProduct = requestResult.First();
|
||||
return Math.Round(firstProduct.Price * 1.2m, 2);
|
||||
}
|
||||
}
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
return await databaseClient.GetProducts(article);
|
||||
}) is not IEnumerable<Product> requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (!requestResult.Any())
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
var firstProduct = requestResult.First();
|
||||
return Math.Round(firstProduct.Price * 1.2m, 2);
|
||||
}
|
||||
}
|
||||
|
||||
[ExcelFunction(Name = "РЕХАУЦЕНАРУБ")]
|
||||
public static object GetProductPriceRub(string query, double dateField)
|
||||
{
|
||||
if (!ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
var article = skus.First().Id;
|
||||
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
||||
[ExcelFunction(Name = "РЕХАУЦЕНАРУБ")]
|
||||
public static object GetProductPriceRub(string query, double dateField)
|
||||
{
|
||||
if (!ProductSku.TryParse(query, out var skus))
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
var article = skus.First().Id;
|
||||
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
||||
|
||||
|
||||
var functionName = nameof(GetProductPriceRub);
|
||||
var parameters = new object[] { date };
|
||||
var functionName = nameof(GetProductPriceRub);
|
||||
var parameters = new object[] { date };
|
||||
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
var requestResult = await currencyClient.GetExchangeRate(date);
|
||||
return requestResult ?? -1m;
|
||||
}) is not decimal exchangeRate)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
var requestResult = await currencyClient.GetExchangeRate(date);
|
||||
return requestResult ?? -1m;
|
||||
}) is not decimal exchangeRate)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
|
||||
parameters = new object[] { query };
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
var products = await databaseClient.GetProducts(article);
|
||||
var product = products.FirstOrDefault();
|
||||
return product == null ? -1m :
|
||||
product.Price * (decimal)exchangeRate * 1.2m;
|
||||
}) is not decimal requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (requestResult < 0 || exchangeRate < 0)
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.Round(requestResult, 2);
|
||||
}
|
||||
}
|
||||
parameters = new object[] { query };
|
||||
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||||
{
|
||||
var products = await databaseClient.GetProducts(article);
|
||||
var product = products.FirstOrDefault();
|
||||
return product == null ? -1m :
|
||||
product.Price * (decimal)exchangeRate * 1.2m;
|
||||
}) is not decimal requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else if (requestResult < 0 || exchangeRate < 0)
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.Round(requestResult, 2);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net472</TargetFrameworks>
|
||||
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
||||
<LangVersion>10</LangVersion>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>RhSolutions</RootNamespace>
|
||||
@ -17,8 +17,8 @@
|
||||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
||||
<PackageReference Include="netDxf" Version="2022.11.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="System.Buffers" Version="4.5.1" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user