Compare commits

...

33 Commits

Author SHA1 Message Date
38011f165e Update 50-63 sleeves skus 2024-08-26 18:11:57 +03:00
46b8468628 Merge branch 'master' of https://gitea.cebotari.ru/chebser/RhSolutions-AddIn
Update readme.
2024-07-24 10:01:03 +03:00
7a7c703aa7 Add vscode assets 2024-07-24 10:00:40 +03:00
3b3e37b1c3 Update README.md 2024-06-04 10:18:22 +03:00
a6e5ed1476 Version 1.9.5.0 2024-05-27 23:46:45 +03:00
dfe4ef7b5b Fix merged column header data format 2024-05-27 23:44:59 +03:00
dc1e8616a6 Fix merged column ordering 2024-05-27 23:39:43 +03:00
e71636f5f8 Edit icons 2024-05-26 07:23:37 +03:00
a6a0f104c5 Add mx couplings support 2024-05-26 07:07:18 +03:00
cc32e4792c Add LX sleeves support 2024-05-25 15:15:17 +03:00
678bdb47b9 Bump ExcelDNA packages 2024-05-19 16:22:16 +03:00
0292348f03 Fix usings 2024-02-22 18:10:53 +03:00
9b205a5b3e Ensure price list exists on Excel open 2024-02-22 18:09:27 +03:00
5c8c5f5736 Excel functions refactoring 2024-02-14 23:20:08 +03:00
339cd65dee Version 1.9.3.0 2024-01-21 23:15:22 +03:00
b931809534 Do not close workbook on merge if opened 2024-01-21 23:10:41 +03:00
964bb01a80 Revert "Refactoring Excel application field"
This reverts commit 56112eae51.
2024-01-21 15:14:35 +03:00
f0fca06beb Merge branch 'master' of https://gitea.cebotari.ru/chebser/RhSolutions-AddIn 2024-01-21 15:08:51 +03:00
ed47fd38f6 Use AsyncTaskUtil.RunTask for async functions in formulas 2024-01-21 15:04:51 +03:00
556bb3778e Compress Resources 2024-01-21 15:03:43 +03:00
d71ad65c80 Clean up csproj 2024-01-21 15:03:29 +03:00
2def24c9af Increase DefaultConnectionLimit to 50 2024-01-21 14:52:02 +03:00
56112eae51 Refactoring Excel application field 2024-01-21 14:51:38 +03:00
c6f6551e4e Remove InteslliSense library from pack 2024-01-18 23:55:27 +03:00
84001e050c Remove IntelliSense server 2024-01-18 23:23:26 +03:00
7b2a5955d8 Refactoring functions 2024-01-18 23:16:38 +03:00
fe58c854ea Add memory cache to currency client 2024-01-18 23:16:27 +03:00
822398e286 Update launchSettings.json 2024-01-18 22:38:02 +03:00
634f91dd13 Upgrade packages 2024-01-15 23:06:20 +03:00
03146a6561 Update couplings and sleeves calculator icons 2023-12-28 23:40:33 +03:00
17e1a1681e Fix merge of not selected files behaviour 2023-12-26 00:03:25 +03:00
e73c97e1f8 Update README.md 2023-12-12 23:51:08 +03:00
61f679f52e Delete Install.ps1 2023-12-12 23:50:09 +03:00
29 changed files with 284 additions and 322 deletions

26
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE",
"args": [
"${workspaceFolder}\\RhSolutions.AddIn\\bin\\Debug\\net6.0-windows\\RhSolutions-AddIn64.xll"
],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

12
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dotnet",
"task": "build ${workspaceFolder}\\RhSolutions.AddIn\\RhSolutions.AddIn.csproj",
"group": "build",
"problemMatcher": [],
"label": "build"
},
]
}

View File

