From cc96e1ebe7255c7278c70cef0f951103e9844487 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 4 Feb 2022 17:13:47 +0300 Subject: Implement Enable/Disable tools buttons events --- src/AddIn/AddIn.cs | 18 ++++++++++++++ src/AddIn/SkuExtensions.cs | 12 +++++++++ src/AddIn/WorksheetExtensions.cs | 32 ++++++++++++++++++++++++ src/Assistant/SkuExtensions.cs | 12 --------- src/Interface/RibbonController.cs | 47 ++++++++++++++++++++++++++++++++--- src/PriceListTools/ExportTool.cs | 1 - src/PriceListTools/SourcePriceList.cs | 6 ++--- src/RehauSku.Assist.csproj | 3 ++- 8 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 src/AddIn/SkuExtensions.cs create mode 100644 src/AddIn/WorksheetExtensions.cs delete mode 100644 src/Assistant/SkuExtensions.cs diff --git a/src/AddIn/AddIn.cs b/src/AddIn/AddIn.cs index b0fcc3b..ad77247 100644 --- a/src/AddIn/AddIn.cs +++ b/src/AddIn/AddIn.cs @@ -31,6 +31,24 @@ namespace RehauSku IntelliSenseServer.Install(); RegistryUtil.Initialize(); Excel = (Application)ExcelDnaUtil.Application; + 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() diff --git a/src/AddIn/SkuExtensions.cs b/src/AddIn/SkuExtensions.cs new file mode 100644 index 0000000..c7fe2bc --- /dev/null +++ b/src/AddIn/SkuExtensions.cs @@ -0,0 +1,12 @@ +using System.Text.RegularExpressions; + +namespace RehauSku +{ + static class SkuExtensions + { + public static bool IsRehauSku(this string line) + { + return Regex.IsMatch(line, @"^[1]\d{6}[1]\d{3}$"); + } + } +} \ No newline at end of file diff --git a/src/AddIn/WorksheetExtensions.cs b/src/AddIn/WorksheetExtensions.cs new file mode 100644 index 0000000..51ce13a --- /dev/null +++ b/src/AddIn/WorksheetExtensions.cs @@ -0,0 +1,32 @@ +using Microsoft.Office.Interop.Excel; +using System.Linq; + +namespace RehauSku +{ + public static class WorksheetExtensions + { + private static string amountHeader = "Кол-во"; + private static string skuHeader = "Актуальный материал"; + private static string groupHeader = "Программа"; + private static string nameHeader = "Наименование"; + + public static bool IsRehauSource(this Worksheet worksheet) + { + Range amountCell; + Range skuCell; + Range groupCell; + Range nameCell; + + Range[] cells = new[] + { + amountCell = worksheet.Cells.Find(amountHeader), + skuCell = worksheet.Cells.Find(skuHeader), + groupCell = worksheet.Cells.Find(groupHeader), + nameCell = worksheet.Cells.Find(nameHeader) + }; + + return cells.All(x => x != null); + } + } +} + diff --git a/src/Assistant/SkuExtensions.cs b/src/Assistant/SkuExtensions.cs deleted file mode 100644 index e39807b..0000000 --- a/src/Assistant/SkuExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.RegularExpressions; - -namespace RehauSku.Assistant -{ - static class SkuExtensions - { - public static bool IsRehauSku(this string line) - { - return Regex.IsMatch(line, @"^[1]\d{6}[1]\d{3}$"); - } - } -} \ No newline at end of file diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs index 822fe98..7d70391 100644 --- a/src/Interface/RibbonController.cs +++ b/src/Interface/RibbonController.cs @@ -1,4 +1,5 @@ using ExcelDna.Integration.CustomUI; +using Microsoft.Office.Interop.Excel; using RehauSku.PriceListTools; using System; using System.Runtime.InteropServices; @@ -9,16 +10,18 @@ namespace RehauSku.Interface [ComVisible(true)] public class RibbonController : ExcelRibbon { + private static IRibbonUI ribbonUi; + public override string GetCustomUI(string RibbonID) { return @" - + -