From 443364e66c5b010197dd4d62a65af716d09fdab9 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 30 Mar 2022 12:24:28 +0300 Subject: [PATCH 01/10] Revert "Refactoring" This reverts commit 68d2b4e2fb8a3e7903d63f6bc461307e746bf163. --- src/PriceListTools/AbstractTool.cs | 42 ++++++++++++------------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs index abf4bae..0ffabd2 100644 --- a/src/PriceListTools/AbstractTool.cs +++ b/src/PriceListTools/AbstractTool.cs @@ -45,17 +45,13 @@ namespace RehauSku.PriceListTools protected void FillPositionAmountToColumns(KeyValuePair positionAmount, params int[] columns) { - Range worksheetCells = TargetFile.Sheet.Cells; - Range skuColumn = TargetFile.SkuCell.EntireColumn; - Range oldSkuColumn = TargetFile.OldSkuCell.EntireColumn; - - int? row = GetPositionRow(skuColumn, positionAmount.Key.Sku, positionAmount.Key.Group); + int? row = GetPositionRow(TargetFile.SkuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group); if (row != null) { foreach (int column in columns) { - Range cell = worksheetCells[row, column]; + Range cell = TargetFile.Sheet.Cells[row, column]; cell.AddValue(positionAmount.Value); } @@ -65,13 +61,13 @@ namespace RehauSku.PriceListTools if (TargetFile.OldSkuCell != null) { - row = GetPositionRow(oldSkuColumn, positionAmount.Key.Sku, positionAmount.Key.Group); + row = GetPositionRow(TargetFile.OldSkuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group); if (row != null) { foreach (int column in columns) { - Range cell = worksheetCells[row, column]; + Range cell = TargetFile.Sheet.Cells[row, column]; cell.AddValue(positionAmount.Value); } @@ -81,13 +77,13 @@ namespace RehauSku.PriceListTools } string sku = positionAmount.Key.Sku.Substring(1, 6); - row = GetPositionRow(skuColumn, sku, positionAmount.Key.Group); + row = GetPositionRow(TargetFile.SkuCell.EntireColumn, sku, positionAmount.Key.Group); if (row != null) { foreach (int column in columns) { - Range cell = worksheetCells[row, column]; + Range cell = TargetFile.Sheet.Cells[row, column]; cell.AddValue(positionAmount.Value); } @@ -101,43 +97,37 @@ namespace RehauSku.PriceListTools protected void FillMissing(KeyValuePair positionAmount, params int[] columns) { - Range worksheetCells = TargetFile.Sheet.Cells; - Range worksheetRows = TargetFile.Sheet.Rows; - int skuColumn = TargetFile.SkuCell.Column; - int groupColumn = TargetFile.GroupCell.Column; - int nameColumn = TargetFile.NameCell.Column; - - int row = worksheetCells[worksheetRows.Count, skuColumn] + int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.SkuCell.Column] .End[XlDirection.xlUp] .Row + 1; - worksheetRows[row] + TargetFile.Sheet.Rows[row] .EntireRow .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); - Range previous = worksheetRows[row - 1]; - Range current = worksheetRows[row]; + Range previous = TargetFile.Sheet.Rows[row - 1]; + Range current = TargetFile.Sheet.Rows[row]; previous.Copy(current); current.ClearContents(); - worksheetCells[row, groupColumn].Value2 = positionAmount.Key.Group; - worksheetCells[row, nameColumn].Value2 = positionAmount.Key.Name; + 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) { - worksheetCells[row, skuColumn].Value2 = "Не найден"; - worksheetCells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.Sku; + TargetFile.Sheet.Cells[row, TargetFile.SkuCell.Column].Value2 = "Не найден"; + TargetFile.Sheet.Cells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.Sku; } else { - worksheetCells[row, skuColumn].Value2 = positionAmount.Key.Sku; + TargetFile.Sheet.Cells[row, TargetFile.SkuCell.Column].Value2 = positionAmount.Key.Sku; } foreach (int column in columns) { - Range cell = worksheetCells[row, column]; + Range cell = TargetFile.Sheet.Cells[row, column]; cell.AddValue(positionAmount.Value); } } From 1e91c34e465dd8a7f4f44307c874883b3569053d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 30 Mar 2022 12:26:18 +0300 Subject: [PATCH 02/10] Revert "Turn off save as file dialog at the end of tool process. Version update." This reverts commit eaf3ebaa9489462e3d663c93df7a9bc34011464c. --- src/Interface/Dialog.cs | 17 +++++++++++++++++ src/PriceListTools/CombineTool.cs | 5 ++--- src/PriceListTools/ConvertTool.cs | 6 ++---- src/PriceListTools/ExportTool.cs | 9 ++++----- src/PriceListTools/MergeTool.cs | 5 ++--- src/Properties/AssemblyInfo.cs | 4 ++-- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs index 95d676f..e6c7955 100644 --- a/src/Interface/Dialog.cs +++ b/src/Interface/Dialog.cs @@ -36,5 +36,22 @@ namespace RehauSku.Interface else return null; } } + + public static void SaveWorkbookAs() + { + Workbook workbook = AddIn.Excel.ActiveWorkbook; + + using (SaveFileDialog dialog = new SaveFileDialog()) + { + dialog.FileName = workbook.Name; + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + string fileName = dialog.FileName; + workbook.SaveAs(fileName); + } + } + } } } diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 26a2832..eddf9e7 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -3,7 +3,6 @@ using RehauSku.Interface; using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Dialog = RehauSku.Interface.Dialog; namespace RehauSku.PriceListTools @@ -27,7 +26,7 @@ namespace RehauSku.PriceListTools } } - public override async void FillTarget() + public override void FillTarget() { ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count)); ResultBar = new ResultBar(); @@ -52,7 +51,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - await Task.Delay(new TimeSpan(0, 0, 5)); + Interface.Dialog.SaveWorkbookAs(); ExcelApp.StatusBar = false; } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index dde969c..1bb02f4 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -1,6 +1,4 @@ using RehauSku.Interface; -using System; -using System.Threading.Tasks; namespace RehauSku.PriceListTools { @@ -13,7 +11,7 @@ namespace RehauSku.PriceListTools Current = new SourcePriceList(ExcelApp.ActiveWorkbook); } - public override async void FillTarget() + public override void FillTarget() { ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count); ResultBar = new ResultBar(); @@ -27,7 +25,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - await Task.Delay(new TimeSpan(0, 0, 5)); + Dialog.SaveWorkbookAs(); ExcelApp.StatusBar = false; } } diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 6f910b7..603de8b 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using RehauSku.Interface; -using System.Threading.Tasks; namespace RehauSku.PriceListTools { @@ -22,11 +21,11 @@ namespace RehauSku.PriceListTools } } - public override async void FillTarget() + public override void FillTarget() { ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count); ResultBar = new ResultBar(); - + foreach (var kvp in PositionAmount) { FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); @@ -36,13 +35,13 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - await Task.Delay(new TimeSpan(0, 0, 5)); + Interface.Dialog.SaveWorkbookAs(); ExcelApp.StatusBar = false; } 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 1eb1d54..179fb81 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace RehauSku.PriceListTools { @@ -25,7 +24,7 @@ namespace RehauSku.PriceListTools } } - public override async void FillTarget() + public override void FillTarget() { ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count)); ResultBar = new ResultBar(); @@ -42,7 +41,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - await Task.Delay(new TimeSpan(0, 0, 5)); + Dialog.SaveWorkbookAs(); ExcelApp.StatusBar = false; } } diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 1493351..5f1731a 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.4.2")] -[assembly: AssemblyFileVersion("1.0.4.2")] +[assembly: AssemblyVersion("1.0.4.1")] +[assembly: AssemblyFileVersion("1.0.4.1")] From 7844ac52b652e30a77385b048db9b1eb4c2c9674 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 30 Mar 2022 12:28:33 +0300 Subject: [PATCH 03/10] Revert "Revert "Refactoring"" This reverts commit 443364e66c5b010197dd4d62a65af716d09fdab9. --- src/PriceListTools/AbstractTool.cs | 42 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs index 0ffabd2..abf4bae 100644 --- a/src/PriceListTools/AbstractTool.cs +++ b/src/PriceListTools/AbstractTool.cs @@ -45,13 +45,17 @@ namespace RehauSku.PriceListTools protected void FillPositionAmountToColumns(KeyValuePair positionAmount, params int[] columns) { - int? row = GetPositionRow(TargetFile.SkuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group); + Range worksheetCells = TargetFile.Sheet.Cells; + Range skuColumn = TargetFile.SkuCell.EntireColumn; + Range oldSkuColumn = TargetFile.OldSkuCell.EntireColumn; + + int? row = GetPositionRow(skuColumn, positionAmount.Key.Sku, positionAmount.Key.Group); if (row != null) { foreach (int column in columns) { - Range cell = TargetFile.Sheet.Cells[row, column]; + Range cell = worksheetCells[row, column]; cell.AddValue(positionAmount.Value); } @@ -61,13 +65,13 @@ namespace RehauSku.PriceListTools if (TargetFile.OldSkuCell != null) { - row = GetPositionRow(TargetFile.OldSkuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group); + row = GetPositionRow(oldSkuColumn, positionAmount.Key.Sku, positionAmount.Key.Group); if (row != null) { foreach (int column in columns) { - Range cell = TargetFile.Sheet.Cells[row, column]; + Range cell = worksheetCells[row, column]; cell.AddValue(positionAmount.Value); } @@ -77,13 +81,13 @@ namespace RehauSku.PriceListTools } string sku = positionAmount.Key.Sku.Substring(1, 6); - row = GetPositionRow(TargetFile.SkuCell.EntireColumn, sku, positionAmount.Key.Group); + row = GetPositionRow(skuColumn, sku, positionAmount.Key.Group); if (row != null) { foreach (int column in columns) { - Range cell = TargetFile.Sheet.Cells[row, column]; + Range cell = worksheetCells[row, column]; cell.AddValue(positionAmount.Value); } @@ -97,37 +101,43 @@ namespace RehauSku.PriceListTools protected void FillMissing(KeyValuePair positionAmount, params int[] columns) { - int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.SkuCell.Column] + Range worksheetCells = TargetFile.Sheet.Cells; + Range worksheetRows = TargetFile.Sheet.Rows; + int skuColumn = TargetFile.SkuCell.Column; + int groupColumn = TargetFile.GroupCell.Column; + int nameColumn = TargetFile.NameCell.Column; + + int row = worksheetCells[worksheetRows.Count, skuColumn] .End[XlDirection.xlUp] .Row + 1; - TargetFile.Sheet.Rows[row] + worksheetRows[row] .EntireRow .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); - Range previous = TargetFile.Sheet.Rows[row - 1]; - Range current = TargetFile.Sheet.Rows[row]; + Range previous = worksheetRows[row - 1]; + Range current = worksheetRows[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; + worksheetCells[row, groupColumn].Value2 = positionAmount.Key.Group; + worksheetCells[row, nameColumn].Value2 = positionAmount.Key.Name; if (TargetFile.OldSkuCell != null) { - TargetFile.Sheet.Cells[row, TargetFile.SkuCell.Column].Value2 = "Не найден"; - TargetFile.Sheet.Cells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.Sku; + worksheetCells[row, skuColumn].Value2 = "Не найден"; + worksheetCells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.Sku; } else { - TargetFile.Sheet.Cells[row, TargetFile.SkuCell.Column].Value2 = positionAmount.Key.Sku; + worksheetCells[row, skuColumn].Value2 = positionAmount.Key.Sku; } foreach (int column in columns) { - Range cell = TargetFile.Sheet.Cells[row, column]; + Range cell = worksheetCells[row, column]; cell.AddValue(positionAmount.Value); } } From 4d01a456e3c5faea7a23e7e39b41e1a1bd8beef0 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 16:35:25 +0300 Subject: [PATCH 04/10] Fix cast failing on non-digital value in amount field --- src/PriceListTools/SourcePriceList.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PriceListTools/SourcePriceList.cs b/src/PriceListTools/SourcePriceList.cs index d03d776..b11e060 100644 --- a/src/PriceListTools/SourcePriceList.cs +++ b/src/PriceListTools/SourcePriceList.cs @@ -77,9 +77,9 @@ namespace RehauSku.PriceListTools for (int row = AmountCell.Row + 1; row <= Sheet.Cells[Sheet.Rows.Count, AmountCell.Column].End[XlDirection.xlUp].Row; row++) { - object amount = Sheet.Cells[row, AmountCell.Column].Value2; + double? amount = Sheet.Cells[row, AmountCell.Column].Value2 as double?; - if (amount != null && (double)amount != 0) + if (amount != null && amount.Value != 0) { object group = Sheet.Cells[row, GroupCell.Column].Value2; object name = Sheet.Cells[row, NameCell.Column].Value2; @@ -95,12 +95,12 @@ namespace RehauSku.PriceListTools if (PositionAmount.ContainsKey(p)) { - PositionAmount[p] += (double)amount; + PositionAmount[p] += amount.Value; } else { - PositionAmount.Add(p, (double)amount); + PositionAmount.Add(p, amount.Value); } } } From 84eab9425c9fbf27ff50a3bc314966babd1e960c Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 17:39:01 +0300 Subject: [PATCH 05/10] Keep ResultBar update 5 seconds long. Turn off save as dialog after tools complete. --- src/Interface/AbstractBar.cs | 11 +++++++++-- src/Interface/ResultBar.cs | 4 +++- src/PriceListTools/CombineTool.cs | 3 --- src/PriceListTools/ConvertTool.cs | 3 --- src/PriceListTools/ExportTool.cs | 3 --- src/PriceListTools/MergeTool.cs | 3 --- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Interface/AbstractBar.cs b/src/Interface/AbstractBar.cs index c5918a8..84ece24 100644 --- a/src/Interface/AbstractBar.cs +++ b/src/Interface/AbstractBar.cs @@ -1,11 +1,18 @@ -using Microsoft.Office.Interop.Excel; +using ExcelDna.Integration; +using Microsoft.Office.Interop.Excel; namespace RehauSku.Interface { - internal abstract class AbstractBar + internal abstract class AbstractBar { protected Application Excel = AddIn.Excel; public abstract void Update(); + + [ExcelFunction] + public static void ResetStatusBar() + { + AddIn.Excel.StatusBar = false; + } } } diff --git a/src/Interface/ResultBar.cs b/src/Interface/ResultBar.cs index 1b4d7f4..55bc235 100644 --- a/src/Interface/ResultBar.cs +++ b/src/Interface/ResultBar.cs @@ -1,4 +1,5 @@ -using System.Text; +using System; +using System.Text; namespace RehauSku.Interface { @@ -39,6 +40,7 @@ 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 eddf9e7..5a4d128 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -50,9 +50,6 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - - Interface.Dialog.SaveWorkbookAs(); - ExcelApp.StatusBar = false; } } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index 1bb02f4..3a7da20 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -24,9 +24,6 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - - Dialog.SaveWorkbookAs(); - ExcelApp.StatusBar = false; } } } \ No newline at end of file diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 603de8b..a5457c0 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -34,9 +34,6 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - - Interface.Dialog.SaveWorkbookAs(); - ExcelApp.StatusBar = false; } private void GetSelected() diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 179fb81..f55601f 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -40,9 +40,6 @@ namespace RehauSku.PriceListTools FilterByAmount(); ResultBar.Update(); - - Dialog.SaveWorkbookAs(); - ExcelApp.StatusBar = false; } } } From 64240ee46c350b49ff06294ab3c908c99527a23d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 17:40:50 +0300 Subject: [PATCH 06/10] Delete SaveAsDialog method depricated --- src/Interface/Dialog.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs index e6c7955..95d676f 100644 --- a/src/Interface/Dialog.cs +++ b/src/Interface/Dialog.cs @@ -36,22 +36,5 @@ namespace RehauSku.Interface else return null; } } - - public static void SaveWorkbookAs() - { - Workbook workbook = AddIn.Excel.ActiveWorkbook; - - using (SaveFileDialog dialog = new SaveFileDialog()) - { - dialog.FileName = workbook.Name; - dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; - - if (dialog.ShowDialog() == DialogResult.OK) - { - string fileName = dialog.FileName; - workbook.SaveAs(fileName); - } - } - } } } From 28ba91e2d6cedc220e8c853362ebe9507adfbb6d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 17:55:36 +0300 Subject: [PATCH 07/10] 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(); + } } } } From 9282bebb41f1ca0270bab7aedabd9f2a80f4e999 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 17:56:53 +0300 Subject: [PATCH 08/10] Reset Excel Statusbar on fault --- src/Interface/RibbonController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs index 7bf9ee1..2d3290c 100644 --- a/src/Interface/RibbonController.cs +++ b/src/Interface/RibbonController.cs @@ -93,6 +93,7 @@ namespace RehauSku.Interface "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); + AddIn.Excel.StatusBar = false; return; } } From 059e38547091b2801dd9ef8be0cd684eb9475e09 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 1 Apr 2022 18:00:16 +0300 Subject: [PATCH 09/10] Version update --- src/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 5f1731a..d254dfc 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.4.1")] -[assembly: AssemblyFileVersion("1.0.4.1")] +[assembly: AssemblyVersion("1.0.4.3")] +[assembly: AssemblyFileVersion("1.0.4.3")] From f0dc286f9020146a95471506385a4d99d7200595 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sun, 3 Apr 2022 12:24:22 +0300 Subject: [PATCH 10/10] 100% message in progress bar status --- src/Interface/ProgressBar.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Interface/ProgressBar.cs b/src/Interface/ProgressBar.cs index 37f8559..f0f2985 100644 --- a/src/Interface/ProgressBar.cs +++ b/src/Interface/ProgressBar.cs @@ -16,11 +16,7 @@ public override void Update() { double percent = (++CurrentProgress / TaskWeight) * 100; - - if (percent < 100) - { - Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; - } + Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; } } }