@ -1,14 +0,0 @@
$object = Invoke-WebRequest -Uri "https://gitea.cebotari.ru/api/v1/repos/chebser/RhSolutions-AddIn/releases/latest" | ConvertFrom-Json
$download_link = $object.assets[1].browser_download_url
Invoke-WebRequest -Uri $download_link -OutFile "$env:appdata\Microsoft\AddIns\RhSolutions-AddIn-packed.xll"
$excel = New-Object -ComObject Excel.Application
foreach ($addin in $excel.AddIns2)
{
$title = $addin.Title
if ($title -eq 'RhSolutions Add-In')
{
$addin.Installed = $true
}
}
$excel.Quit()

View File

@ -8,12 +8,13 @@
- Объединение нескольких прайс-листов в один файл
- Поиск пар артикул-количество в любой сторонней таблице и экспорт в таблицу заказов
- Подбор монтажных гильз для фитингов RAUTITAN
- Подбор ремонтных муфт по количеству трубы
- Экспорт таблицы заказов в девятиграфку по ГОСТ
*Для работы функций "Экспорт", "Актуализация" и "Объединение" требуется указать путь к файлу пустого прайс-листа РЕХАУ*
## Реализованные формулы для работы с артикулами
- ```=RHSOLUTIONS()``` и ```=РЕХАУ()``` - поиск в удаленной базе данных
- ```=РЕХАУ()``` - поиск артикула РЕХАУ по произвольному запросу в сервисе [RhSolutions-Api](https://gitea.cebotari.ru/chebser/RhSolutions-Api)
- ```=РЕХАУАРТИКУЛ()``` - экстракция артикула РЕХАУ из любой строки по регулярному выражению
- ```=РЕХАУИМЯ()``` - поиск названия артикула по номеру
- ```=РЕХАУЦЕНА()``` - поиск цены в евро по номеру артикула

View File

@ -0,0 +1,27 @@
namespace RhSolutions.AddIn;
public static class CurrencyFunctions
{
private static readonly ICurrencyClient currencyClient =
RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
[ExcelFunction(Name = "КУРСЕВРО")]
public static object GetEuroCurrencyRate(double dateField)
{
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
var functionName = nameof(GetEuroCurrencyRate);
var parameters = new object[] { date };
var exchangeRate = ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
{
var requestResult = await currencyClient.GetExchangeRate(date); return requestResult ?? -1m;
});
if (exchangeRate is not decimal)
{
return "Загрузка...";
}
return (decimal)exchangeRate < 0 ? ExcelError.ExcelErrorNA : exchangeRate;
}
}

View File

@ -1,14 +1,7 @@
using System.Net;
using ExcelDna.IntelliSense;
#if !NET472
using System.Runtime.Versioning;
#endif
namespace RhSolutions.AddIn;
#if !NET472
[SupportedOSPlatform("windows")]
#endif
public sealed class RhSolutionsAddIn : IExcelAddIn
{
public static Application Excel { get; private set; }
@ -55,22 +48,13 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
EventsUtil.Initialize();
if (Environment.GetEnvironmentVariable("ISTESTING") == "false")
{
IntelliSenseServer.Install();
}
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12;
ServicePointManager.DefaultConnectionLimit = 50;
}
public void AutoClose()
{
EventsUtil.Uninitialize();
if (Environment.GetEnvironmentVariable("ISTESTING") == "false")
{
IntelliSenseServer.Uninstall();
}
}
}

View File

