Compare commits

...

4 Commits

Author SHA1 Message Date
Sergey Chebotar
598ffe0d3c Remove Registration 2022-12-19 20:27:11 +03:00
Sergey Chebotar
965eb2b80c Rename project 2022-12-19 20:25:35 +03:00
Sergey Chebotar
012ec9d010 Basic remote database implementation 2022-12-19 09:13:14 +03:00
Sergey Chebotar
75e7f9aae4 Rename Excel Ribbon Tab 2022-12-19 08:44:32 +03:00
28 changed files with 139 additions and 58 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RehauSku.Assist", "src\RehauSku.Assist.csproj", "{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions", "src\RhSolutions.csproj", "{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,20 +1,20 @@
using ExcelDna.Integration;
using ExcelDna.IntelliSense;
using ExcelDna.Registration;
using Microsoft.Office.Interop.Excel;
using System.Net.Http;
using System.Runtime.Caching;
namespace RehauSku
namespace RhSolutions
{
class AddIn : IExcelAddIn
{
public static Application Excel;
public static HttpClient httpClient;
public void AutoOpen()
{
Excel = (Application)ExcelDnaUtil.Application;
RegisterFunctions();
httpClient = new HttpClient();
IntelliSenseServer.Install();
RegistryUtil.Initialize();
EventsUtil.Initialize();
@ -26,12 +26,5 @@ namespace RehauSku
RegistryUtil.Uninitialize();
EventsUtil.Uninitialize();
}
void RegisterFunctions()
{
ExcelRegistration.GetExcelFunctions()
.ProcessAsyncRegistrations(nativeAsyncIfAvailable: false)
.RegisterFunctions();
}
}
}

View File

@ -1,6 +1,6 @@
using Microsoft.Office.Interop.Excel;
namespace RehauSku
namespace RhSolutions
{
internal static class EventsUtil
{

View File

@ -1,6 +1,13 @@
using ExcelDna.Integration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace RehauSku
namespace RhSolutions
{
public class Functions
{
@ -14,5 +21,64 @@ namespace RehauSku
else return ExcelError.ExcelErrorNA;
}
[ExcelFunction(Description = "Запрос в удаленную базу данных")]
public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line)
{
object result;
result = ExcelAsyncUtil.Run("Database request", line, delegate
{
return RhDatabaseClient.GetProduct(line).GetAwaiter().GetResult();
});
if (result == null)
{
return ExcelError.ExcelErrorNA;
}
if (result.Equals(ExcelError.ExcelErrorNA))
{
return "Загрузка...";
}
return result;
}
}
public static class RhDatabaseClient
{
private static HttpClient httpClient = AddIn.httpClient;
public static async Task<object> GetProduct(string line)
{
string request = @"https://rh.cebotari.ru/api/search?query=" + line;
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls;
string response = await httpClient.GetStringAsync(request);
var products = JsonConvert.DeserializeObject<IEnumerable<DbProduct>>(response);
var product = products.FirstOrDefault();
if (product == null)
{
return null;
}
else
{
return $"{product.productSku} {product.name}";
}
}
private class DbProduct
{
public string productSku { get; set; }
public string name { get; set; }
}
}
}

View File

@ -1,10 +1,10 @@
using Microsoft.Win32;
using RehauSku.Interface;
using RhSolutions.Interface;
using System;
using System.IO;
using System.Windows.Forms;
namespace RehauSku
namespace RhSolutions
{
static class RegistryUtil
{

View File

@ -1,6 +1,6 @@
using System.Text.RegularExpressions;
namespace RehauSku
namespace RhSolutions
{
internal class RauSku
{

View File

@ -1,6 +1,6 @@
using System.Text.RegularExpressions;
namespace RehauSku
namespace RhSolutions
{
static class SkuExtensions
{

View File

@ -1,8 +1,8 @@
using Microsoft.Office.Interop.Excel;
using RehauSku.PriceListTools;
using RhSolutions.PriceListTools;
using System.Linq;
namespace RehauSku
namespace RhSolutions
{
public static class WorksheetExtensions
{

View File

@ -2,7 +2,7 @@
using Microsoft.Office.Interop.Excel;
using System;
namespace RehauSku.Interface
namespace RhSolutions.Interface
{
internal abstract class AbstractBar : IDisposable
{

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Windows.Forms;
namespace RehauSku.Interface
namespace RhSolutions.Interface
{
static class Dialog
{

View File

@ -1,4 +1,4 @@
namespace RehauSku.Interface
namespace RhSolutions.Interface
{
internal class ProgressBar : AbstractBar
{

View File

@ -1,7 +1,7 @@
using System;
using System.Text;
namespace RehauSku.Interface
namespace RhSolutions.Interface
{
internal class ResultBar : AbstractBar
{

View File

@ -1,13 +1,13 @@
using ExcelDna.Integration.CustomUI;
using Microsoft.Office.Interop.Excel;
using RehauSku.PriceListTools;
using RhSolutions.PriceListTools;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace RehauSku.Interface
namespace RhSolutions.Interface
{
[ComVisible(true)]
public class RibbonController : ExcelRibbon
@ -20,7 +20,7 @@ namespace RehauSku.Interface
<customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='rau' label='REHAU'>
<tab id='rau' label='RhSolutions'>
<group id='priceList' label='Прайс-лист'>
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/>
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>

View File

@ -1,6 +1,6 @@
using Microsoft.Office.Interop.Excel;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal abstract class AbstractPriceList
{

View File

@ -1,11 +1,11 @@
using Microsoft.Office.Interop.Excel;
using RehauSku.Interface;
using RhSolutions.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using ProgressBar = RehauSku.Interface.ProgressBar;
using ProgressBar = RhSolutions.Interface.ProgressBar;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal abstract class AbstractTool
{

View File

@ -1,11 +1,11 @@
using Microsoft.Office.Interop.Excel;
using RehauSku.Interface;
using RhSolutions.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using Dialog = RehauSku.Interface.Dialog;
using Dialog = RhSolutions.Interface.Dialog;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal class CombineTool : AbstractTool
{

View File

@ -1,6 +1,6 @@
using RehauSku.Interface;
using RhSolutions.Interface;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal class ConvertTool : AbstractTool
{

View File

@ -1,9 +1,9 @@
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using RehauSku.Interface;
using RhSolutions.Interface;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal class ExportTool : AbstractTool
{

View File

@ -1,9 +1,9 @@
using RehauSku.Interface;
using RhSolutions.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal class MergeTool : AbstractTool
{

View File

@ -1,6 +1,6 @@
using System.Linq;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
public class Position
{

View File

@ -1,4 +1,4 @@
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal static class PriceListHeaders
{

View File

@ -3,9 +3,9 @@ using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using RehauSku.Interface;
using RhSolutions.Interface;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal class SourcePriceList : AbstractPriceList
{

View File

@ -2,7 +2,7 @@
using System;
using System.Linq;
namespace RehauSku.PriceListTools
namespace RhSolutions.PriceListTools
{
internal class TargetPriceList : AbstractPriceList
{

View File

@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RehauSku.Assist")]
[assembly: AssemblyTitle("RhXlPLugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RehauSku.Assist")]
[assembly: AssemblyCopyright("Copyright © 2021-2022")]
[assembly: AssemblyProduct("RhXlPLugin")]
[assembly: AssemblyCopyright("Copyright © 2021-2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="RehauSku.Assist Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<ExternalLibrary Path="RehauSku.Assist.dll" ExplicitRegistration="true" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<DnaLibrary Name="RhXlPLugin" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<ExternalLibrary Path="RhXlPLugin.dll" ExplicitRegistration="true" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<Reference Path="ExcelDna.Registration.dll" Pack="true" />
<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
</DnaLibrary>

22
src/RhSolutions-AddIn.dna Normal file
View File

@ -0,0 +1,22 @@
<?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="RhExcelAddin.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<!--
The RuntimeVersion attribute above allows only the following setting:
* RuntimeVersion="v4.0" - for .NET 4.5 or higher
You can have IntelliSense (autocomplete) and validation for this file.
See https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution/XmlSchemas/
Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example:
<Reference Path="Another.Library.dll" Pack="true" />
Excel-DNA also allows the XML for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at https://excel-dna.net for downloads of the full distribution.
-->
</DnaLibrary>

View File

@ -8,8 +8,8 @@
<ProjectGuid>{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RehauSku.Assist</RootNamespace>
<AssemblyName>RehauSku.Assist</AssemblyName>
<RootNamespace>RhExcelAddin</RootNamespace>
<AssemblyName>RhExcelAddin</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
@ -41,9 +41,6 @@
<Reference Include="ExcelDna.IntelliSense, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDna.IntelliSense.1.6.0\lib\net452\ExcelDna.IntelliSense.dll</HintPath>
</Reference>
<Reference Include="ExcelDna.Registration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDna.Registration.1.6.0\lib\net452\ExcelDna.Registration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDna.Interop.15.0.0\lib\net452\Microsoft.Office.Interop.Excel.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
@ -52,6 +49,9 @@
<HintPath>..\packages\ExcelDna.Interop.15.0.0\lib\net452\Microsoft.Vbe.Interop.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDna.Interop.15.0.0\lib\net452\Office.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
@ -103,9 +103,9 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="RhSolutions-AddIn.dna" />
<None Include="packages.config" />
<None Include="Properties\ExcelDna.Build.props" />
<None Include="RehauSku.Assist-AddIn.dna" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@ -114,10 +114,10 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\ExcelDna.Interop.15.0.0\build\ExcelDna.Interop.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ExcelDna.Interop.15.0.0\build\ExcelDna.Interop.targets'))" />
<Error Condition="!Exists('..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.props'))" />
<Error Condition="!Exists('..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.targets'))" />
<Error Condition="!Exists('..\packages\ExcelDna.Interop.15.0.0\build\ExcelDna.Interop.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ExcelDna.Interop.15.0.0\build\ExcelDna.Interop.targets'))" />
</Target>
<Import Project="..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.targets" Condition="Exists('..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.targets')" />
<Import Project="..\packages\ExcelDna.Interop.15.0.0\build\ExcelDna.Interop.targets" Condition="Exists('..\packages\ExcelDna.Interop.15.0.0\build\ExcelDna.Interop.targets')" />
<Import Project="..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.targets" Condition="Exists('..\packages\ExcelDna.AddIn.1.6.0\build\ExcelDna.AddIn.targets')" />
</Project>

View File

@ -4,6 +4,6 @@
<package id="ExcelDna.Integration" version="1.6.0" targetFramework="net48" />
<package id="ExcelDna.IntelliSense" version="1.6.0" targetFramework="net48" />
<package id="ExcelDna.Interop" version="15.0.0" targetFramework="net48" />
<package id="ExcelDna.Registration" version="1.6.0" targetFramework="net48" />
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net48" />
</packages>