Create Tool Factory. Exception on empty selection in Export Tool.
This commit is contained in:
parent
41317cab71
commit
69865e96e3
@ -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("Неизвестный инструмент");
|
||||
}
|
||||
|
||||
if (files != null)
|
||||
tool.OpenNewPrice();
|
||||
tool.FillTarget();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 void FillTarget()
|
||||
public CombineTool()
|
||||
{
|
||||
string[] files = Dialog.GetMultiplyFiles();
|
||||
|
||||
if (files != null)
|
||||
{
|
||||
SourceFiles = SourcePriceList.GetSourceLists(files);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new Exception("Не выбраны файлы");
|
||||
}
|
||||
}
|
||||
|
||||
public override void FillTarget()
|
||||
{
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count));
|
||||
ResultBar = new ResultBar();
|
||||
|
@ -5,27 +5,14 @@ namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class ConvertTool : AbstractTool
|
||||
{
|
||||
private SourcePriceList Current;
|
||||
private SourcePriceList Current { get; set; }
|
||||
|
||||
public void GetCurrent()
|
||||
{
|
||||
try
|
||||
public ConvertTool()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void FillTarget()
|
||||
public override void FillTarget()
|
||||
{
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count);
|
||||
ResultBar = new ResultBar();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user