@ -1,245 +1,143 @@
#if !NET472
using System.Runtime.Versioning;
#endif
namespace RhSolutions.AddIn;
using Microsoft.Extensions.Caching.Memory;
namespace RhSolutions.AddIn;
#if !NET472
[SupportedOSPlatform("windows")]
#endif
public class RhSolutionsFunctions
public static class RhSolutionsFunctions
{
[ExcelFunction(Description = "Поиск артикула в базе данных")]
public static object RHSOLUTIONS([ExcelArgument(Name = "СТРОКА", Description = "Ячейка с артикулом РЕХАУ или поисковый запрос в свободной форме")] string line)
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)
{
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
ProductSku.TryParse(line, out var skus);
if (ExcelAsyncUtil.Run(nameof(RHSOLUTIONS), line, delegate
var functionName = nameof(ProductSearch);
var parameters = new object[] { query };
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
{
return databaseClient.GetProducts(line)
.GetAwaiter()
.GetResult();
}) is not IEnumerable<Product> requestResult)
return await databaseClient.GetProducts(query);
}) is not IEnumerable<Product> products)
{
if (skus.Any())
{
return $"{skus.First()} ...";
}
else
{
return "Загрузка...";
}
return "Загрузка...";
}
else if (!products.Any())
{
return ExcelError.ExcelErrorNA;
}
else
{
if (!requestResult.Any() && !skus.Any())
{
return ExcelError.ExcelErrorNA;
}
else if (!requestResult.Any())
{
return $"{skus.First()}";
}
else
{
var firstProduct = requestResult.First();
return $"{firstProduct.ProductSku} {firstProduct.Name}";
}
var product = products.First();
return $"{product.Id} {product.Name}";
}
}
[ExcelFunction(Description = "Поиск артикула в базе данных")]
public static object РЕХАУ([ExcelArgument(Name = "СТРОКА", Description = "Ячейка с артикулом РЕХАУ или поисковый запрос в свободной форме")] string line)
=> RHSOLUTIONS(line);
[ExcelFunction(Description = "Выделить артикул РЕХАУ из ячейки")]
public static object РЕХАУАРТИКУЛ([ExcelArgument(Name = "СТРОКА", Description = "Ячейка содержащая артикул РЕХАУ")] string line)
[ExcelFunction(Name = "РЕХАУАРТИКУЛ")]
public static object SkuSearch(string query)
{
if (ProductSku.TryParse(line, out var skus))
if (ProductSku.TryParse(query, out var skus))
{
return skus.First().Id;
}
else
return ExcelError.ExcelErrorNA;
}
[ExcelFunction(Name = "РЕХАУИМЯ")]
public static object GetProductName(string query)
{
if (!ProductSku.TryParse(query, out var skus))
{
return ExcelError.ExcelErrorNA;
}
}
[ExcelFunction(Description = "Поиск названия по артикулу РЕХАУ")]
public static object РЕХАУИМЯ([ExcelArgument(Name = "АРТИКУЛ", Description = "Ячейка содержащая артикул РЕХАУ")] string line)
{
if (!ProductSku.TryParse(line, out var skus))
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 article = skus.First().Id;
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
if (ExcelAsyncUtil.Run(nameof(РЕХАУИМЯ), line, delegate
{
return databaseClient.GetProducts(article)
.GetAwaiter()
.GetResult();
}) is not IEnumerable<Product> requestResult)
{
return "Загрузка...";
}
else
{
if (!requestResult.Any())
{
return ExcelError.ExcelErrorNA;
}
else
{
var firstProduct = requestResult.First();
return firstProduct.Name;
}
}
var firstProduct = requestResult.First();
return firstProduct.Name;
}
}
[ExcelFunction(Description = "Поиск цены артикула РЕХАУ в евро")]
public static object РЕХАУЦЕНА([ExcelArgument(Name = "АРТИКУЛ", Description = "Ячейка содержащая артикул РЕХАУ")] string line)
[ExcelFunction(Name = "РЕХАУЦЕНА")]
public static object GetProductPrice(string query)
{
if (!ProductSku.TryParse(line, out var skus))
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 article = skus.First().Id;
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
if (ExcelAsyncUtil.Run(nameof(РЕХАУЦЕНА), line, delegate
{
return databaseClient.GetProducts(article)
.GetAwaiter()
.GetResult();
}) 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);
}
}
var firstProduct = requestResult.First();
return Math.Round(firstProduct.Price * 1.2m, 2);
}
}
[ExcelFunction(Description = "Поиск цены артикула РЕХАУ в рублях")]
public static object РЕХАУЦЕНАРУБ([ExcelArgument(Name = "АРТИКУЛ", Description = "Ячейка содержащая артикул РЕХАУ")] string line,
[ExcelArgument(Name = "ДАТА", Description = "Дата в формате Excel (необязательно)")] double dateField)
[ExcelFunction(Name = "РЕХАУЦЕНАРУБ")]
public static object GetProductPriceRub(string query, double dateField)
{
if (!ProductSku.TryParse(line, out var skus))
if (!ProductSku.TryParse(query, out var skus))
{
return ExcelError.ExcelErrorNA;
}
else
{
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
ICurrencyClient currencyClient = RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
IMemoryCache memoryCache = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IMemoryCache>();
var article = skus.First().Id;
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
if (!memoryCache.TryGetValue(date, out decimal exchangeRate))
{
var result = ExcelAsyncUtil.Run(nameof(КУРСЕВРО), dateField, delegate
{
var requestResult = currencyClient.GetExchangeRate(date)
.GetAwaiter()
.GetResult();
return requestResult ?? -1m;
});
if (result is not decimal)
{
return "Загрузка...";
}
else
{
exchangeRate = (decimal)result;
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromHours(1));
memoryCache.Set(date, exchangeRate, cacheEntryOptions);
}
}
if (ExcelAsyncUtil.Run(nameof(РЕХАУЦЕНАРУБ), line, delegate
{
var product = databaseClient.GetProducts(article)
.GetAwaiter()
.GetResult()
.FirstOrDefault();
return product == null ? -1m :
product.Price * exchangeRate * 1.2m;
}) is not decimal requestResult)
{
return "Загрузка...";
}
else
{
if (requestResult < 0)
{
return ExcelError.ExcelErrorNA;
}
else
{
return Math.Round(requestResult, 2);
}
}
}
}
[ExcelFunction(Description = "Получить курс евро по ЦБ")]
public static object КУРСЕВРО([ExcelArgument(Name = "ДАТА", Description = "Дата в формате Excel (необязательно)")] double dateField)
{
ICurrencyClient currencyClient = RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
IMemoryCache memoryCache = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IMemoryCache>();
var article = skus.First().Id;
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
if (!memoryCache.TryGetValue(date, out decimal exchangeRate))
var functionName = nameof(GetProductPriceRub);
var parameters = new object[] { date };
if (ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
{
var result = ExcelAsyncUtil.Run(nameof(КУРСЕВРО), dateField, delegate
{
var requestResult = currencyClient.GetExchangeRate(date)
.GetAwaiter()
.GetResult();
return requestResult ?? -1m;
});
if (result is not decimal)
{
return "Загрузка...";
}
else
{
exchangeRate = (decimal)result;
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromHours(1));
memoryCache.Set(date, exchangeRate, cacheEntryOptions);
}
var requestResult = await currencyClient.GetExchangeRate(date);
return requestResult ?? -1m;
}) is not decimal exchangeRate)
{
return "Загрузка...";
}
return exchangeRate < 0 ? ExcelError.ExcelErrorNA : exchangeRate;
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);
}
}
}

