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/Interface/RibbonController.cs | |
parent | 180807d749f4eb3a16c1f136d42b90ea2945008f (diff) | |
parent | eb6a28b955b5b179bd40f21dcf1daa6f9337765f (diff) |
Merge pull request #15 from schebotar/dev
Dev
Diffstat (limited to 'src/Interface/RibbonController.cs')
-rw-r--r-- | src/Interface/RibbonController.cs | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs new file mode 100644 index 0000000..bc038d1 --- /dev/null +++ b/src/Interface/RibbonController.cs @@ -0,0 +1,140 @@ +using ExcelDna.Integration.CustomUI; +using Microsoft.Office.Interop.Excel; +using RehauSku.PriceListTools; +using System; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace RehauSku.Interface +{ + [ComVisible(true)] + public class RibbonController : ExcelRibbon + { + private static IRibbonUI ribbonUi; + + public override string GetCustomUI(string RibbonID) + { + return @" + <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' 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'/> + </menu> + </group> + <group id='rausettings' label='Настройки'> + <button id='setPriceList' label='Указать путь к шаблону' size='large' imageMso='CurrentViewSettings' onAction='OnSetPricePressed'/> + </group> + </tab> + </tabs> + </ribbon> + </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(); + string[] files = Dialog.GetMultiplyFiles(); + + if (files != null) + { + mergeTool.SourceFiles = SourcePriceList.GetSourceLists(files); + mergeTool.OpenNewPrice(); + mergeTool.FillTarget(); + } + } + + public void OnCombinePressed(IRibbonControl control) + { + CombineTool combineTool = new CombineTool(); + string[] files = Dialog.GetMultiplyFiles(); + + if (files != null) + { + combineTool.SourceFiles = SourcePriceList.GetSourceLists(files); + combineTool.OpenNewPrice(); + combineTool.FillTarget(); + } + } + + 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 + { + ExportTool exportTool = new ExportTool(); + exportTool.OpenNewPrice(); + exportTool.FillTarget(); + } + + catch (Exception ex) + { + MessageBox.Show(ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + return; + } + } + + 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(); + + convertTool.GetCurrent(); + convertTool.OpenNewPrice(); + convertTool.FillTarget(); + } + + public void OnSetPricePressed(IRibbonControl control) + { + string path = Dialog.GetFilePath(); + + if (!string.IsNullOrEmpty(path)) + { + RegistryUtil.PriceListPath = path; + } + } + } +} |