From 28ba91e2d6cedc220e8c853362ebe9507adfbb6d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 17:55:36 +0300 Subject: [PATCH] StatusBar update using directive --- src/Interface/AbstractBar.cs | 8 ++++++- src/Interface/ProgressBar.cs | 5 ---- src/Interface/ResultBar.cs | 1 - src/PriceListTools/CombineTool.cs | 39 ++++++++++++++++--------------- src/PriceListTools/ConvertTool.cs | 19 ++++++++------- src/PriceListTools/ExportTool.cs | 21 +++++++++-------- src/PriceListTools/MergeTool.cs | 21 +++++++++-------- 7 files changed, 59 insertions(+), 55 deletions(-) diff --git a/src/Interface/AbstractBar.cs b/src/Interface/AbstractBar.cs index 84ece24..dda7ea1 100644 --- a/src/Interface/AbstractBar.cs +++ b/src/Interface/AbstractBar.cs @@ -1,9 +1,10 @@ using ExcelDna.Integration; using Microsoft.Office.Interop.Excel; +using System; namespace RehauSku.Interface { - internal abstract class AbstractBar + internal abstract class AbstractBar : IDisposable { protected Application Excel = AddIn.Excel; @@ -14,5 +15,10 @@ namespace RehauSku.Interface { AddIn.Excel.StatusBar = false; } + + public void Dispose() + { + AddIn.Excel.OnTime(DateTime.Now + new TimeSpan(0, 0, 5), "ResetStatusBar"); + } } } diff --git a/src/Interface/ProgressBar.cs b/src/Interface/ProgressBar.cs index 416c7d6..37f8559 100644 --- a/src/Interface/ProgressBar.cs +++ b/src/Interface/ProgressBar.cs @@ -21,11 +21,6 @@ { Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; } - - else - { - Excel.StatusBar = false; - } } } } diff --git a/src/Interface/ResultBar.cs b/src/Interface/ResultBar.cs index 55bc235..f59eb0a 100644 --- a/src/Interface/ResultBar.cs +++ b/src/Interface/ResultBar.cs @@ -40,7 +40,6 @@ namespace RehauSku.Interface } Excel.StatusBar = sb.ToString(); - AddIn.Excel.OnTime(DateTime.Now + new TimeSpan(0, 0, 5), "ResetStatusBar"); } } } diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 5a4d128..cd3fc8a 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -28,28 +28,29 @@ namespace RehauSku.PriceListTools public override void FillTarget() { - ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count)); - ResultBar = new ResultBar(); - - foreach (SourcePriceList source in SourceFiles) + using (ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count))) + using (ResultBar = new ResultBar()) { - TargetFile.Sheet.Columns[TargetFile.AmountCell.Column] - .EntireColumn - .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); - - Range newColumnHeader = TargetFile.Sheet.Cells[TargetFile.AmountCell.Row, TargetFile.AmountCell.Column - 1]; - newColumnHeader.Value2 = $"{source.Name}"; - newColumnHeader.WrapText = true; - - foreach (var kvp in source.PositionAmount) + foreach (SourcePriceList source in SourceFiles) { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column - 1, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } - } + TargetFile.Sheet.Columns[TargetFile.AmountCell.Column] + .EntireColumn + .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); - FilterByAmount(); - ResultBar.Update(); + Range newColumnHeader = TargetFile.Sheet.Cells[TargetFile.AmountCell.Row, TargetFile.AmountCell.Column - 1]; + newColumnHeader.Value2 = $"{source.Name}"; + newColumnHeader.WrapText = true; + + foreach (var kvp in source.PositionAmount) + { + FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column - 1, TargetFile.AmountCell.Column); + ProgressBar.Update(); + } + } + + FilterByAmount(); + ResultBar.Update(); + } } } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index 3a7da20..04cf1ec 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -13,17 +13,18 @@ namespace RehauSku.PriceListTools public override void FillTarget() { - ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count); - ResultBar = new ResultBar(); - - foreach (var kvp in Current.PositionAmount) + using (ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count)) + using (ResultBar = new ResultBar()) { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } + foreach (var kvp in Current.PositionAmount) + { + FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); + ProgressBar.Update(); + } - FilterByAmount(); - ResultBar.Update(); + FilterByAmount(); + ResultBar.Update(); + } } } } \ No newline at end of file diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index a5457c0..1a24d48 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -23,22 +23,23 @@ namespace RehauSku.PriceListTools public override void FillTarget() { - ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count); - ResultBar = new ResultBar(); - - foreach (var kvp in PositionAmount) + using (ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count)) + using (ResultBar = new ResultBar()) { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } + foreach (var kvp in PositionAmount) + { + FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); + ProgressBar.Update(); + } - FilterByAmount(); - ResultBar.Update(); + FilterByAmount(); + ResultBar.Update(); + } } private void GetSelected() { - object[,] cells = Selection.Value2; + object[,] cells = Selection.Value2; PositionAmount = new Dictionary(); int rowsCount = Selection.Rows.Count; diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index f55601f..ac2a455 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -26,20 +26,21 @@ namespace RehauSku.PriceListTools public override void FillTarget() { - ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count)); - ResultBar = new ResultBar(); - - foreach (SourcePriceList source in SourceFiles) + using (ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count))) + using (ResultBar = new ResultBar()) { - foreach (var kvp in source.PositionAmount) + foreach (SourcePriceList source in SourceFiles) { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); - ProgressBar.Update(); + foreach (var kvp in source.PositionAmount) + { + FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); + ProgressBar.Update(); + } } - } - FilterByAmount(); - ResultBar.Update(); + FilterByAmount(); + ResultBar.Update(); + } } } }