View File

@ -1,16 +1,11 @@
using ExcelDna.Integration.CustomUI;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
#if! NET472
using System.Runtime.Versioning;
#endif
using System.Windows.Forms;
namespace RhSolutions.Controllers;
#if !NET472
[SupportedOSPlatform("windows")]
#endif
[ComVisible(true)]
public class RibbonController : ExcelRibbon
{
@ -114,7 +109,7 @@ public class RibbonController : ExcelRibbon
public string GetPriceListPathLabel(IRibbonControl control)
{
string name = RhSolutionsAddIn.Configuration.GetPriceListFileName();
return string.IsNullOrEmpty(name) ? "Шаблонный файл" : name;
return string.IsNullOrEmpty(name) ? "Указать шаблонный файл" : name;
}
public static void UpdateWorkbookValidation()
@ -128,4 +123,13 @@ public class RibbonController : ExcelRibbon
_workbookIsValid = worksheet.IsValidSource();
}
}
public static void EnsurePriseListExists()
{
string pricelistPath = RhSolutionsAddIn.Configuration.GetPriceListPath();
if (!File.Exists(pricelistPath))
{
RhSolutionsAddIn.Configuration.SetPriceListPath(string.Empty);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
[assembly: AssemblyVersion("1.9.5.0")]
[assembly: AssemblyFileVersion("1.9.5.0")]

View File

@ -3,7 +3,7 @@
"Excel": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE",
"commandLineArgs": "RhSolutions-AddIn64.xll"
"commandLineArgs": "/x \"RhSolutions-AddIn64.xll\""
}
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="RhSolutions Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<ExternalLibrary Path="RhSolutions.AddIn.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<Reference Path="ExcelDna.Registration.dll" Pack="true" />
<Reference Path="Microsoft.Bcl.AsyncInterfaces.dll" Pack="true" />
<Reference Path="Microsoft.Bcl.HashCode.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Caching.Abstractions.dll" Pack="true" />
@ -12,7 +13,6 @@
<Reference Path="Microsoft.Extensions.Logging.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Options.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Primitives.dll" Pack="true" />
<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
<Reference Path="Newtonsoft.Json.dll" Pack="true" />
<Reference Path="netDxf.dll" Pack="true" />
<Reference Path="RhSolutions.ProductSku.dll" Pack="true" />

View File

@ -8,35 +8,17 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<ExcelDnaPackCompressResources>false</ExcelDnaPackCompressResources>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net472|AnyCPU'">
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net472|AnyCPU'">
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-windows7.0|AnyCPU'">
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-windows7.0|AnyCPU'">
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExcelDna.AddIn" Version="1.6.0">
<TreatAsUsed>true</TreatAsUsed>
</PackageReference>
<PackageReference Include="ExcelDna.Integration" Version="1.6.0" />
<PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" />
<PackageReference Include="ExcelDna.AddIn" Version="1.8.0" />
<PackageReference Include="ExcelDna.Integration" Version="1.8.0" />
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="ExcelDna.Registration" Version="1.8.0" />
<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="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="netDxf" Version="2022.11.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Buffers" Version="4.5.1" />

View File

@ -38,10 +38,10 @@ public class CouplingsCalculator : IFittingsCalculator
.ToDictionary(kvp =>
kvp.Key switch
{
"16" => new Product("11600111001"),
"20" => new Product("11600121001"),
"25" => new Product("11600131001"),
"32" => new Product("11600141001"),
"16" => new Product("11080111001"),
"20" => new Product("11080121001"),
"25" => new Product("11080131001"),
"32" => new Product("11080141001"),
"40" => new Product("11600151001"),
"50" => new Product("14563021001"),
"63" => new Product("14563031001"),

View File

@ -1,4 +1,5 @@
using System.Net;
using Microsoft.Extensions.Caching.Memory;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Xml.Linq;
@ -8,34 +9,42 @@ namespace RhSolutions.Services;
public class CurrencyClient : ICurrencyClient
{
private readonly HttpClient _httpClient;
private readonly IMemoryCache _memoryCache;
private const string _requestAddress = @"https://www.cbr.ru/scripts/XML_daily.asp?date_req=";
public HttpStatusCode StatusCode { get; private set; }
public CurrencyClient(HttpClient httpClient)
public CurrencyClient(HttpClient httpClient, IMemoryCache memoryCache)
{
_httpClient = httpClient;
_memoryCache = memoryCache;
}
public async Task<decimal?> GetExchangeRate(DateTime date)
{
string request = $"{_requestAddress}{date.Date:dd/MM/yyyy}";
HttpResponseMessage response = await _httpClient.GetAsync(request);
try
if (!_memoryCache.TryGetValue(date, out decimal exchangeRate))
{
response.EnsureSuccessStatusCode();
string xml = await response.Content.ReadAsStringAsync();
XElement valCourses = XElement.Parse(xml);
decimal? exchangeRate = decimal.Parse(valCourses.Elements("Valute")
.Where(e => e.Element("Name").Value == "Евро")
.FirstOrDefault()
.Element("Value").Value);
return exchangeRate;
}
catch
{
StatusCode = response.StatusCode;
return null;
string request = $"{_requestAddress}{date.Date:dd/MM/yyyy}";
HttpResponseMessage response = await _httpClient.GetAsync(request);
try
{
response.EnsureSuccessStatusCode();
string xml = await response.Content.ReadAsStringAsync();
XElement valCourses = XElement.Parse(xml);
exchangeRate = decimal.Parse(valCourses.Elements("Valute")
.Where(e => e.Element("Name").Value == "Евро")
.FirstOrDefault()
.Element("Value").Value);
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromHours(1));
_memoryCache.Set(date, exchangeRate, cacheEntryOptions);
return exchangeRate;
}
catch
{
StatusCode = response.StatusCode;
return null;
}
}
return exchangeRate;
}
}

View File

@ -79,7 +79,7 @@ public class ExcelReader : IReader, IDisposable
return readResult;
}
public List<(string, Dictionary<Product, double>)>
public IEnumerable<(string, Dictionary<Product, double>)>
ReadProducts(IEnumerable<Worksheet> worksheets)
{
List<(string, Dictionary<Product, double>)> result = new();
@ -151,11 +151,15 @@ public class ExcelReader : IReader, IDisposable
result.Add((wbName, readResult));
}
return result;
return result.OrderBy(x => x.Item1);
}
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files)
public IEnumerable<(string, Dictionary<Product, double>)> ReadProducts(string[] files)
{
HashSet<string> openedFiles = RhSolutionsAddIn.Excel.Workbooks
.Cast<Workbook>()
.Select(wb => wb.FullName)
.ToHashSet();
_progressBar = new("Открываю исходные файлы...", files.Length);
List<Worksheet> worksheets = new();
@ -170,7 +174,11 @@ public class ExcelReader : IReader, IDisposable
var result = ReadProducts(worksheets);
foreach (var ws in worksheets)
{
ws.Parent.Close();
string file = (string)ws.Parent.FullName;
if (!openedFiles.Contains(file))
{
ws.Parent.Close(SaveChanges: false);
}
}
return result;
}

