diff --git a/src/Interface/AbstractBar.cs b/src/Interface/AbstractBar.cs index c5918a8..dda7ea1 100644 --- a/src/Interface/AbstractBar.cs +++ b/src/Interface/AbstractBar.cs @@ -1,11 +1,24 @@ -using Microsoft.Office.Interop.Excel; +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; public abstract void Update(); + + [ExcelFunction] + public static void ResetStatusBar() + { + 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..f0f2985 100644 --- a/src/Interface/ProgressBar.cs +++ b/src/Interface/ProgressBar.cs @@ -16,16 +16,7 @@ public override void Update() { double percent = (++CurrentProgress / TaskWeight) * 100; - - if (percent < 100) - { - Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; - } - - else - { - Excel.StatusBar = false; - } + Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; } } } diff --git a/src/Interface/ResultBar.cs b/src/Interface/ResultBar.cs index 1b4d7f4..f59eb0a 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 { 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; } } diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 26a2832..cd3fc8a 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,33 +26,31 @@ namespace RehauSku.PriceListTools } } - public override async void FillTarget() + 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); + + 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(); } - - FilterByAmount(); - ResultBar.Update(); - - await Task.Delay(new TimeSpan(0, 0, 5)); - ExcelApp.StatusBar = false; } } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index dde969c..04cf1ec 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,22 +11,20 @@ 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(); - - 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(); - - await Task.Delay(new TimeSpan(0, 0, 5)); - ExcelApp.StatusBar = false; } } } \ No newline at end of file diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 6f910b7..1a24d48 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,22 +21,20 @@ 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) + 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(); - - await Task.Delay(new TimeSpan(0, 0, 5)); - ExcelApp.StatusBar = false; } private void GetSelected() diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 1eb1d54..ac2a455 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,25 +24,23 @@ namespace RehauSku.PriceListTools } } - public override async void FillTarget() + 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(); - - await Task.Delay(new TimeSpan(0, 0, 5)); - ExcelApp.StatusBar = false; } } } 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); } } } diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 1493351..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.2")] -[assembly: AssemblyFileVersion("1.0.4.2")] +[assembly: AssemblyVersion("1.0.4.3")] +[assembly: AssemblyFileVersion("1.0.4.3")]