diff options
Diffstat (limited to 'src/Interface')
-rw-r--r-- | src/Interface/Dialog.cs | 62 | ||||
-rw-r--r-- | src/Interface/RibbonController.cs | 97 |
2 files changed, 159 insertions, 0 deletions
diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs new file mode 100644 index 0000000..c888703 --- /dev/null +++ b/src/Interface/Dialog.cs @@ -0,0 +1,62 @@ +using Microsoft.Office.Interop.Excel; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace RehauSku.Interface +{ + static class Dialog + { + public static string GetFilePath() + { + string filePath = string.Empty; + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + filePath = dialog.FileName; + } + } + + return filePath; + } + + public static string[] GetMultiplyFiles() + { + List<string> fileNames = new List<string>(); + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + dialog.Multiselect = true; + + if (dialog.ShowDialog() == DialogResult.OK) + { + foreach (string file in dialog.FileNames) + { + fileNames.Add(file); + } + } + } + + return fileNames.ToArray(); + } + + public static void SaveWorkbookAs() + { + Workbook wb = AddIn.Excel.ActiveWorkbook; + string currentFilename = wb.FullName; + string fileFilter = "Файлы Excel (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm"; + + object fileName = AddIn.Excel.GetSaveAsFilename(currentFilename, fileFilter); + + if (fileName.GetType() == typeof(string)) + wb.SaveAs(fileName); + + else + wb.Close(false); + } + } +} diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs new file mode 100644 index 0000000..cd7058d --- /dev/null +++ b/src/Interface/RibbonController.cs @@ -0,0 +1,97 @@ +using ExcelDna.Integration.CustomUI; +using RehauSku.PriceListTools; +using System; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace RehauSku.Interface +{ + [ComVisible(true)] + public class RibbonController : ExcelRibbon + { + public override string GetCustomUI(string RibbonID) + { + return @" + <customUI 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'/> + <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 OnMergePressed(IRibbonControl control) + { + MergeTool mergeTool = new MergeTool(); + string[] files = Dialog.GetMultiplyFiles(); + + if (files.Length != 0) + { + mergeTool.SourceFiles = Source.GetSourceLists(files); + mergeTool.OpenNewPrice(); + mergeTool.FillTarget(); + } + } + + public void OnCombinePressed(IRibbonControl control) + { + CombineTool combineTool = new CombineTool(); + string[] files = Dialog.GetMultiplyFiles(); + + if (files.Length != 0) + { + combineTool.SourceFiles = Source.GetSourceLists(files); + combineTool.OpenNewPrice(); + combineTool.FillTarget(); + } + } + + public void OnExportPressed(IRibbonControl control) + { + try + { + ExportTool exportTool = new ExportTool(); + exportTool.TryGetSelection(); + exportTool.OpenNewPrice(); + exportTool.FillTarget(); + } + + catch (Exception ex) + { + MessageBox.Show(ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + return; + } + } + + public void OnConvertPressed(IRibbonControl control) + { + ConvertTool convertTool = new ConvertTool(); + + convertTool.GetCurrent(); + convertTool.OpenNewPrice(); + convertTool.FillTarget(); + } + + public void OnSetPricePressed(IRibbonControl control) + { + string path = Dialog.GetFilePath(); + RegistryUtil.PriceListPath = path; + } + } +} |