aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-03-28 09:58:43 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-03-28 09:58:43 +0300
commitde2f7f43ec802e79ab7cdf67642168d39ef53fa2 (patch)
tree21f94e9745260c903eac4dc8bcea5cd9efc41415
parent7bb6ce6c5a094975b0331d42eae7cc25c763600d (diff)
Switch to Excel internal file dialogs
-rw-r--r--RhSolutions.AddIn/Controllers/CombineTool.cs17
-rw-r--r--RhSolutions.AddIn/Controllers/MergeTool.cs20
-rw-r--r--RhSolutions.AddIn/Controllers/RibbonController.cs35
-rw-r--r--RhSolutions.AddIn/Models/Dialog.cs40
4 files changed, 41 insertions, 71 deletions
diff --git a/RhSolutions.AddIn/Controllers/CombineTool.cs b/RhSolutions.AddIn/Controllers/CombineTool.cs
index 4d84d44..ea4e782 100644
--- a/RhSolutions.AddIn/Controllers/CombineTool.cs
+++ b/RhSolutions.AddIn/Controllers/CombineTool.cs
@@ -1,9 +1,9 @@
using Microsoft.Office.Interop.Excel;
+using RhSolutions.AddIn;
using RhSolutions.Models;
using System;
using System.Collections.Generic;
using System.Linq;
-using Dialog = RhSolutions.Models.Dialog;
using Range = Microsoft.Office.Interop.Excel.Range;
namespace RhSolutions.Controllers
@@ -14,11 +14,20 @@ namespace RhSolutions.Controllers
public CombineTool()
{
- string[] files = Dialog.GetMultiplyFiles();
+ var dialog = RhSolutionsAddIn.Excel.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
+ dialog.AllowMultiSelect = true;
+ dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
- if (files != null)
+ if (dialog.Show() < 0)
{
- SourceFiles = SourcePriceList.GetSourceLists(files);
+ List<string> files = new();
+
+ foreach (string file in dialog.SelectedItems)
+ {
+ files.Add(file);
+ }
+
+ SourceFiles = SourcePriceList.GetSourceLists(files.ToArray());
}
else
diff --git a/RhSolutions.AddIn/Controllers/MergeTool.cs b/RhSolutions.AddIn/Controllers/MergeTool.cs
index dec8ff7..8566ee7 100644
--- a/RhSolutions.AddIn/Controllers/MergeTool.cs
+++ b/RhSolutions.AddIn/Controllers/MergeTool.cs
@@ -1,4 +1,5 @@
-using RhSolutions.Models;
+using RhSolutions.AddIn;
+using RhSolutions.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,12 +12,21 @@ namespace RhSolutions.Controllers
public MergeTool()
{
- string[] files = Dialog.GetMultiplyFiles();
+ var dialog = RhSolutionsAddIn.Excel.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
+ dialog.AllowMultiSelect = true;
+ dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
- if (files != null)
+ if ( dialog.Show() < 0)
{
- SourceFiles = SourcePriceList.GetSourceLists(files);
- }
+ List<string> files = new();
+
+ foreach (string file in dialog.SelectedItems)
+ {
+ files.Add(file);
+ }
+
+ SourceFiles = SourcePriceList.GetSourceLists(files.ToArray());
+ }
else
{
diff --git a/RhSolutions.AddIn/Controllers/RibbonController.cs b/RhSolutions.AddIn/Controllers/RibbonController.cs
index b95bb4f..d819b4b 100644
--- a/RhSolutions.AddIn/Controllers/RibbonController.cs
+++ b/RhSolutions.AddIn/Controllers/RibbonController.cs
@@ -1,5 +1,4 @@
using ExcelDna.Integration.CustomUI;
-using Microsoft.Extensions.DependencyInjection;
using Microsoft.Office.Interop.Excel;
using RhSolutions.AddIn;
using RhSolutions.Services;
@@ -55,11 +54,14 @@ namespace RhSolutions.Controllers
public void OnSetPricePressed(IRibbonControl control)
{
- string path = Models.Dialog.GetFilePath();
+ var dialog = RhSolutionsAddIn.Excel
+ .FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
+ dialog.AllowMultiSelect = false;
+ dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
- if (!string.IsNullOrEmpty(path))
+ if (dialog.Show() < 0)
{
- RhSolutionsAddIn.Configuration.SetPriceListPath(path);
+ RhSolutionsAddIn.Configuration.SetPriceListPath(dialog.SelectedItems.Item(1));
RhSolutionsAddIn.Configuration.SaveSettings();
}
}
@@ -68,25 +70,14 @@ namespace RhSolutions.Controllers
{
try
{
- ToolBase tool;
- switch (control.Id)
+ ToolBase tool = control.Id switch
{
- 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("Неизвестный инструмент");
- }
-
+ "export" => new ExportTool(),
+ "convert" => new ConvertTool(),
+ "merge" => new MergeTool(),
+ "combine" => new CombineTool(),
+ _ => throw new Exception("Неизвестный инструмент"),
+ };
tool.OpenNewPrice();
tool.FillTarget();
}
diff --git a/RhSolutions.AddIn/Models/Dialog.cs b/RhSolutions.AddIn/Models/Dialog.cs
deleted file mode 100644
index abc89b8..0000000
--- a/RhSolutions.AddIn/Models/Dialog.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using Microsoft.Office.Interop.Excel;
-using System.Collections.Generic;
-using System.Windows.Forms;
-
-namespace RhSolutions.Models
-{
- static class Dialog
- {
- public static string GetFilePath()
- {
- using (OpenFileDialog dialog = new OpenFileDialog())
- {
- dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- return dialog.FileName;
- }
-
- else return string.Empty;
- }
- }
-
- public static string[] GetMultiplyFiles()
- {
- using (OpenFileDialog dialog = new OpenFileDialog())
- {
- dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
- dialog.Multiselect = true;
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- return dialog.FileNames;
- }
-
- else return null;
- }
- }
- }
-}