Add Excel statusbar progress message

This commit is contained in:
Sergey Chebotar 2022-02-02 10:23:50 +03:00
parent 06799119fb
commit 120eee0231
7 changed files with 60 additions and 2 deletions

View File

@ -0,0 +1,32 @@
using Microsoft.Office.Interop.Excel;
namespace RehauSku.Interface
{
internal class ProgressBar
{
private Application Excel = AddIn.Excel;
private double CurrentProgress { get; set; }
private readonly double TaskWeight;
public ProgressBar(int weight)
{
TaskWeight = weight;
CurrentProgress = 0;
}
public void DoProgress()
{
double percent = (++CurrentProgress / TaskWeight) * 100;
if (percent < 100)
{
Excel.StatusBar = $"Выполнено {percent.ToString("#.##")} %";
}
else
{
Excel.StatusBar = false;
}
}
}
}

View File

@ -1,5 +1,7 @@
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
using RehauSku.Interface;
using System.Linq;
namespace RehauSku.PriceListTools
{
@ -9,6 +11,8 @@ namespace RehauSku.PriceListTools
public void FillTarget()
{
ProgressBar bar = new ProgressBar(SourceFiles.Sum(file => file.PositionAmount.Count));
foreach (Source source in SourceFiles)
{
TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
@ -19,8 +23,11 @@ namespace RehauSku.PriceListTools
newColumnHeader.Value2 = $"{source.Name}";
newColumnHeader.WrapText = true;
foreach(var kvp in source.PositionAmount)
foreach (var kvp in source.PositionAmount)
{
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
bar.DoProgress();
}
}
FilterByAmount();

View File

@ -27,8 +27,13 @@ namespace RehauSku.PriceListTools
public void FillTarget()
{
ProgressBar bar = new ProgressBar(Current.PositionAmount.Count);
foreach (var kvp in Current.PositionAmount)
{
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
bar.DoProgress();
}
FilterByAmount();

View File

@ -2,6 +2,7 @@
using RehauSku.Assistant;
using System;
using System.Collections.Generic;
using RehauSku.Interface;
namespace RehauSku.PriceListTools
{
@ -23,10 +24,12 @@ namespace RehauSku.PriceListTools
public void FillTarget()
{
GetSelected();
ProgressBar bar = new ProgressBar(PositionAmount.Count);
foreach (var kvp in PositionAmount)
{
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
bar.DoProgress();
}
FilterByAmount();

View File

@ -1,5 +1,6 @@
using RehauSku.Interface;
using System.Collections.Generic;
using System.Linq;
namespace RehauSku.PriceListTools
{
@ -9,10 +10,15 @@ namespace RehauSku.PriceListTools
public void FillTarget()
{
ProgressBar bar = new ProgressBar(SourceFiles.Sum(x => x.PositionAmount.Count));
foreach (Source source in SourceFiles)
{
foreach (var kvp in source.PositionAmount)
{
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
bar.DoProgress();
}
}
FilterByAmount();

View File

@ -3,6 +3,7 @@ using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using RehauSku.Interface;
namespace RehauSku.PriceListTools
{
@ -39,6 +40,7 @@ namespace RehauSku.PriceListTools
public static List<Source> GetSourceLists(string[] files)
{
var ExcelApp = (Application)ExcelDnaUtil.Application;
ProgressBar bar = new ProgressBar(files.Length);
List<Source> sourceFiles = new List<Source>();
@ -51,6 +53,7 @@ namespace RehauSku.PriceListTools
Source priceList = new Source(wb);
sourceFiles.Add(priceList);
wb.Close();
bar.DoProgress();
}
catch (Exception ex)
{
@ -60,6 +63,7 @@ namespace RehauSku.PriceListTools
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
wb.Close();
bar.DoProgress();
}
ExcelApp.ScreenUpdating = true;
}

View File

@ -121,6 +121,7 @@
<Compile Include="Assistant\ParseUtil.cs" />
<Compile Include="Assistant\RequestModifier.cs" />
<Compile Include="Assistant\SkuExtensions.cs" />
<Compile Include="Interface\ProgressBar.cs" />
<Compile Include="PriceListTools\CombineTool.cs" />
<Compile Include="PriceListTools\ConvertTool.cs" />
<Compile Include="PriceListTools\Position.cs" />