Implement Enable/Disable tools buttons events
This commit is contained in:
parent
6e889419e2
commit
cc96e1ebe7
@ -31,6 +31,24 @@ namespace RehauSku
|
|||||||
IntelliSenseServer.Install();
|
IntelliSenseServer.Install();
|
||||||
RegistryUtil.Initialize();
|
RegistryUtil.Initialize();
|
||||||
Excel = (Application)ExcelDnaUtil.Application;
|
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()
|
public void AutoClose()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace RehauSku.Assistant
|
namespace RehauSku
|
||||||
{
|
{
|
||||||
static class SkuExtensions
|
static class SkuExtensions
|
||||||
{
|
{
|
32
src/AddIn/WorksheetExtensions.cs
Normal file
32
src/AddIn/WorksheetExtensions.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
using ExcelDna.Integration.CustomUI;
|
using ExcelDna.Integration.CustomUI;
|
||||||
|
using Microsoft.Office.Interop.Excel;
|
||||||
using RehauSku.PriceListTools;
|
using RehauSku.PriceListTools;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -9,16 +10,18 @@ namespace RehauSku.Interface
|
|||||||
[ComVisible(true)]
|
[ComVisible(true)]
|
||||||
public class RibbonController : ExcelRibbon
|
public class RibbonController : ExcelRibbon
|
||||||
{
|
{
|
||||||
|
private static IRibbonUI ribbonUi;
|
||||||
|
|
||||||
public override string GetCustomUI(string RibbonID)
|
public override string GetCustomUI(string RibbonID)
|
||||||
{
|
{
|
||||||
return @"
|
return @"
|
||||||
<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
|
<customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
|
||||||
<ribbon>
|
<ribbon>
|
||||||
<tabs>
|
<tabs>
|
||||||
<tab id='rau' label='REHAU'>
|
<tab id='rau' label='REHAU'>
|
||||||
<group id='priceList' label='Прайс-лист'>
|
<group id='priceList' label='Прайс-лист'>
|
||||||
<button id='exportToPrice' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/>
|
<button id='exportToPrice' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/>
|
||||||
<button id='convertPrice' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/>
|
<button id='convertPrice' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/>
|
||||||
<menu id='conjoinMenu' label='Объединить' imageMso='Copy'>
|
<menu id='conjoinMenu' label='Объединить' imageMso='Copy'>
|
||||||
<button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/>
|
<button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/>
|
||||||
<button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/>
|
<button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/>
|
||||||
@ -33,6 +36,19 @@ namespace RehauSku.Interface
|
|||||||
</customUI>";
|
</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)
|
public void OnMergePressed(IRibbonControl control)
|
||||||
{
|
{
|
||||||
MergeTool mergeTool = new MergeTool();
|
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)
|
public void OnExportPressed(IRibbonControl control)
|
||||||
{
|
{
|
||||||
try
|
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)
|
public void OnConvertPressed(IRibbonControl control)
|
||||||
{
|
{
|
||||||
ConvertTool convertTool = new ConvertTool();
|
ConvertTool convertTool = new ConvertTool();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
using RehauSku.Assistant;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using RehauSku.Interface;
|
using RehauSku.Interface;
|
||||||
|
@ -4,10 +4,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using RehauSku.Interface;
|
using RehauSku.Interface;
|
||||||
using RehauSku.Assistant;
|
|
||||||
|
|
||||||
namespace RehauSku.PriceListTools
|
namespace RehauSku.PriceListTools
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class SourcePriceList : AbstractPriceList
|
internal class SourcePriceList : AbstractPriceList
|
||||||
{
|
{
|
||||||
public Dictionary<Position, double> PositionAmount { get; private set; }
|
public Dictionary<Position, double> PositionAmount { get; private set; }
|
||||||
@ -22,7 +22,7 @@ namespace RehauSku.PriceListTools
|
|||||||
Sheet = workbook.ActiveSheet;
|
Sheet = workbook.ActiveSheet;
|
||||||
Name = workbook.Name;
|
Name = workbook.Name;
|
||||||
|
|
||||||
Range[] cells = new []
|
Range[] cells = new[]
|
||||||
{
|
{
|
||||||
amountCell = Sheet.Cells.Find(amountHeader),
|
amountCell = Sheet.Cells.Find(amountHeader),
|
||||||
skuCell = Sheet.Cells.Find(skuHeader),
|
skuCell = Sheet.Cells.Find(skuHeader),
|
||||||
@ -30,7 +30,7 @@ namespace RehauSku.PriceListTools
|
|||||||
nameCell = Sheet.Cells.Find(nameHeader)
|
nameCell = Sheet.Cells.Find(nameHeader)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cells.Any(x => x == null))
|
if (cells.Any(x => x == null))
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Файл {Name} не распознан");
|
throw new ArgumentException($"Файл {Name} не распознан");
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
<Compile Include="AddIn\MemoryCacheUtil.cs" />
|
<Compile Include="AddIn\MemoryCacheUtil.cs" />
|
||||||
<Compile Include="Assistant\ParseUtil.cs" />
|
<Compile Include="Assistant\ParseUtil.cs" />
|
||||||
<Compile Include="Assistant\RequestModifier.cs" />
|
<Compile Include="Assistant\RequestModifier.cs" />
|
||||||
<Compile Include="Assistant\SkuExtensions.cs" />
|
<Compile Include="AddIn\SkuExtensions.cs" />
|
||||||
<Compile Include="Interface\ProgressBar.cs" />
|
<Compile Include="Interface\ProgressBar.cs" />
|
||||||
<Compile Include="Interface\ResultBar.cs" />
|
<Compile Include="Interface\ResultBar.cs" />
|
||||||
<Compile Include="PriceListTools\CombineTool.cs" />
|
<Compile Include="PriceListTools\CombineTool.cs" />
|
||||||
@ -139,6 +139,7 @@
|
|||||||
<Compile Include="AddIn\AddIn.cs" />
|
<Compile Include="AddIn\AddIn.cs" />
|
||||||
<Compile Include="Assistant\IProduct.cs" />
|
<Compile Include="Assistant\IProduct.cs" />
|
||||||
<Compile Include="AddIn\Functions.cs" />
|
<Compile Include="AddIn\Functions.cs" />
|
||||||
|
<Compile Include="AddIn\WorksheetExtensions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Assistant\SkuAssist.cs" />
|
<Compile Include="Assistant\SkuAssist.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user