View File

@ -70,6 +70,7 @@ namespace RhSolutions.Services
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
Range newColumnHeader = _worksheet.Cells[_amountCell.Row, _amountCell.Column - 1];
newColumnHeader.NumberFormat = "@";
newColumnHeader.Value2 = $"{product.Item1}";
newColumnHeader.WrapText = true;

View File

@ -192,7 +192,7 @@ public class GuessReader : IReader
return result;
}
public List<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets)
public IEnumerable<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets)
{
List<(string, Dictionary<Product, double>)> result = new();
foreach (Worksheet worksheet in worksheets)
@ -206,7 +206,7 @@ public class GuessReader : IReader
return result;
}
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files)
public IEnumerable<(string, Dictionary<Product, double>)> ReadProducts(string[] files)
{
_progressBar = new("Открываю исходные файлы...", files.Length);
List<Worksheet> worksheets = new();

View File

@ -3,7 +3,7 @@
public interface IReader : IDisposable
{
public Dictionary<Product, double> ReadProducts(Range range);
public List<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets);
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files);
public IEnumerable<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets);
public IEnumerable<(string, Dictionary<Product, double>)> ReadProducts(string[] files);
new void Dispose();
}

View File

@ -17,6 +17,10 @@ public class SleevesCalculator : IFittingsCalculator
["20"] = 0,
["25"] = 0,
["32"] = 0,
["16PX"] = 0,
["20PX"] = 0,
["25PX"] = 0,
["32PX"] = 0,
["40"] = 0,
["50"] = 0,
["63"] = 0,
@ -31,7 +35,14 @@ public class SleevesCalculator : IFittingsCalculator
CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures;
foreach (Capture sleeve in collection)
{
result[sleeve.Value] += kvp.Value * 2;
if (kvp.Key.Name.Contains("PX") && sleeve.Value != "40")
{
result[$"{sleeve.Value}PX"] += kvp.Value * 2;
}
else
{
result[sleeve.Value] += kvp.Value * 2;
}
}
continue;
}
@ -41,7 +52,14 @@ public class SleevesCalculator : IFittingsCalculator
CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures;
foreach (Capture sleeve in collection)
{
result[sleeve.Value] += kvp.Value;
if (kvp.Key.Name.Contains("PX") && sleeve.Value != "40")
{
result[$"{sleeve.Value}PX"] += kvp.Value;
}
else
{
result[sleeve.Value] += kvp.Value;
}
}
}
}
@ -50,13 +68,17 @@ public class SleevesCalculator : IFittingsCalculator
.ToDictionary(kvp =>
kvp.Key switch
{
"16" => new Product("11600011001"),
"20" => new Product("11600021001"),
"25" => new Product("11600031001"),
"32" => new Product("11600041001"),
"16" => new Product("11080011001"),
"20" => new Product("11080021001"),
"25" => new Product("11080031001"),
"32" => new Product("11080041001"),
"16PX" => new Product("11600011001"),
"20PX" => new Product("11600021001"),
"25PX" => new Product("11600031001"),
"32PX" => new Product("11600041001"),
"40" => new Product("11600051001"),
"50" => new Product("11397711002"),
"63" => new Product("11397811002"),
"50" => new Product("11397713002"),
"63" => new Product("11397813002"),
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
}, kvp => kvp.Value);
}

