diff options
author | Serghei Cebotari <51533848+schebotar@users.noreply.github.com> | 2022-02-05 13:18:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-05 13:18:18 +0300 |
commit | ad7234fda7927c45e5ca457facae71a4b9be6b31 (patch) | |
tree | d9fc89b0e02a5fdc92d54674b7b48ad2d10859e4 /src/AddIn | |
parent | 180807d749f4eb3a16c1f136d42b90ea2945008f (diff) | |
parent | eb6a28b955b5b179bd40f21dcf1daa6f9337765f (diff) |
Merge pull request #15 from schebotar/dev
Dev
Diffstat (limited to 'src/AddIn')
-rw-r--r-- | src/AddIn/AddIn.cs | 9 | ||||
-rw-r--r-- | src/AddIn/EventsUtil.cs | 33 | ||||
-rw-r--r-- | src/AddIn/RegistryUtil.cs | 8 | ||||
-rw-r--r-- | src/AddIn/SkuExtensions.cs | 12 | ||||
-rw-r--r-- | src/AddIn/WorksheetExtensions.cs | 32 |
5 files changed, 89 insertions, 5 deletions
diff --git a/src/AddIn/AddIn.cs b/src/AddIn/AddIn.cs index 93d8aec..b532bfb 100644 --- a/src/AddIn/AddIn.cs +++ b/src/AddIn/AddIn.cs @@ -5,10 +5,9 @@ using Microsoft.Office.Interop.Excel; using System.Net.Http; using System.Runtime.Caching; - namespace RehauSku { - public enum ResponseOrder + enum ResponseOrder { Default, Relevance, @@ -17,7 +16,7 @@ namespace RehauSku Series } - public class AddIn : IExcelAddIn + class AddIn : IExcelAddIn { public static HttpClient httpClient; public static MemoryCache memoryCache; @@ -27,16 +26,18 @@ namespace RehauSku { httpClient = new HttpClient(); memoryCache = new MemoryCache("RehauSku"); + Excel = (Application)ExcelDnaUtil.Application; RegisterFunctions(); IntelliSenseServer.Install(); RegistryUtil.Initialize(); - Excel = (Application)ExcelDnaUtil.Application; + EventsUtil.Initialize(); } public void AutoClose() { IntelliSenseServer.Uninstall(); RegistryUtil.Uninitialize(); + EventsUtil.Uninitialize(); memoryCache.Dispose(); } diff --git a/src/AddIn/EventsUtil.cs b/src/AddIn/EventsUtil.cs new file mode 100644 index 0000000..102e12e --- /dev/null +++ b/src/AddIn/EventsUtil.cs @@ -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"); + } + } +} diff --git a/src/AddIn/RegistryUtil.cs b/src/AddIn/RegistryUtil.cs index 3ec6f6a..5fe2eea 100644 --- a/src/AddIn/RegistryUtil.cs +++ b/src/AddIn/RegistryUtil.cs @@ -1,5 +1,5 @@ using Microsoft.Win32; -using RehauSku.Forms; +using RehauSku.Interface; using System; using System.IO; using System.Windows.Forms; @@ -38,6 +38,12 @@ namespace RehauSku if (result == DialogResult.OK) { string fileName = Dialog.GetFilePath(); + + if (string.IsNullOrEmpty(fileName)) + { + throw new Exception("Нет файла шаблона"); + } + priceListPath = fileName; RootKey.SetValue("PriceListPath", fileName); return priceListPath; 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); + } + } +} + |