diff options
Diffstat (limited to 'src/Interface/RibbonController.cs')
-rw-r--r-- | src/Interface/RibbonController.cs | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs index bc038d1..7bf9ee1 100644 --- a/src/Interface/RibbonController.cs +++ b/src/Interface/RibbonController.cs @@ -2,6 +2,8 @@ using Microsoft.Office.Interop.Excel; using RehauSku.PriceListTools; using System; +using System.IO; +using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -20,15 +22,15 @@ namespace RehauSku.Interface <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'/> + <button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/> + <button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/> <menu id='conjoinMenu' label='Объединить' imageMso='Copy'> - <button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/> - <button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/> + <button id='merge' label='Сложить' onAction='OnToolPressed'/> + <button id='combine' label='По колонкам' onAction='OnToolPressed'/> </menu> </group> - <group id='rausettings' label='Настройки'> - <button id='setPriceList' label='Указать путь к шаблону' size='large' imageMso='CurrentViewSettings' onAction='OnSetPricePressed'/> + <group id='rausettings' getLabel='GetVersionLabel'> + <button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' imageMso='TableExcelSpreadsheetInsert' onAction='OnSetPricePressed'/> </group> </tab> </tabs> @@ -48,30 +50,50 @@ namespace RehauSku.Interface ribbonUi.InvalidateControl(id); } } - - public void OnMergePressed(IRibbonControl control) + public void OnSetPricePressed(IRibbonControl control) { - MergeTool mergeTool = new MergeTool(); - string[] files = Dialog.GetMultiplyFiles(); + string path = Dialog.GetFilePath(); - if (files != null) + if (!string.IsNullOrEmpty(path)) { - mergeTool.SourceFiles = SourcePriceList.GetSourceLists(files); - mergeTool.OpenNewPrice(); - mergeTool.FillTarget(); + RegistryUtil.PriceListPath = path; } } - public void OnCombinePressed(IRibbonControl control) + public void OnToolPressed(IRibbonControl control) { - CombineTool combineTool = new CombineTool(); - string[] files = Dialog.GetMultiplyFiles(); + try + { + AbstractTool tool; + switch (control.Id) + { + case "export": + tool = new ExportTool(); + break; + case "convert": + tool = new ConvertTool(); + break; + case "merge": + tool = new MergeTool(); + break; + case "combine": + tool = new CombineTool(); + break; + default: + throw new Exception("Неизвестный инструмент"); + } + + tool.OpenNewPrice(); + tool.FillTarget(); + } - if (files != null) + catch (Exception exception) { - combineTool.SourceFiles = SourcePriceList.GetSourceLists(files); - combineTool.OpenNewPrice(); - combineTool.FillTarget(); + MessageBox.Show(exception.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + return; } } @@ -87,25 +109,6 @@ namespace RehauSku.Interface } } - 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) @@ -118,23 +121,16 @@ namespace RehauSku.Interface } } - public void OnConvertPressed(IRibbonControl control) + public string GetVersionLabel(IRibbonControl control) { - ConvertTool convertTool = new ConvertTool(); - - convertTool.GetCurrent(); - convertTool.OpenNewPrice(); - convertTool.FillTarget(); + string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + return $"v{version}"; } - public void OnSetPricePressed(IRibbonControl control) + public string GetPriceListPathLabel(IRibbonControl control) { - string path = Dialog.GetFilePath(); - - if (!string.IsNullOrEmpty(path)) - { - RegistryUtil.PriceListPath = path; - } + string name = RegistryUtil.GetPriceListName(); + return string.IsNullOrEmpty(name) ? "Нет файла шаблона!" : name; } } } |