aboutsummaryrefslogtreecommitdiff
path: root/src/Interface
diff options
context:
space:
mode:
Diffstat (limited to 'src/Interface')
-rw-r--r--src/Interface/AbstractBar.cs11
-rw-r--r--src/Interface/Dialog.cs62
-rw-r--r--src/Interface/ProgressBar.cs31
-rw-r--r--src/Interface/ResultBar.cs44
-rw-r--r--src/Interface/RibbonController.cs140
5 files changed, 288 insertions, 0 deletions
diff --git a/src/Interface/AbstractBar.cs b/src/Interface/AbstractBar.cs
new file mode 100644
index 0000000..c5918a8
--- /dev/null
+++ b/src/Interface/AbstractBar.cs
@@ -0,0 +1,11 @@
+using Microsoft.Office.Interop.Excel;
+
+namespace RehauSku.Interface
+{
+ internal abstract class AbstractBar
+ {
+ protected Application Excel = AddIn.Excel;
+
+ public abstract void Update();
+ }
+}
diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs
new file mode 100644
index 0000000..23f65d7
--- /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()
+ {
+ 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;
+ }
+ }
+
+ public static void SaveWorkbookAs()
+ {
+ Workbook workbook = AddIn.Excel.ActiveWorkbook;
+
+ using (SaveFileDialog dialog = new SaveFileDialog())
+ {
+ dialog.FileName = workbook.Name;
+ dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
+
+ if (dialog.ShowDialog() == DialogResult.Cancel)
+ {
+ workbook.Close(false);
+ }
+
+ else
+ {
+ string fileName = dialog.FileName;
+ workbook.SaveAs(fileName);
+ }
+ }
+ }
+ }
+}
diff --git a/src/Interface/ProgressBar.cs b/src/Interface/ProgressBar.cs
new file mode 100644
index 0000000..2e68e8b
--- /dev/null
+++ b/src/Interface/ProgressBar.cs
@@ -0,0 +1,31 @@
+namespace RehauSku.Interface
+{
+ internal class ProgressBar : AbstractBar
+ {
+ private double CurrentProgress { get; set; }
+ private readonly double TaskWeight;
+ private readonly string Message;
+
+ public ProgressBar(string message, int weight)
+ {
+ Message = message;
+ TaskWeight = weight;
+ CurrentProgress = 0;
+ }
+
+ public override void Update()
+ {
+ double percent = (++CurrentProgress / TaskWeight) * 100;
+
+ if (percent < 100)
+ {
+ Excel.StatusBar = $"{Message} Выполнено {percent.ToString("#.#")} %";
+ }
+
+ else
+ {
+ Excel.StatusBar = false;
+ }
+ }
+ }
+}
diff --git a/src/Interface/ResultBar.cs b/src/Interface/ResultBar.cs
new file mode 100644
index 0000000..1b4d7f4
--- /dev/null
+++ b/src/Interface/ResultBar.cs
@@ -0,0 +1,44 @@
+using System.Text;
+
+namespace RehauSku.Interface
+{
+ internal class ResultBar : AbstractBar
+ {
+ private int Success { get; set; }
+ private int Replaced { get; set; }
+ private int NotFound { get; set; }
+
+ public ResultBar()
+ {
+ Success = 0;
+ Replaced = 0;
+ NotFound = 0;
+ }
+
+ public void IncrementSuccess() => Success++;
+ public void IncrementReplaced() => Replaced++;
+ public void IncrementNotFound() => NotFound++;
+
+ public override void Update()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ if (Success > 0)
+ {
+ sb.Append($"Успешно экспортировано {Success} артикулов. ");
+ }
+
+ if (Replaced > 0)
+ {
+ sb.Append($"Заменено {Replaced} артикулов. ");
+ }
+
+ if (NotFound > 0)
+ {
+ sb.Append($"Не найдено {NotFound} артикулов.");
+ }
+
+ Excel.StatusBar = sb.ToString();
+ }
+ }
+}
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;
+ }
+ }
+ }
+}