aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-02-02 10:23:50 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-02-02 10:23:50 +0300
commit120eee0231d02e90d9d195ebc38327a58d4564a8 (patch)
treeed1819297d8825805dbeb15156a032b172e826b9 /src
parent06799119fb83cb6b75721c5cf60f4051e50976a7 (diff)
Add Excel statusbar progress message
Diffstat (limited to 'src')
-rw-r--r--src/Interface/ProgressBar.cs32
-rw-r--r--src/PriceListTools/CombineTool.cs9
-rw-r--r--src/PriceListTools/ConvertTool.cs5
-rw-r--r--src/PriceListTools/ExportTool.cs5
-rw-r--r--src/PriceListTools/MergeTool.cs6
-rw-r--r--src/PriceListTools/Source.cs4
-rw-r--r--src/RehauSku.Assist.csproj1
7 files changed, 60 insertions, 2 deletions
diff --git a/src/Interface/ProgressBar.cs b/src/Interface/ProgressBar.cs
new file mode 100644
index 0000000..474bed7
--- /dev/null
+++ b/src/Interface/ProgressBar.cs
@@ -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;
+ }
+ }
+ }
+}
diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs
index e637fef..cb47379 100644
--- a/src/PriceListTools/CombineTool.cs
+++ b/src/PriceListTools/CombineTool.cs
@@ -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();
diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs
index d43b30d..d10d65e 100644
--- a/src/PriceListTools/ConvertTool.cs
+++ b/src/PriceListTools/ConvertTool.cs
@@ -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();
diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs
index 119a289..568145d 100644
--- a/src/PriceListTools/ExportTool.cs
+++ b/src/PriceListTools/ExportTool.cs
@@ -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();
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs
index 895740c..a51b9b7 100644
--- a/src/PriceListTools/MergeTool.cs
+++ b/src/PriceListTools/MergeTool.cs
@@ -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();
diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/Source.cs
index 7cf56be..fe5ee9b 100644
--- a/src/PriceListTools/Source.cs
+++ b/src/PriceListTools/Source.cs
@@ -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;
}
diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj
index f1a7725..e2d9794 100644
--- a/src/RehauSku.Assist.csproj
+++ b/src/RehauSku.Assist.csproj
@@ -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" />