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