Add Result Statusbar message
This commit is contained in:
parent
ef04747df5
commit
6e889419e2
11
src/Interface/AbstractBar.cs
Normal file
11
src/Interface/AbstractBar.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
|
||||
namespace RehauSku.Interface
|
||||
namespace RehauSku.Interface
|
||||
{
|
||||
internal class ProgressBar
|
||||
internal class ProgressBar : AbstractBar
|
||||
{
|
||||
private Application Excel = AddIn.Excel;
|
||||
private double CurrentProgress { get; set; }
|
||||
private readonly double TaskWeight;
|
||||
private readonly string Message;
|
||||
@ -16,7 +13,7 @@ namespace RehauSku.Interface
|
||||
CurrentProgress = 0;
|
||||
}
|
||||
|
||||
public void DoProgress()
|
||||
public override void Update()
|
||||
{
|
||||
double percent = (++CurrentProgress / TaskWeight) * 100;
|
||||
|
||||
|
44
src/Interface/ResultBar.cs
Normal file
44
src/Interface/ResultBar.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
using ExcelDna.Integration;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RehauSku.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using Application = Microsoft.Office.Interop.Excel.Application;
|
||||
using ProgressBar = RehauSku.Interface.ProgressBar;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
@ -11,6 +13,8 @@ namespace RehauSku.PriceListTools
|
||||
{
|
||||
protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
|
||||
protected private TargetPriceList TargetFile;
|
||||
protected private ResultBar ResultBar { get; set; }
|
||||
protected private ProgressBar ProgressBar { get; set; }
|
||||
|
||||
public void OpenNewPrice()
|
||||
{
|
||||
@ -53,72 +57,96 @@ namespace RehauSku.PriceListTools
|
||||
sumCell.Value2 += positionAmount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
ResultBar.IncrementSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
if (TargetFile.oldSkuCell != null)
|
||||
{
|
||||
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
||||
Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
|
||||
|
||||
row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||
|
||||
if (row != null)
|
||||
if (foundCell != null)
|
||||
{
|
||||
row = foundCell.Row;
|
||||
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range amountCell = TargetFile.Sheet.Cells[row, column];
|
||||
|
||||
if (amountCell.Value2 == null)
|
||||
if (TargetFile.Sheet.Cells[row, column].Value2 == null)
|
||||
{
|
||||
amountCell.Value2 = positionAmount.Value;
|
||||
TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
amountCell.Value2 += positionAmount.Value;
|
||||
TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column];
|
||||
oldSkuCell.Value2 = positionAmount.Key.Sku;
|
||||
ResultBar.IncrementReplaced();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
||||
row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range amountCell = TargetFile.Sheet.Cells[row, column];
|
||||
|
||||
if (amountCell.Value2 == null)
|
||||
{
|
||||
amountCell.Value2 = positionAmount.Value;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
amountCell.Value2 += positionAmount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
FillMissing(positionAmount, columns);
|
||||
}
|
||||
ResultBar.IncrementReplaced();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
FillMissing(positionAmount, columns);
|
||||
ResultBar.IncrementNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
|
||||
{
|
||||
Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
|
||||
int row;
|
||||
int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
|
||||
.End[XlDirection.xlUp]
|
||||
.Row + 1;
|
||||
|
||||
if (foundCell == null)
|
||||
TargetFile.Sheet.Rows[row]
|
||||
.EntireRow
|
||||
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
||||
|
||||
Range previous = TargetFile.Sheet.Rows[row - 1];
|
||||
Range current = TargetFile.Sheet.Rows[row];
|
||||
|
||||
previous.Copy(current);
|
||||
current.ClearContents();
|
||||
|
||||
TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name;
|
||||
|
||||
if (TargetFile.oldSkuCell != null)
|
||||
{
|
||||
row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
|
||||
.End[XlDirection.xlUp]
|
||||
.Row + 1;
|
||||
|
||||
TargetFile.Sheet.Rows[row]
|
||||
.EntireRow
|
||||
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
||||
|
||||
Range previous = TargetFile.Sheet.Rows[row - 1];
|
||||
Range current = TargetFile.Sheet.Rows[row];
|
||||
|
||||
previous.Copy(current);
|
||||
current.ClearContents();
|
||||
|
||||
TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден";
|
||||
TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
row = foundCell.Row;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||
}
|
||||
|
||||
foreach (int column in columns)
|
||||
|
@ -11,7 +11,8 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
ProgressBar bar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count));
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count));
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (SourcePriceList source in SourceFiles)
|
||||
{
|
||||
@ -26,13 +27,15 @@ namespace RehauSku.PriceListTools
|
||||
foreach (var kvp in source.PositionAmount)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
|
||||
bar.DoProgress();
|
||||
ProgressBar.Update();
|
||||
}
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Interface.Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,17 +27,20 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
ProgressBar bar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count);
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count);
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (var kvp in Current.PositionAmount)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
||||
bar.DoProgress();
|
||||
ProgressBar.Update();
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,17 +24,20 @@ namespace RehauSku.PriceListTools
|
||||
public void FillTarget()
|
||||
{
|
||||
GetSelected();
|
||||
ProgressBar bar = new ProgressBar("Заполняю строки...", PositionAmount.Count);
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count);
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (var kvp in PositionAmount)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
||||
bar.DoProgress();
|
||||
ProgressBar.Update();
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Interface.Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
|
||||
private void GetSelected()
|
||||
|
@ -10,20 +10,23 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
ProgressBar bar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count));
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count));
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (SourcePriceList source in SourceFiles)
|
||||
{
|
||||
foreach (var kvp in source.PositionAmount)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
||||
bar.DoProgress();
|
||||
ProgressBar.Update();
|
||||
}
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RehauSku.Interface;
|
||||
using RehauSku.Assistant;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
@ -53,7 +54,7 @@ namespace RehauSku.PriceListTools
|
||||
SourcePriceList priceList = new SourcePriceList(wb);
|
||||
sourceFiles.Add(priceList);
|
||||
wb.Close();
|
||||
bar.DoProgress();
|
||||
bar.Update();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -63,7 +64,7 @@ namespace RehauSku.PriceListTools
|
||||
System.Windows.Forms.MessageBoxButtons.OK,
|
||||
System.Windows.Forms.MessageBoxIcon.Information);
|
||||
wb.Close();
|
||||
bar.DoProgress();
|
||||
bar.Update();
|
||||
}
|
||||
ExcelApp.ScreenUpdating = true;
|
||||
}
|
||||
@ -85,6 +86,12 @@ namespace RehauSku.PriceListTools
|
||||
object name = Sheet.Cells[row, nameCell.Column].Value2;
|
||||
object sku = Sheet.Cells[row, skuCell.Column].Value2;
|
||||
|
||||
if (group == null || name == null || sku == null)
|
||||
continue;
|
||||
|
||||
if (!sku.ToString().IsRehauSku())
|
||||
continue;
|
||||
|
||||
Position p = new Position(group.ToString(), sku.ToString(), name.ToString());
|
||||
|
||||
if (PositionAmount.ContainsKey(p))
|
||||
|
@ -19,10 +19,11 @@ namespace RehauSku.PriceListTools
|
||||
amountCell = Sheet.Cells.Find(amountHeader),
|
||||
skuCell = Sheet.Cells.Find(skuHeader),
|
||||
groupCell = Sheet.Cells.Find(groupHeader),
|
||||
nameCell = Sheet.Cells.Find(nameHeader),
|
||||
oldSkuCell = Sheet.Cells.Find(oldSkuHeader)
|
||||
nameCell = Sheet.Cells.Find(nameHeader)
|
||||
};
|
||||
|
||||
oldSkuCell = Sheet.Cells.Find(oldSkuHeader);
|
||||
|
||||
if (cells.Any(x => x == null))
|
||||
{
|
||||
throw new ArgumentException($"Шаблон { Name } не является прайс-листом");
|
||||
|
@ -115,6 +115,7 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interface\AbstractBar.cs" />
|
||||
<Compile Include="Interface\Dialog.cs" />
|
||||
<Compile Include="AddIn\RegistryUtil.cs" />
|
||||
<Compile Include="AddIn\MemoryCacheUtil.cs" />
|
||||
@ -122,6 +123,7 @@
|
||||
<Compile Include="Assistant\RequestModifier.cs" />
|
||||
<Compile Include="Assistant\SkuExtensions.cs" />
|
||||
<Compile Include="Interface\ProgressBar.cs" />
|
||||
<Compile Include="Interface\ResultBar.cs" />
|
||||
<Compile Include="PriceListTools\CombineTool.cs" />
|
||||
<Compile Include="PriceListTools\ConvertTool.cs" />
|
||||
<Compile Include="PriceListTools\Position.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user