diff options
author | Serghei Cebotari <51533848+schebotar@users.noreply.github.com> | 2022-02-14 11:09:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-14 11:09:22 +0300 |
commit | 031ea7f7ef0c690d93bb7e653e59c7dac6964dbb (patch) | |
tree | 34bb5c7808434a8dad116a052274c271b92f560c /src/Interface | |
parent | 14aa7249fb6ada16416689f013e1f014727bc83a (diff) | |
parent | f190e27948255303c73a6b457ad1c3af1c88dba9 (diff) |
Merge pull request #17 from schebotar/dev
Dev
Diffstat (limited to 'src/Interface')
-rw-r--r-- | src/Interface/ProgressBar.cs | 2 | ||||
-rw-r--r-- | src/Interface/RibbonController.cs | 102 |
2 files changed, 50 insertions, 54 deletions
diff --git a/src/Interface/ProgressBar.cs b/src/Interface/ProgressBar.cs index 2e68e8b..416c7d6 100644 --- a/src/Interface/ProgressBar.cs +++ b/src/Interface/ProgressBar.cs @@ -19,7 +19,7 @@ if (percent < 100) { - Excel.StatusBar = $"{Message} Выполнено {percent.ToString("#.#")} %"; + Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; } else 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; } } } |