From 233c91c71b5c68ed7c51f26731b491dac8423771 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 19:03:28 +0300 Subject: [PATCH] Exception message on wrong files --- src/PriceListTools/AbstractPriceListTool.cs | 24 +++++++++++++++++---- src/PriceListTools/ExportTool.cs | 15 +++++++------ src/PriceListTools/MergeTool.cs | 4 ++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/PriceListTools/AbstractPriceListTool.cs b/src/PriceListTools/AbstractPriceListTool.cs index b1fd70b..c174f30 100644 --- a/src/PriceListTools/AbstractPriceListTool.cs +++ b/src/PriceListTools/AbstractPriceListTool.cs @@ -36,8 +36,12 @@ namespace RehauSku.PriceListTools catch (Exception ex) { + System.Windows.Forms.MessageBox.Show + (ex.Message, + "Ошибка открытия шаблонного прайс-листа", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); wb.Close(); - throw ex; } } @@ -52,9 +56,21 @@ namespace RehauSku.PriceListTools foreach (string file in files) { Workbook wb = ExcelApp.Workbooks.Open(file); - PriceList priceList = new PriceList(wb); - sourcePriceLists.Add(priceList); - wb.Close(); + try + { + PriceList priceList = new PriceList(wb); + sourcePriceLists.Add(priceList); + wb.Close(); + } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show + (ex.Message, + "Ошибка открытия исходного прайс-листа", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); + wb.Close(); + } } ExcelApp.ScreenUpdating = true; } diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 5ff52d2..2dc673b 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -75,16 +75,16 @@ namespace RehauSku.PriceListTools public override void FillPriceList() { - if (SkuAmount.Count < 1) return; - - PriceList offer = NewPriceList; - offer.Sheet.Activate(); + if (SkuAmount.Count < 1) + return; int exportedValues = 0; + ExcelApp.ScreenUpdating = false; + foreach (var kvp in SkuAmount) { - Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); + Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key); if (cell == null) { @@ -97,7 +97,7 @@ namespace RehauSku.PriceListTools else { - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column]; + Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -107,7 +107,10 @@ namespace RehauSku.PriceListTools exportedValues++; } } + FilterByAmount(); + ExcelApp.ScreenUpdating = true; + AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}"; Forms.Dialog.SaveWorkbookAs(); } diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 6440d4b..0e98b95 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -9,6 +9,8 @@ namespace RehauSku.PriceListTools { int exportedValues = 0; + ExcelApp.ScreenUpdating = false; + foreach (var sheet in sourcePriceLists) { if (sheet.SkuAmount.Count == 0) @@ -42,6 +44,8 @@ namespace RehauSku.PriceListTools } FilterByAmount(); + ExcelApp.ScreenUpdating = true; + AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; Forms.Dialog.SaveWorkbookAs(); }