Create EventsUtil

This commit is contained in:
Sergey Chebotar 2022-02-05 12:59:16 +03:00
parent cc96e1ebe7
commit 880b95f862
3 changed files with 37 additions and 20 deletions

View File

@ -5,7 +5,6 @@ using Microsoft.Office.Interop.Excel;
using System.Net.Http; using System.Net.Http;
using System.Runtime.Caching; using System.Runtime.Caching;
namespace RehauSku namespace RehauSku
{ {
enum ResponseOrder enum ResponseOrder
@ -27,34 +26,18 @@ namespace RehauSku
{ {
httpClient = new HttpClient(); httpClient = new HttpClient();
memoryCache = new MemoryCache("RehauSku"); memoryCache = new MemoryCache("RehauSku");
Excel = (Application)ExcelDnaUtil.Application;
RegisterFunctions(); RegisterFunctions();
IntelliSenseServer.Install(); IntelliSenseServer.Install();
RegistryUtil.Initialize(); RegistryUtil.Initialize();
Excel = (Application)ExcelDnaUtil.Application; EventsUtil.Initialize();
AddEvents();
}
private void AddEvents()
{
Excel.SheetSelectionChange += RefreshExportButton;
Excel.SheetActivate += RefreshConvertButton;
Excel.WorkbookActivate += RefreshConvertButton;
}
private void RefreshConvertButton(object sh)
{
Interface.RibbonController.RefreshControl("convertPrice");
}
private void RefreshExportButton(object sh, Range target)
{
Interface.RibbonController.RefreshControl("exportToPrice");
} }
public void AutoClose() public void AutoClose()
{ {
IntelliSenseServer.Uninstall(); IntelliSenseServer.Uninstall();
RegistryUtil.Uninitialize(); RegistryUtil.Uninitialize();
EventsUtil.Uninitialize();
memoryCache.Dispose(); memoryCache.Dispose();
} }

33
src/AddIn/EventsUtil.cs Normal file
View File

@ -0,0 +1,33 @@
using Microsoft.Office.Interop.Excel;
namespace RehauSku
{
internal static class EventsUtil
{
private static Application Excel = AddIn.Excel;
public static void Initialize()
{
Excel.SheetSelectionChange += RefreshExportButton;
Excel.SheetActivate += RefreshConvertButton;
Excel.WorkbookActivate += RefreshConvertButton;
}
public static void Uninitialize()
{
Excel.SheetSelectionChange -= RefreshExportButton;
Excel.SheetActivate -= RefreshConvertButton;
Excel.WorkbookActivate -= RefreshConvertButton;
}
private static void RefreshConvertButton(object sh)
{
Interface.RibbonController.RefreshControl("convertPrice");
}
private static void RefreshExportButton(object sh, Range target)
{
Interface.RibbonController.RefreshControl("exportToPrice");
}
}
}

View File

@ -115,6 +115,7 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AddIn\EventsUtil.cs" />
<Compile Include="Interface\AbstractBar.cs" /> <Compile Include="Interface\AbstractBar.cs" />
<Compile Include="Interface\Dialog.cs" /> <Compile Include="Interface\Dialog.cs" />
<Compile Include="AddIn\RegistryUtil.cs" /> <Compile Include="AddIn\RegistryUtil.cs" />