aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn
diff options
context:
space:
mode:
Diffstat (limited to 'src/AddIn')
-rw-r--r--src/AddIn/AddIn.cs9
-rw-r--r--src/AddIn/EventsUtil.cs33
-rw-r--r--src/AddIn/RegistryUtil.cs8
-rw-r--r--src/AddIn/SkuExtensions.cs12
-rw-r--r--src/AddIn/WorksheetExtensions.cs32
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);
+ }
+ }
+}
+