View File

@ -1,17 +1,12 @@
using RhSolutions.Controllers;
#if !NET472
using System.Runtime.Versioning;
#endif
namespace RhSolutions.Tools;
#if !NET472
[SupportedOSPlatform("windows")]
#endif
internal static class EventsUtil
{
public static void Initialize()
{
RibbonController.EnsurePriseListExists();
RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;

View File

@ -17,9 +17,12 @@ internal class MergeTool : Tool
{
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IFileDialog>();
string[] files = dialog.GetFiles();
_reader = _readerFactory.GetReader("Excel");
var products = _reader.ReadProducts(files);
_writer = _writerFactory.GetWriter("NewPrice");
_writer.WriteProducts(products);
if (files.Length > 0)
{
_reader = _readerFactory.GetReader("Excel");
var products = _reader.ReadProducts(files);
_writer = _writerFactory.GetWriter("NewPrice");
_writer.WriteProducts(products);
}
}
}

View File

@ -29,13 +29,17 @@ public class CanFillSleeves : IDisposable
var sleeves = _calculator.Calculate(products.First().Item2);
_writer.WriteProducts(sleeves);
Assert.Equal(25, _worksheet.Range["E2"].Value);
Assert.Equal(15, _worksheet.Range["E3"].Value);
Assert.Equal(7, _worksheet.Range["E4"].Value);
Assert.Equal(8, _worksheet.Range["E5"].Value);
Assert.Equal(1, _worksheet.Range["E6"].Value);
Assert.Equal(22, _worksheet.Range["E2"].Value);
Assert.Equal(12, _worksheet.Range["E3"].Value);
Assert.Equal(5, _worksheet.Range["E4"].Value);
Assert.Equal(6, _worksheet.Range["E5"].Value);
Assert.Equal(3, _worksheet.Range["E6"].Value);
Assert.Equal(3, _worksheet.Range["E7"].Value);
Assert.Equal(4, _worksheet.Range["E8"].Value);
Assert.Equal(2, _worksheet.Range["E8"].Value);
Assert.Equal(2, _worksheet.Range["E9"].Value);
Assert.Equal(1, _worksheet.Range["E10"].Value);
Assert.Equal(3, _worksheet.Range["E11"].Value);
Assert.Equal(4, _worksheet.Range["E12"].Value);
}
public void Dispose()

View File

@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="ExcelDna.Testing" Version="1.6.0" />
<PackageReference Include="ExcelDna.Testing" Version="1.8.0" />
</ItemGroup>
<ItemGroup>