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/Assistant/SkuExtensions.cs b/src/AddIn/SkuExtensions.cs similarity index 88% rename from src/Assistant/SkuExtensions.cs rename to src/AddIn/SkuExtensions.cs index e39807b..c7fe2bc 100644 --- a/src/Assistant/SkuExtensions.cs +++ b/src/AddIn/SkuExtensions.cs @@ -1,6 +1,6 @@ using System.Text.RegularExpressions; -namespace RehauSku.Assistant +namespace RehauSku { static class SkuExtensions { 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/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 @" - + -