aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Interface/RibbonController.cs96
-rw-r--r--src/PriceListTools/AbstractTool.cs31
-rw-r--r--src/PriceListTools/CombineTool.cs23
-rw-r--r--src/PriceListTools/ConvertTool.cs21
-rw-r--r--src/PriceListTools/ExportTool.cs9
-rw-r--r--src/PriceListTools/MergeTool.cs20
6 files changed, 98 insertions, 102 deletions
diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs
index bc038d1..7a58c7c 100644
--- a/src/Interface/RibbonController.cs
+++ b/src/Interface/RibbonController.cs
@@ -20,11 +20,11 @@ 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='exportToPrice' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/>
+ <button id='convertPrice' 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='mergeFiles' label='Сложить' onAction='OnToolPressed'/>
+ <button id='combineFiles' label='По колонкам' onAction='OnToolPressed'/>
</menu>
</group>
<group id='rausettings' label='Настройки'>
@@ -48,30 +48,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 "exportToPrice":
+ tool = new ExportTool();
+ break;
+ case "convertPrice":
+ tool = new ConvertTool();
+ break;
+ case "mergeFiles":
+ tool = new MergeTool();
+ break;
+ case "combineFiles":
+ 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 +107,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)
@@ -117,24 +118,5 @@ namespace RehauSku.Interface
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;
- }
- }
}
}
diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs
index 68c5250..af60d0d 100644
--- a/src/PriceListTools/AbstractTool.cs
+++ b/src/PriceListTools/AbstractTool.cs
@@ -4,7 +4,6 @@ using RehauSku.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Windows.Forms;
using Application = Microsoft.Office.Interop.Excel.Application;
using ProgressBar = RehauSku.Interface.ProgressBar;
@@ -12,10 +11,12 @@ namespace RehauSku.PriceListTools
{
internal abstract class AbstractTool
{
- protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
- protected private TargetPriceList TargetFile;
- protected private ResultBar ResultBar { get; set; }
- protected private ProgressBar ProgressBar { get; set; }
+ protected Application ExcelApp = (Application)ExcelDnaUtil.Application;
+ protected TargetPriceList TargetFile { get; set; }
+ protected ResultBar ResultBar { get; set; }
+ protected ProgressBar ProgressBar { get; set; }
+
+ public abstract void FillTarget();
public void OpenNewPrice()
{
@@ -23,12 +24,6 @@ namespace RehauSku.PriceListTools
.Cast<Workbook>()
.FirstOrDefault(w => w.FullName == RegistryUtil.PriceListPath) != null)
{
- MessageBox.Show
- ("Шаблонный файл редактируется в другом месте",
- "Ошибка открытия шаблонного прайс-листа",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
-
throw new ArgumentException("Шаблонный файл редактируется в другом месте");
}
@@ -41,12 +36,6 @@ namespace RehauSku.PriceListTools
catch (Exception exception)
{
- MessageBox.Show
- (exception.Message,
- "Ошибка открытия шаблонного прайс-листа",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
-
if (wb != null)
{
wb.Close();
@@ -56,7 +45,7 @@ namespace RehauSku.PriceListTools
}
}
- protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, params int[] columns)
+ protected void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, params int[] columns)
{
int? row = GetPositionRow(TargetFile.skuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group);
@@ -108,7 +97,7 @@ namespace RehauSku.PriceListTools
ResultBar.IncrementNotFound();
}
- protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
+ protected void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
{
int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
.End[XlDirection.xlUp]
@@ -145,7 +134,7 @@ namespace RehauSku.PriceListTools
}
}
- protected private int? GetPositionRow(Range range, string sku, string group)
+ protected int? GetPositionRow(Range range, string sku, string group)
{
Range found = range.Find(sku);
string foundGroupValue;
@@ -175,7 +164,7 @@ namespace RehauSku.PriceListTools
}
}
- protected private void FilterByAmount()
+ protected void FilterByAmount()
{
AutoFilter filter = TargetFile.Sheet.AutoFilter;
int startColumn = filter.Range.Column;
diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs
index af9378c..e3cb83e 100644
--- a/src/PriceListTools/CombineTool.cs
+++ b/src/PriceListTools/CombineTool.cs
@@ -1,15 +1,32 @@
using Microsoft.Office.Interop.Excel;
-using System.Collections.Generic;
using RehauSku.Interface;
+using System;
+using System.Collections.Generic;
using System.Linq;
+using Dialog = RehauSku.Interface.Dialog;
namespace RehauSku.PriceListTools
{
internal class CombineTool : AbstractTool
{
- public List<SourcePriceList> SourceFiles;
+ private List<SourcePriceList> SourceFiles { get; set; }
+
+ public CombineTool()
+ {
+ string[] files = Dialog.GetMultiplyFiles();
+
+ if (files != null)
+ {
+ SourceFiles = SourcePriceList.GetSourceLists(files);
+ }
+
+ else
+ {
+ throw new Exception("Не выбраны файлы");
+ }
+ }
- public void FillTarget()
+ public override void FillTarget()
{
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count));
ResultBar = new ResultBar();
diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs
index d13c803..fc5850f 100644
--- a/src/PriceListTools/ConvertTool.cs
+++ b/src/PriceListTools/ConvertTool.cs
@@ -5,27 +5,14 @@ namespace RehauSku.PriceListTools
{
internal class ConvertTool : AbstractTool
{
- private SourcePriceList Current;
+ private SourcePriceList Current { get; set; }
- public void GetCurrent()
+ public ConvertTool()
{
- try
- {
- Current = new SourcePriceList(ExcelApp.ActiveWorkbook);
- }
-
- catch (Exception exception)
- {
- System.Windows.Forms.MessageBox.Show
- (exception.Message,
- "Ошибка распознавания",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Information);
- throw exception;
- }
+ Current = new SourcePriceList(ExcelApp.ActiveWorkbook);
}
- public void FillTarget()
+ public override void FillTarget()
{
ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count);
ResultBar = new ResultBar();
diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs
index f341671..acc6515 100644
--- a/src/PriceListTools/ExportTool.cs
+++ b/src/PriceListTools/ExportTool.cs
@@ -13,11 +13,16 @@ namespace RehauSku.PriceListTools
public ExportTool()
{
Selection = ExcelApp.Selection;
+ GetSelected();
+
+ if (PositionAmount.Count == 0)
+ {
+ throw new Exception("В выделенном диапазоне не найдены позиции для экспорта");
+ }
}
- public void FillTarget()
+ public override void FillTarget()
{
- GetSelected();
ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count);
ResultBar = new ResultBar();
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs
index 0e3f1dc..77732bf 100644
--- a/src/PriceListTools/MergeTool.cs
+++ b/src/PriceListTools/MergeTool.cs
@@ -1,4 +1,5 @@
using RehauSku.Interface;
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -6,9 +7,24 @@ namespace RehauSku.PriceListTools
{
internal class MergeTool : AbstractTool
{
- public List<SourcePriceList> SourceFiles;
+ private List<SourcePriceList> SourceFiles { get; set; }
- public void FillTarget()
+ public MergeTool()
+ {
+ string[] files = Dialog.GetMultiplyFiles();
+
+ if (files != null)
+ {
+ SourceFiles = SourcePriceList.GetSourceLists(files);
+ }
+
+ else
+ {
+ throw new Exception("Не выбраны файлы");
+ }
+ }
+
+ public override void FillTarget()
{
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count));
ResultBar = new ResultBar();