aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AddIn/AddIn.cs18
-rw-r--r--src/AddIn/SkuExtensions.cs (renamed from src/Assistant/SkuExtensions.cs)2
-rw-r--r--src/AddIn/WorksheetExtensions.cs32
-rw-r--r--src/Interface/RibbonController.cs47
-rw-r--r--src/PriceListTools/ExportTool.cs1
-rw-r--r--src/PriceListTools/SourcePriceList.cs6
-rw-r--r--src/RehauSku.Assist.csproj3
7 files changed, 100 insertions, 9 deletions
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
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 @"
- <customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
+ <customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='rau' label='REHAU'>
<group id='priceList' label='Прайс-лист'>
- <button id='exportToPrice' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/>
- <button id='convertPrice' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/>
+ <button id='exportToPrice' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/>
+ <button id='convertPrice' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/>
<menu id='conjoinMenu' label='Объединить' imageMso='Copy'>
<button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/>
<button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/>
@@ -33,6 +36,19 @@ namespace RehauSku.Interface
</customUI>";
}
+ public void RibbonLoad(IRibbonUI sender)
+ {
+ ribbonUi = sender;
+ }
+
+ public static void RefreshControl(string id)
+ {
+ if (ribbonUi != null)
+ {
+ ribbonUi.InvalidateControl(id);
+ }
+ }
+
public void OnMergePressed(IRibbonControl control)
{
MergeTool mergeTool = new MergeTool();
@@ -59,6 +75,19 @@ namespace RehauSku.Interface
}
}
+ public bool GetConvertEnabled(IRibbonControl control)
+ {
+ if (AddIn.Excel.ActiveWorkbook == null)
+ return false;
+
+ else
+ {
+ Worksheet worksheet = AddIn.Excel.ActiveWorkbook.ActiveSheet;
+ return worksheet.IsRehauSource();
+ }
+ }
+
+
public void OnExportPressed(IRibbonControl control)
{
try
@@ -79,6 +108,18 @@ namespace RehauSku.Interface
}
}
+ public bool GetExportEnabled(IRibbonControl control)
+ {
+ if (AddIn.Excel.ActiveWorkbook == null)
+ return false;
+
+ else
+ {
+ Range selection = AddIn.Excel.Selection;
+ return selection.Columns.Count == 2;
+ }
+ }
+
public void OnConvertPressed(IRibbonControl control)
{
ConvertTool convertTool = new ConvertTool();
diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs
index b36bf09..82fd86a 100644
--- a/src/PriceListTools/ExportTool.cs
+++ b/src/PriceListTools/ExportTool.cs
@@ -1,5 +1,4 @@
using Microsoft.Office.Interop.Excel;
-using RehauSku.Assistant;
using System;
using System.Collections.Generic;
using RehauSku.Interface;
diff --git a/src/PriceListTools/SourcePriceList.cs b/src/PriceListTools/SourcePriceList.cs
index ec9025d..01637f8 100644
--- a/src/PriceListTools/SourcePriceList.cs
+++ b/src/PriceListTools/SourcePriceList.cs
@@ -4,10 +4,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
using RehauSku.Interface;
-using RehauSku.Assistant;
namespace RehauSku.PriceListTools
{
+
internal class SourcePriceList : AbstractPriceList
{
public Dictionary<Position, double> PositionAmount { get; private set; }
@@ -22,7 +22,7 @@ namespace RehauSku.PriceListTools
Sheet = workbook.ActiveSheet;
Name = workbook.Name;
- Range[] cells = new []
+ Range[] cells = new[]
{
amountCell = Sheet.Cells.Find(amountHeader),
skuCell = Sheet.Cells.Find(skuHeader),
@@ -30,7 +30,7 @@ namespace RehauSku.PriceListTools
nameCell = Sheet.Cells.Find(nameHeader)
};
- if (cells.Any(x => x == null))
+ if (cells.Any(x => x == null))
{
throw new ArgumentException($"Файл {Name} не распознан");
}
diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj
index f4b4695..9ffc4c4 100644
--- a/src/RehauSku.Assist.csproj
+++ b/src/RehauSku.Assist.csproj
@@ -121,7 +121,7 @@
<Compile Include="AddIn\MemoryCacheUtil.cs" />
<Compile Include="Assistant\ParseUtil.cs" />
<Compile Include="Assistant\RequestModifier.cs" />
- <Compile Include="Assistant\SkuExtensions.cs" />
+ <Compile Include="AddIn\SkuExtensions.cs" />
<Compile Include="Interface\ProgressBar.cs" />
<Compile Include="Interface\ResultBar.cs" />
<Compile Include="PriceListTools\CombineTool.cs" />
@@ -139,6 +139,7 @@
<Compile Include="AddIn\AddIn.cs" />
<Compile Include="Assistant\IProduct.cs" />
<Compile Include="AddIn\Functions.cs" />
+ <Compile Include="AddIn\WorksheetExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Assistant\SkuAssist.cs" />
</ItemGroup>