Exception message on wrong files

This commit is contained in:
Sergey Chebotar 2022-01-26 19:03:28 +03:00
parent 94e0c84ce1
commit 233c91c71b
3 changed files with 33 additions and 10 deletions

View File

@ -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,10 +56,22 @@ namespace RehauSku.PriceListTools
foreach (string file in files)
{
Workbook wb = ExcelApp.Workbooks.Open(file);
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;
}

View File

@ -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();
}

View File

@ -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();
}