Compare commits
18 Commits
a065c4c699
...
b68a2b2107
Author | SHA1 | Date | |
---|---|---|---|
b68a2b2107 | |||
2dd664df0a | |||
ded0520756 | |||
b18e573da4 | |||
e1289aebbc | |||
2026e2a4e2 | |||
ac20bbfc05 | |||
bb33840185 | |||
843f73fec8 | |||
f8c62c6def | |||
3800c96116 | |||
cc52668afc | |||
cd9c2734f0 | |||
c3da89678e | |||
d0c5ed5e1a | |||
29bd23a52c | |||
1511dafa93 | |||
dbaa8b111a |
@ -4,57 +4,59 @@ namespace RhSolutions.AddIn;
|
|||||||
|
|
||||||
public sealed class RhSolutionsAddIn : IExcelAddIn
|
public sealed class RhSolutionsAddIn : IExcelAddIn
|
||||||
{
|
{
|
||||||
public static Application Excel { get; private set; }
|
public static Application Excel { get; private set; }
|
||||||
public static ServiceProvider ServiceProvider { get; private set; }
|
public static ServiceProvider ServiceProvider { get; private set; }
|
||||||
public static IAddInConfiguration Configuration { get; private set; }
|
public static IAddInConfiguration Configuration { get; private set; }
|
||||||
|
|
||||||
public void AutoOpen()
|
public void AutoOpen()
|
||||||
{
|
{
|
||||||
IServiceCollection Services = new ServiceCollection();
|
IServiceCollection Services = new ServiceCollection();
|
||||||
|
|
||||||
Services.AddHttpClient()
|
Services.AddHttpClient()
|
||||||
.AddMemoryCache()
|
.AddMemoryCache()
|
||||||
.AddSingleton((Application)ExcelDnaUtil.Application)
|
.AddSingleton((Application)ExcelDnaUtil.Application)
|
||||||
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
||||||
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
||||||
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
||||||
.AddTransient<IFileDialog, FileDialog>();
|
.AddTransient<IFileDialog, FileDialog>();
|
||||||
|
|
||||||
Services.AddSingleton<WriterFactory>();
|
Services.AddSingleton<WriterFactory>();
|
||||||
Services.AddTransient<NewPriceWriter>()
|
Services.AddTransient<NewPriceWriter>()
|
||||||
.AddTransient<IWriter, NewPriceWriter>(s => s.GetService<NewPriceWriter>());
|
.AddTransient<IWriter, NewPriceWriter>(s => s.GetService<NewPriceWriter>());
|
||||||
Services.AddTransient<DxfWriter>()
|
Services.AddTransient<DxfWriter>()
|
||||||
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
|
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
|
||||||
Services.AddTransient<CurrentPriceWriter>()
|
Services.AddTransient<CurrentPriceWriter>()
|
||||||
.AddTransient<IWriter, CurrentPriceWriter>(s => s.GetService<CurrentPriceWriter>());
|
.AddTransient<IWriter, CurrentPriceWriter>(s => s.GetService<CurrentPriceWriter>());
|
||||||
|
|
||||||
Services.AddSingleton<ReaderFactory>();
|
Services.AddSingleton<ReaderFactory>();
|
||||||
Services.AddTransient<ExcelReader>()
|
Services.AddTransient<ExcelReader>()
|
||||||
.AddTransient<IReader, ExcelReader>(s => s.GetService<ExcelReader>());
|
.AddTransient<IReader, ExcelReader>(s => s.GetService<ExcelReader>());
|
||||||
Services.AddTransient<GuessReader>()
|
Services.AddTransient<GuessReader>()
|
||||||
.AddTransient<IReader, GuessReader>(s => s.GetService<GuessReader>());
|
.AddTransient<IReader, GuessReader>(s => s.GetService<GuessReader>());
|
||||||
|
|
||||||
Services.AddSingleton<FittingsCalculatorFactory>();
|
Services.AddSingleton<FittingsCalculatorFactory>();
|
||||||
Services.AddTransient<CouplingsCalculator>()
|
Services.AddTransient<CouplingsCalculator>()
|
||||||
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
|
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
|
||||||
Services.AddTransient<SleevesCalculator>()
|
Services.AddTransient<SleevesCalculator>()
|
||||||
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
|
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
|
||||||
|
|
||||||
|
Services.AddTransient<IOcrClient, YandexOcrClient>();
|
||||||
|
|
||||||
Services.AddSingleton<ToolFactory>();
|
Services.AddSingleton<ToolFactory>();
|
||||||
|
|
||||||
ServiceProvider = Services.BuildServiceProvider();
|
ServiceProvider = Services.BuildServiceProvider();
|
||||||
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
|
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
|
||||||
Excel = ServiceProvider.GetService<Application>();
|
Excel = ServiceProvider.GetService<Application>();
|
||||||
|
|
||||||
EventsUtil.Initialize();
|
EventsUtil.Initialize();
|
||||||
|
|
||||||
ServicePointManager.SecurityProtocol =
|
ServicePointManager.SecurityProtocol =
|
||||||
SecurityProtocolType.Tls12;
|
SecurityProtocolType.Tls12;
|
||||||
ServicePointManager.DefaultConnectionLimit = 50;
|
ServicePointManager.DefaultConnectionLimit = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AutoClose()
|
public void AutoClose()
|
||||||
{
|
{
|
||||||
EventsUtil.Uninitialize();
|
EventsUtil.Uninitialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,127 +9,137 @@ namespace RhSolutions.Controllers;
|
|||||||
[ComVisible(true)]
|
[ComVisible(true)]
|
||||||
public class RibbonController : ExcelRibbon
|
public class RibbonController : ExcelRibbon
|
||||||
{
|
{
|
||||||
private static IRibbonUI ribbonUi;
|
private static IRibbonUI ribbonUi;
|
||||||
private static bool _workbookIsValid;
|
private static bool _workbookIsValid;
|
||||||
|
|
||||||
public override string GetCustomUI(string RibbonID)
|
public override string GetCustomUI(string RibbonID)
|
||||||
{
|
{
|
||||||
return @"
|
return @"
|
||||||
<customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui' loadImage='LoadImage'>
|
<customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui' loadImage='LoadImage'>
|
||||||
<ribbon>
|
<ribbon>
|
||||||
<tabs>
|
<tabs>
|
||||||
<tab id='rau' label='RhSolutions'>
|
<tab id='rau' label='RhSolutions'>
|
||||||
<group id='priceList' label='Прайс-лист'>
|
<group id='priceList' label='Прайс-лист'>
|
||||||
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' image='RhSolutions' onAction='OnToolPressed'/>
|
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' image='RhSolutions' onAction='OnToolPressed'/>
|
||||||
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>
|
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>
|
||||||
<button id='merge' label='Объединить' size='normal' imageMso='Copy' onAction='OnToolPressed'/>
|
<button id='merge' label='Объединить' size='normal' imageMso='Copy' onAction='OnToolPressed'/>
|
||||||
<button id='guess' getEnabled='GetGuessEnabled' label='Найти и экспортировать' size='large' imageMso='ControlWizards' onAction='OnToolPressed'/>
|
<button id='guess' getEnabled='GetGuessEnabled' label='Найти и экспортировать' size='large' imageMso='ControlWizards' onAction='OnToolPressed'/>
|
||||||
</group>
|
</group>
|
||||||
<group id='fittingsCalc' label='Расчет фитингов'>
|
<group id='fittingsCalc' label='Расчет фитингов'>
|
||||||
<button id='fillsleeves' getEnabled='GetFittingsCalcEnabled' label='Гильзы' size='large' image='Sleeve' onAction='OnToolPressed'/>
|
<button id='fillsleeves' getEnabled='GetFittingsCalcEnabled' label='Гильзы' size='large' image='Sleeve' onAction='OnToolPressed'/>
|
||||||
<button id='fillcouplings' getEnabled='GetFittingsCalcEnabled' label='Муфты' size='large' image='Coupling' onAction='OnToolPressed'/>
|
<button id='fillcouplings' getEnabled='GetFittingsCalcEnabled' label='Муфты' size='large' image='Coupling' onAction='OnToolPressed'/>
|
||||||
</group>
|
</group>
|
||||||
<group id='exportTab' label='Экспорт'>
|
<group id='exportTab' label='Экспорт'>
|
||||||
<button id='dxfexport' getEnabled='GetDxfEnabled' label='DXF' size='large' image='DXF' onAction='OnToolPressed'/>
|
<button id='dxfexport' getEnabled='GetDxfEnabled' label='DXF' size='large' image='DXF' onAction='OnToolPressed'/>
|
||||||
</group>
|
</group>
|
||||||
<group id='settings' getLabel='GetVersionLabel'>
|
<group id='importTab' label='OCR'>
|
||||||
<button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' image='RhSolutions' onAction='OnSetPricePressed'/>
|
<button id='ocr' getEnabled='GetOcrEnabled' label='Распознать таблицу' size='large' imageMso='TableInsert' onAction='OnToolPressed'/>
|
||||||
</group>
|
</group>
|
||||||
</tab>
|
<group id='settings' getLabel='GetVersionLabel'>
|
||||||
</tabs>
|
<button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' image='RhSolutions' onAction='OnSetPricePressed'/>
|
||||||
</ribbon>
|
</group>
|
||||||
</customUI>";
|
</tab>
|
||||||
}
|
</tabs>
|
||||||
|
</ribbon>
|
||||||
|
</customUI>";
|
||||||
|
}
|
||||||
|
|
||||||
public void RibbonLoad(IRibbonUI sender)
|
public void RibbonLoad(IRibbonUI sender)
|
||||||
{
|
{
|
||||||
ribbonUi = sender;
|
ribbonUi = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RefreshControl(string id)
|
public static void RefreshControl(string id)
|
||||||
{
|
{
|
||||||
ribbonUi?.InvalidateControl(id);
|
ribbonUi?.InvalidateControl(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSetPricePressed(IRibbonControl control)
|
public void OnSetPricePressed(IRibbonControl control)
|
||||||
{
|
{
|
||||||
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetService<IFileDialog>();
|
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetService<IFileDialog>();
|
||||||
string file = dialog.GetFile();
|
string file = dialog.GetFile();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(file))
|
if (!string.IsNullOrEmpty(file))
|
||||||
{
|
{
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(file);
|
RhSolutionsAddIn.Configuration.SetPriceListPath(file);
|
||||||
RhSolutionsAddIn.Configuration.SaveSettings();
|
RhSolutionsAddIn.Configuration.SaveSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnToolPressed(IRibbonControl control)
|
public void OnToolPressed(IRibbonControl control)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var toolFactory = RhSolutionsAddIn.ServiceProvider.GetService<ToolFactory>();
|
var toolFactory = RhSolutionsAddIn.ServiceProvider.GetService<ToolFactory>();
|
||||||
using Tool tool = toolFactory.GetTool(control.Id);
|
using ITool tool = toolFactory.GetTool(control.Id);
|
||||||
tool.Execute();
|
tool.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
MessageBox.Show(exception.Message,
|
MessageBox.Show(exception.Message,
|
||||||
"Ошибка",
|
"Ошибка",
|
||||||
MessageBoxButtons.OK,
|
MessageBoxButtons.OK,
|
||||||
MessageBoxIcon.Information);
|
MessageBoxIcon.Information);
|
||||||
RhSolutionsAddIn.Excel.StatusBar = false;
|
RhSolutionsAddIn.Excel.StatusBar = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetConvertEnabled(IRibbonControl control) => _workbookIsValid;
|
public bool GetConvertEnabled(IRibbonControl control) => _workbookIsValid;
|
||||||
public bool GetDxfEnabled(IRibbonControl control) => _workbookIsValid;
|
public bool GetDxfEnabled(IRibbonControl control) => _workbookIsValid;
|
||||||
public bool GetFittingsCalcEnabled(IRibbonControl control) => _workbookIsValid;
|
public bool GetFittingsCalcEnabled(IRibbonControl control) => _workbookIsValid;
|
||||||
public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook != null && !_workbookIsValid;
|
public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook != null && !_workbookIsValid;
|
||||||
|
|
||||||
public bool GetExportEnabled(IRibbonControl control)
|
public bool GetExportEnabled(IRibbonControl control)
|
||||||
{
|
{
|
||||||
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Range selection = RhSolutionsAddIn.Excel.Selection;
|
Range selection = RhSolutionsAddIn.Excel.Selection;
|
||||||
return selection.Columns.Count == 2;
|
return selection.Columns.Count == 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool GetOcrEnabled(IRibbonControl control)
|
||||||
|
{
|
||||||
|
return RhSolutionsAddIn.Excel.ActiveWorkbook != null &&
|
||||||
|
!string.IsNullOrEmpty(RhSolutionsAddIn.Configuration["x-folder-id"]) &&
|
||||||
|
!string.IsNullOrEmpty(RhSolutionsAddIn.Configuration["apiKey"]);
|
||||||
|
}
|
||||||
|
|
||||||
public string GetVersionLabel(IRibbonControl control)
|
public string GetVersionLabel(IRibbonControl control)
|
||||||
{
|
{
|
||||||
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||||
return $"v{version}";
|
return $"v{version}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetPriceListPathLabel(IRibbonControl control)
|
public string GetPriceListPathLabel(IRibbonControl control)
|
||||||
{
|
{
|
||||||
string name = RhSolutionsAddIn.Configuration.GetPriceListFileName();
|
string name = RhSolutionsAddIn.Configuration.GetPriceListFileName();
|
||||||
return string.IsNullOrEmpty(name) ? "Указать шаблонный файл" : name;
|
return string.IsNullOrEmpty(name) ? "Указать шаблонный файл" : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateWorkbookValidation()
|
public static void UpdateWorkbookValidation()
|
||||||
{
|
{
|
||||||
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
||||||
_workbookIsValid = false;
|
_workbookIsValid = false;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
||||||
_workbookIsValid = worksheet.IsValidSource();
|
_workbookIsValid = worksheet.IsValidSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EnsurePriseListExists()
|
public static void EnsurePriseListExists()
|
||||||
{
|
{
|
||||||
string pricelistPath = RhSolutionsAddIn.Configuration.GetPriceListPath();
|
string pricelistPath = RhSolutionsAddIn.Configuration.GetPriceListPath();
|
||||||
if (!File.Exists(pricelistPath))
|
if (!File.Exists(pricelistPath))
|
||||||
{
|
{
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(string.Empty);
|
RhSolutionsAddIn.Configuration.SetPriceListPath(string.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
RhSolutions.AddIn/Models/OcrResponse.cs
Normal file
28
RhSolutions.AddIn/Models/OcrResponse.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
namespace RhSolutions.Models;
|
||||||
|
|
||||||
|
public class OcrResponse
|
||||||
|
{
|
||||||
|
public Result Result { get; set; }
|
||||||
|
}
|
||||||
|
public class Result
|
||||||
|
{
|
||||||
|
public TextAnnotation TextAnnotation { get; set; }
|
||||||
|
}
|
||||||
|
public class TextAnnotation
|
||||||
|
{
|
||||||
|
public List<Table> Tables { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Table
|
||||||
|
{
|
||||||
|
public string RowCount { get; set; }
|
||||||
|
public string ColumnCount { get; set; }
|
||||||
|
public List<Cell> Cells { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Cell
|
||||||
|
{
|
||||||
|
public string RowIndex { get; set; }
|
||||||
|
public string ColumnIndex { get; set; }
|
||||||
|
public string Text { get; set; }
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.Extensions.Configuration.UserSecrets;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
@ -31,5 +32,6 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.9.5.1")]
|
[assembly: AssemblyVersion("1.10.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.9.5.1")]
|
[assembly: AssemblyFileVersion("1.10.0.0")]
|
||||||
|
[assembly: UserSecretsId("d4bb704e-14a5-421f-8f2d-0ffb66d090a2")]
|
||||||
|
@ -6,8 +6,17 @@
|
|||||||
<Reference Path="Microsoft.Bcl.HashCode.dll" Pack="true" />
|
<Reference Path="Microsoft.Bcl.HashCode.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.Caching.Abstractions.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.Caching.Abstractions.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.Caching.Memory.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.Caching.Memory.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.Configuration.Abstractions.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.Configuration.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.Configuration.EnvironmentVariables.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.Configuration.FileExtensions.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.Configuration.Json.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.Configuration.UserSecrets.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.DependencyInjection.Abstractions.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.DependencyInjection.Abstractions.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.DependencyInjection.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.DependencyInjection.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.FileProviders.Abstractions.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.FileProviders.Physical.dll" Pack="true" />
|
||||||
|
<Reference Path="Microsoft.Extensions.FileSystemGlobbing.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.Http.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.Http.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.Logging.Abstractions.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.Logging.Abstractions.dll" Pack="true" />
|
||||||
<Reference Path="Microsoft.Extensions.Logging.dll" Pack="true" />
|
<Reference Path="Microsoft.Extensions.Logging.dll" Pack="true" />
|
||||||
@ -21,8 +30,11 @@
|
|||||||
<Reference Path="System.Memory.dll" Pack="true" />
|
<Reference Path="System.Memory.dll" Pack="true" />
|
||||||
<Reference Path="System.Numerics.Vectors.dll" Pack="true" />
|
<Reference Path="System.Numerics.Vectors.dll" Pack="true" />
|
||||||
<Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
|
<Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
|
||||||
|
<Reference Path="System.Text.Encodings.Web.dll" Pack="true" />
|
||||||
|
<Reference Path="System.Text.Json.dll" Pack="true" />
|
||||||
<Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
|
<Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
|
||||||
<Reference Path="System.ValueTuple.dll" Pack="true" />
|
<Reference Path="System.ValueTuple.dll" Pack="true" />
|
||||||
|
<Reference Path="SnippingTool.dll" Pack="true" />
|
||||||
<Image Name='RhSolutions' Path='Images\RhSolutions.png' Pack='true' />
|
<Image Name='RhSolutions' Path='Images\RhSolutions.png' Pack='true' />
|
||||||
<Image Name='DXF' Path='Images\DXF.png' Pack='true' />
|
<Image Name='DXF' Path='Images\DXF.png' Pack='true' />
|
||||||
<Image Name='Sleeve' Path='Images\Sleeve.png' Pack='true' />
|
<Image Name='Sleeve' Path='Images\Sleeve.png' Pack='true' />
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>10</LangVersion>
|
||||||
<OutputType>Library</OutputType>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
<RootNamespace>RhSolutions</RootNamespace>
|
|
||||||
<AssemblyName>RhSolutions.AddIn</AssemblyName>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
<UserSecretsId>d4bb704e-14a5-421f-8f2d-0ffb66d090a2</UserSecretsId>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<NoWarn>CA1416</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ExcelDna.AddIn" Version="1.8.0" />
|
<PackageReference Include="ExcelDna.AddIn" Version="1.8.0" />
|
||||||
@ -18,6 +20,10 @@
|
|||||||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
|
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
||||||
<PackageReference Include="netDxf" Version="2022.11.2" />
|
<PackageReference Include="netDxf" Version="2022.11.2" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
@ -25,7 +31,8 @@
|
|||||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
|
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
|
||||||
|
<ProjectReference Include="..\SnippingTool\SnippingTool.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="Images\Coupling.png">
|
<None Update="Images\Coupling.png">
|
||||||
|
@ -1,43 +1,55 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Win32;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace RhSolutions.Services;
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
public class AddInConfiguration : IAddInConfiguration
|
public class AddInConfiguration : IAddInConfiguration
|
||||||
{
|
{
|
||||||
private RegistryKey _rootKey;
|
private IConfiguration _configuration;
|
||||||
private string _priceListPath;
|
private RegistryKey _rootKey;
|
||||||
private Dictionary<string, string> _priceListHeaders;
|
private string _priceListPath;
|
||||||
|
private Dictionary<string, string> settingsValues;
|
||||||
|
|
||||||
public event IAddInConfiguration.SettingsHandler OnSettingsChange;
|
public string this[string key]
|
||||||
|
{
|
||||||
|
get => _configuration[key];
|
||||||
|
}
|
||||||
|
|
||||||
public AddInConfiguration()
|
public event IAddInConfiguration.SettingsHandler OnSettingsChange;
|
||||||
{
|
|
||||||
_rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");
|
|
||||||
_priceListPath = (string)_rootKey.GetValue("PriceListPath");
|
|
||||||
_priceListHeaders = new()
|
|
||||||
{
|
|
||||||
["Amount"] = "Кол-во",
|
|
||||||
["OldSku"] = "Прежний материал",
|
|
||||||
["Sku"] = "Актуальный материал",
|
|
||||||
["ProductLine"] = "Программа",
|
|
||||||
["Name"] = "Наименование",
|
|
||||||
["Measure"] = "Ед. изм."
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetPriceListFileName() => Path.GetFileName(_priceListPath);
|
public AddInConfiguration()
|
||||||
public Dictionary<string, string> GetPriceListHeaders() => _priceListHeaders;
|
{
|
||||||
public string GetPriceListPath() => _priceListPath;
|
_configuration = new ConfigurationBuilder()
|
||||||
|
.AddUserSecrets<RhSolutionsAddIn>()
|
||||||
|
.AddEnvironmentVariables("RHS_ADDIN__")
|
||||||
|
.Build();
|
||||||
|
|
||||||
public void SaveSettings()
|
_rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");
|
||||||
{
|
_priceListPath = (string)_rootKey.GetValue("PriceListPath");
|
||||||
_rootKey.SetValue("PriceListPath", _priceListPath);
|
settingsValues = new()
|
||||||
OnSettingsChange.Invoke();
|
{
|
||||||
}
|
["Amount"] = "Кол-во",
|
||||||
|
["OldSku"] = "Прежний материал",
|
||||||
|
["Sku"] = "Актуальный материал",
|
||||||
|
["ProductLine"] = "Программа",
|
||||||
|
["Name"] = "Наименование",
|
||||||
|
["Measure"] = "Ед. изм."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPriceListPath(string value)
|
public string GetPriceListFileName() => Path.GetFileName(_priceListPath);
|
||||||
{
|
public Dictionary<string, string> GetPriceListHeaders() => settingsValues;
|
||||||
_priceListPath = value;
|
public string GetPriceListPath() => _priceListPath;
|
||||||
}
|
|
||||||
|
public void SaveSettings()
|
||||||
|
{
|
||||||
|
_rootKey.SetValue("PriceListPath", _priceListPath);
|
||||||
|
OnSettingsChange.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPriceListPath(string value)
|
||||||
|
{
|
||||||
|
_priceListPath = value;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,15 @@
|
|||||||
namespace RhSolutions.Services;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
public interface IAddInConfiguration
|
public interface IAddInConfiguration
|
||||||
{
|
{
|
||||||
public string GetPriceListPath();
|
string this[string key] { get; }
|
||||||
public void SetPriceListPath(string value);
|
public string GetPriceListPath();
|
||||||
public string GetPriceListFileName();
|
public void SetPriceListPath(string value);
|
||||||
public Dictionary<string, string> GetPriceListHeaders();
|
public string GetPriceListFileName();
|
||||||
public delegate void SettingsHandler();
|
public Dictionary<string, string> GetPriceListHeaders();
|
||||||
public event SettingsHandler OnSettingsChange;
|
public delegate void SettingsHandler();
|
||||||
public void SaveSettings();
|
public event SettingsHandler OnSettingsChange;
|
||||||
|
public void SaveSettings();
|
||||||
}
|
}
|
8
RhSolutions.AddIn/Services/IOcrClient.cs
Normal file
8
RhSolutions.AddIn/Services/IOcrClient.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
public interface IOcrClient
|
||||||
|
{
|
||||||
|
public Task<IEnumerable<object[,]>> ProcessImage(string base64Image);
|
||||||
|
}
|
82
RhSolutions.AddIn/Services/YandexOcrClient.cs
Normal file
82
RhSolutions.AddIn/Services/YandexOcrClient.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
public class YandexOcrClient : IOcrClient
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly string _apiKey;
|
||||||
|
private readonly string _xFolderId;
|
||||||
|
public YandexOcrClient(HttpClient httpClient, IAddInConfiguration configuration)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
_httpClient.BaseAddress = new Uri("https://ocr.api.cloud.yandex.net/ocr/v1/");
|
||||||
|
_apiKey = configuration["apiKey"];
|
||||||
|
_xFolderId = configuration["x-folder-id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<object[,]>> ProcessImage(string base64Image)
|
||||||
|
{
|
||||||
|
using StringContent jsonContent = new(
|
||||||
|
JsonConvert.SerializeObject(new
|
||||||
|
{
|
||||||
|
mimeType = "PNG",
|
||||||
|
languageCodes = new string[] { "ru", "en" },
|
||||||
|
model = "table",
|
||||||
|
content = base64Image
|
||||||
|
}),
|
||||||
|
Encoding.UTF8,
|
||||||
|
"application/json");
|
||||||
|
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Api-Key", _apiKey);
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("x-folder-id", _xFolderId);
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("x-data-logging-enable", "true");
|
||||||
|
|
||||||
|
using HttpResponseMessage response = await _httpClient.PostAsync("recognizeText", jsonContent);
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string jsonResponse = await response.Content.ReadAsStringAsync();
|
||||||
|
OcrResponse deserialized = JsonConvert.DeserializeObject<OcrResponse>(jsonResponse);
|
||||||
|
|
||||||
|
if (deserialized != null)
|
||||||
|
{
|
||||||
|
var tables = deserialized?.Result?.TextAnnotation?.Tables ?? Enumerable.Empty<Table>();
|
||||||
|
if (tables.Any())
|
||||||
|
{
|
||||||
|
List<object[,]> result = new();
|
||||||
|
foreach (var table in tables)
|
||||||
|
{
|
||||||
|
if (table.Cells == null || table.Cells.Count == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int columnCount = int.Parse(table.ColumnCount);
|
||||||
|
int rowCount = int.Parse(table.RowCount);
|
||||||
|
object[,] cells = new object[rowCount, columnCount];
|
||||||
|
|
||||||
|
foreach (Cell cell in table.Cells)
|
||||||
|
{
|
||||||
|
int rowIndex = int.Parse(cell.RowIndex);
|
||||||
|
int columnIndex = int.Parse(cell.ColumnIndex);
|
||||||
|
cells[rowIndex, columnIndex] = double.TryParse(cell.Text, out double v) ?
|
||||||
|
v : cell.Text ?? string.Empty;
|
||||||
|
}
|
||||||
|
result.Add(cells);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string content = await response.Content.ReadAsStringAsync();
|
||||||
|
MessageBox.Show($"{response.StatusCode}: {content}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Enumerable.Empty<object[,]>();
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,8 @@
|
|||||||
using RhSolutions.AddIn;
|
namespace RhSolutions.Tools;
|
||||||
#if !NET472
|
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
internal class ConvertTool : ReaderWriterTool, ITool
|
||||||
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
internal class ConvertTool : Tool
|
|
||||||
{
|
{
|
||||||
public ConvertTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
public void Execute()
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Execute()
|
|
||||||
{
|
{
|
||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
|
@ -1,19 +1,8 @@
|
|||||||
#if !NET472
|
namespace RhSolutions.Tools;
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
internal class DxfTool : ReaderWriterTool, ITool
|
||||||
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
internal class DxfTool : Tool
|
|
||||||
{
|
{
|
||||||
public DxfTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
public void Execute()
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Execute()
|
|
||||||
{
|
{
|
||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
|
@ -4,40 +4,43 @@ namespace RhSolutions.Tools;
|
|||||||
|
|
||||||
internal static class EventsUtil
|
internal static class EventsUtil
|
||||||
{
|
{
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
RibbonController.EnsurePriseListExists();
|
RibbonController.EnsurePriseListExists();
|
||||||
RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
|
RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
|
||||||
RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
|
RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
|
||||||
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
|
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
|
||||||
RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
|
RhSolutionsAddIn.Excel.WorkbookDeactivate += RefreshButtons;
|
||||||
}
|
RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
|
||||||
|
}
|
||||||
|
|
||||||
public static void Uninitialize()
|
public static void Uninitialize()
|
||||||
{
|
{
|
||||||
RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
|
RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
|
||||||
RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
|
RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
|
||||||
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
|
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
|
||||||
RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
|
RhSolutionsAddIn.Excel.WorkbookDeactivate -= RefreshButtons;
|
||||||
}
|
RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
|
||||||
|
}
|
||||||
|
|
||||||
private static void RefreshButtons(object sh)
|
private static void RefreshButtons(object sh)
|
||||||
{
|
{
|
||||||
RibbonController.UpdateWorkbookValidation();
|
RibbonController.UpdateWorkbookValidation();
|
||||||
RibbonController.RefreshControl("convert");
|
RibbonController.RefreshControl("convert");
|
||||||
RibbonController.RefreshControl("dxfexport");
|
RibbonController.RefreshControl("dxfexport");
|
||||||
RibbonController.RefreshControl("guess");
|
RibbonController.RefreshControl("guess");
|
||||||
RibbonController.RefreshControl("fillsleeves");
|
RibbonController.RefreshControl("fillsleeves");
|
||||||
RibbonController.RefreshControl("fillcouplings");
|
RibbonController.RefreshControl("fillcouplings");
|
||||||
}
|
RibbonController.RefreshControl("ocr");
|
||||||
|
}
|
||||||
|
|
||||||
private static void RefreshExportButton(object sh, Range target)
|
private static void RefreshExportButton(object sh, Range target)
|
||||||
{
|
{
|
||||||
RibbonController.RefreshControl("export");
|
RibbonController.RefreshControl("export");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshSettingTitle()
|
private static void RefreshSettingTitle()
|
||||||
{
|
{
|
||||||
RibbonController.RefreshControl("setPriceList");
|
RibbonController.RefreshControl("setPriceList");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,13 @@
|
|||||||
#if !NET472
|
namespace RhSolutions.Tools;
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
internal class ExportTool : ReaderWriterTool, ITool
|
||||||
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
internal class ExportTool : Tool
|
|
||||||
{
|
{
|
||||||
public ExportTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
public void Execute()
|
||||||
{
|
{
|
||||||
}
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
|
_reader = _readerFactory.GetReader("Excel");
|
||||||
public override void Execute()
|
var products = _reader.ReadProducts(app.Selection);
|
||||||
{
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
_writer.WriteProducts(products);
|
||||||
_reader = _readerFactory.GetReader("Excel");
|
}
|
||||||
var products = _reader.ReadProducts(app.Selection);
|
}
|
||||||
_writer = _writerFactory.GetWriter("NewPrice");
|
|
||||||
_writer.WriteProducts(products);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
|||||||
namespace RhSolutions.Tools;
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
internal class FittingsTool : Tool
|
internal class FittingsTool : ReaderWriterTool, ITool
|
||||||
{
|
{
|
||||||
private readonly FittingsCalculatorFactory _factory;
|
private readonly FittingsCalculatorFactory _factory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
|
||||||
private string _calculatorName;
|
private string _calculatorName;
|
||||||
|
|
||||||
public FittingsTool(ReaderFactory readerFactory, WriterFactory writerFactory, FittingsCalculatorFactory calculatorFactory, string calculatorName) : base(readerFactory, writerFactory)
|
public FittingsTool(string calculatorName)
|
||||||
{
|
{
|
||||||
_factory = calculatorFactory;
|
|
||||||
_calculatorName = calculatorName;
|
_calculatorName = calculatorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
#if !NET472
|
namespace RhSolutions.Tools;
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
internal class GuessTool : ReaderWriterTool, ITool
|
||||||
|
|
||||||
internal class GuessTool : Tool
|
|
||||||
{
|
{
|
||||||
public GuessTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
public void Execute()
|
||||||
{
|
{
|
||||||
}
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
public override void Execute()
|
_reader = _readerFactory.GetReader("Guess");
|
||||||
{
|
var products = _reader.ReadProducts(new[] { worksheet });
|
||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
_writer.WriteProducts(products);
|
||||||
_reader = _readerFactory.GetReader("Guess");
|
}
|
||||||
var products = _reader.ReadProducts(new[] { worksheet });
|
}
|
||||||
_writer = _writerFactory.GetWriter("NewPrice");
|
|
||||||
_writer.WriteProducts(products);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
9
RhSolutions.AddIn/Tools/ITool.cs
Normal file
9
RhSolutions.AddIn/Tools/ITool.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#if !NET472
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
|
internal interface ITool: IDisposable
|
||||||
|
{
|
||||||
|
public void Execute();
|
||||||
|
}
|
@ -1,28 +1,17 @@
|
|||||||
#if !NET472
|
namespace RhSolutions.Tools;
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
internal class MergeTool : ReaderWriterTool, ITool
|
||||||
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
internal class MergeTool : Tool
|
|
||||||
{
|
{
|
||||||
public MergeTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
public void Execute()
|
||||||
{
|
{
|
||||||
}
|
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IFileDialog>();
|
||||||
|
string[] files = dialog.GetFiles();
|
||||||
public override void Execute()
|
if (files.Length > 0)
|
||||||
{
|
{
|
||||||
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IFileDialog>();
|
_reader = _readerFactory.GetReader("Excel");
|
||||||
string[] files = dialog.GetFiles();
|
var products = _reader.ReadProducts(files);
|
||||||
if (files.Length > 0)
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
{
|
_writer.WriteProducts(products);
|
||||||
_reader = _readerFactory.GetReader("Excel");
|
}
|
||||||
var products = _reader.ReadProducts(files);
|
}
|
||||||
_writer = _writerFactory.GetWriter("NewPrice");
|
|
||||||
_writer.WriteProducts(products);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
87
RhSolutions.AddIn/Tools/OcrTool.cs
Normal file
87
RhSolutions.AddIn/Tools/OcrTool.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using SnippingTool;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Application = Microsoft.Office.Interop.Excel.Application;
|
||||||
|
|
||||||
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
|
internal class OcrTool : ITool
|
||||||
|
{
|
||||||
|
private IOcrClient client = RhSolutionsAddIn.ServiceProvider.GetService<IOcrClient>();
|
||||||
|
private Application app = RhSolutionsAddIn.Excel;
|
||||||
|
private string xFolderId = RhSolutionsAddIn.Configuration["x-folder-id"];
|
||||||
|
private string apiKey = RhSolutionsAddIn.Configuration["apiKey"];
|
||||||
|
|
||||||
|
public async void Execute()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RhSolutionsAddIn.Excel.Visible = false;
|
||||||
|
Task.Run(async delegate
|
||||||
|
{
|
||||||
|
await Task.Delay(250);
|
||||||
|
}).Wait();
|
||||||
|
|
||||||
|
string shot = Snipper.SnipBase64();
|
||||||
|
RhSolutionsAddIn.Excel.Visible = true;
|
||||||
|
|
||||||
|
if (shot != null)
|
||||||
|
{
|
||||||
|
IEnumerable<object[,]> tables = await client.ProcessImage(shot);
|
||||||
|
if (tables != null)
|
||||||
|
{
|
||||||
|
foreach (var table in tables)
|
||||||
|
{
|
||||||
|
int rowCount = table.GetLength(0);
|
||||||
|
int columnCount = table.GetLength(1);
|
||||||
|
|
||||||
|
Range currentCell = app.ActiveCell;
|
||||||
|
Range tableRange = app.ActiveSheet.Range(currentCell,
|
||||||
|
app.ActiveSheet.Cells(currentCell.Row + rowCount - 1, currentCell.Column + columnCount - 1));
|
||||||
|
|
||||||
|
if (app.WorksheetFunction.CountA(tableRange) > 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"На листе отсустствует диапазон для вставки распознанной таблицы.Попробуйте в другом месте или на пустом листе.",
|
||||||
|
"Ошибка",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
RhSolutionsAddIn.Excel.Visible = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tableRange.Borders.LineStyle = XlLineStyle.xlContinuous;
|
||||||
|
|
||||||
|
for (int row = 0; row < rowCount; row++)
|
||||||
|
for (int column = 0; column < columnCount; column++)
|
||||||
|
{
|
||||||
|
Range excelCell = app.ActiveSheet.Cells(currentCell.Row + row,
|
||||||
|
currentCell.Column + column);
|
||||||
|
excelCell.Value2 = table[row, column];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Range row in tableRange.Rows)
|
||||||
|
{
|
||||||
|
row.EntireRow.AutoFit();
|
||||||
|
}
|
||||||
|
foreach (Range column in tableRange.Columns)
|
||||||
|
{
|
||||||
|
column.EntireColumn.AutoFit();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ActiveSheet.Cells(currentCell.Row + rowCount + 1, currentCell.Column).Activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
RhSolutionsAddIn.Excel.Visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
15
RhSolutions.AddIn/Tools/ReaderWriterTool.cs
Normal file
15
RhSolutions.AddIn/Tools/ReaderWriterTool.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
|
internal abstract class ReaderWriterTool: IDisposable
|
||||||
|
{
|
||||||
|
protected IReader _reader;
|
||||||
|
protected IWriter _writer;
|
||||||
|
|
||||||
|
protected ReaderFactory _readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
|
||||||
|
protected WriterFactory _writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_reader?.Dispose();
|
||||||
|
_writer?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +0,0 @@
|
|||||||
#if !NET472
|
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
|
||||||
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
internal abstract class Tool : IDisposable
|
|
||||||
{
|
|
||||||
protected readonly ReaderFactory _readerFactory;
|
|
||||||
protected readonly WriterFactory _writerFactory;
|
|
||||||
protected IReader _reader;
|
|
||||||
protected IWriter _writer;
|
|
||||||
|
|
||||||
public Tool(ReaderFactory readerFactory, WriterFactory writerFactory)
|
|
||||||
{
|
|
||||||
_readerFactory = readerFactory;
|
|
||||||
_writerFactory = writerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_reader?.Dispose();
|
|
||||||
_writer?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Execute();
|
|
||||||
}
|
|
@ -2,23 +2,19 @@
|
|||||||
|
|
||||||
internal class ToolFactory
|
internal class ToolFactory
|
||||||
{
|
{
|
||||||
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
|
public ITool GetTool(string toolName)
|
||||||
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
{
|
||||||
static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
|
return toolName switch
|
||||||
|
{
|
||||||
public Tool GetTool(string toolName)
|
"export" => new ExportTool(),
|
||||||
{
|
"convert" => new ConvertTool(),
|
||||||
Tool tool = toolName switch
|
"merge" => new MergeTool(),
|
||||||
{
|
"dxfexport" => new DxfTool(),
|
||||||
"export" => new ExportTool(readerFactory, writerFactory),
|
"guess" => new GuessTool(),
|
||||||
"convert" => new ConvertTool(readerFactory, writerFactory),
|
"fillsleeves" => new FittingsTool("Sleeves"),
|
||||||
"merge" => new MergeTool(readerFactory, writerFactory),
|
"fillcouplings" => new FittingsTool("Couplings"),
|
||||||
"dxfexport" => new DxfTool(readerFactory, writerFactory),
|
"ocr" => new OcrTool(),
|
||||||
"guess" => new GuessTool(readerFactory, writerFactory),
|
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
||||||
"fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"),
|
};
|
||||||
"fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"),
|
}
|
||||||
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
|
||||||
};
|
|
||||||
return tool;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RhSolutions.Tests", "RhSolu
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "RhSolutions.ProductSku\RhSolutions.ProductSku.csproj", "{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "RhSolutions.ProductSku\RhSolutions.ProductSku.csproj", "{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnippingTool", "SnippingTool\SnippingTool.csproj", "{DDB517C7-DF61-4C26-B691-956D0E5906C3}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -27,6 +29,14 @@ Global
|
|||||||
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{53F322B3-F477-4831-8E16-EA76934A0D59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{53F322B3-F477-4831-8E16-EA76934A0D59}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{53F322B3-F477-4831-8E16-EA76934A0D59}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{53F322B3-F477-4831-8E16-EA76934A0D59}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
101
SnippingTool/Snipper.cs
Normal file
101
SnippingTool/Snipper.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using System.Drawing.Imaging;
|
||||||
|
|
||||||
|
namespace SnippingTool;
|
||||||
|
|
||||||
|
public partial class Snipper : Form
|
||||||
|
{
|
||||||
|
public static Image? Snip()
|
||||||
|
{
|
||||||
|
var rc = Screen.PrimaryScreen.Bounds;
|
||||||
|
using Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
|
||||||
|
using Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
gr.CopyFromScreen(0, 0, 0, 0, bmp.Size);
|
||||||
|
using var snipper = new Snipper(bmp);
|
||||||
|
|
||||||
|
return snipper.ShowDialog() == DialogResult.OK ? snipper.Image : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string? SnipBase64()
|
||||||
|
{
|
||||||
|
var shot = Snip();
|
||||||
|
if (shot != null)
|
||||||
|
{
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
shot.Save(ms, ImageFormat.Png);
|
||||||
|
byte[] imageBytes = ms.ToArray();
|
||||||
|
return Convert.ToBase64String(imageBytes);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Snipper(Image screenShot)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BackgroundImage = screenShot;
|
||||||
|
ShowInTaskbar = false;
|
||||||
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
|
WindowState = FormWindowState.Maximized;
|
||||||
|
DoubleBuffered = true;
|
||||||
|
}
|
||||||
|
public Image? Image { get; set; }
|
||||||
|
|
||||||
|
private Rectangle rcSelect = new Rectangle();
|
||||||
|
private Point pntStart;
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button != MouseButtons.Left)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pntStart = e.Location;
|
||||||
|
rcSelect = new Rectangle(e.Location, new Size(0, 0));
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button != MouseButtons.Left)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int x1 = Math.Min(e.X, pntStart.X);
|
||||||
|
int y1 = Math.Min(e.Y, pntStart.Y);
|
||||||
|
int x2 = Math.Max(e.X, pntStart.X);
|
||||||
|
int y2 = Math.Max(e.Y, pntStart.Y);
|
||||||
|
rcSelect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (rcSelect.Width <= 0 || rcSelect.Height <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Image = new Bitmap(rcSelect.Width, rcSelect.Height);
|
||||||
|
using Graphics gr = Graphics.FromImage(Image);
|
||||||
|
gr.DrawImage(BackgroundImage, new Rectangle(0, 0, Image.Width, Image.Height),
|
||||||
|
rcSelect, GraphicsUnit.Pixel);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
using Brush br = new SolidBrush(Color.FromArgb(120, Color.White));
|
||||||
|
int x1 = rcSelect.X; int x2 = rcSelect.X + rcSelect.Width;
|
||||||
|
int y1 = rcSelect.Y; int y2 = rcSelect.Y + rcSelect.Height;
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(0, 0, x1, Height));
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(x2, 0, Width - x2, Height));
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(x1, 0, x2 - x1, y1));
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(x1, y2, x2 - x1, Height - y2));
|
||||||
|
|
||||||
|
using Pen pen = new Pen(Color.Red, 3);
|
||||||
|
e.Graphics.DrawRectangle(pen, rcSelect);
|
||||||
|
}
|
||||||
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||||
|
{
|
||||||
|
if (keyData == Keys.Escape)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
}
|
||||||
|
return base.ProcessCmdKey(ref msg, keyData);
|
||||||
|
}
|
||||||
|
}
|
38
SnippingTool/SnippingTool.Designer.cs
generated
Normal file
38
SnippingTool/SnippingTool.Designer.cs
generated
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
namespace SnippingTool;
|
||||||
|
|
||||||
|
partial class Snipper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.components = new System.ComponentModel.Container();
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Text = "Form1";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
12
SnippingTool/SnippingTool.csproj
Normal file
12
SnippingTool/SnippingTool.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<LangVersion>10</LangVersion>
|
||||||
|
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user