From 20cfbfcca3a779c04aecdca5e4b465651e2be42a Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 24 Dec 2021 17:42:20 +0300 Subject: New release --- Source/AddIn/RegistryUtil.cs | 6 ++++++ Source/Forms/Dialog.cs | 4 ++-- Source/PriceListTools/ExportTool.cs | 22 +++++++++++++++++-- Source/PriceListTools/MergeTool.cs | 43 ++++++++++++++++++++++++++++++++----- Source/Ribbon/RibbonController.cs | 14 ++++++------ 5 files changed, 72 insertions(+), 17 deletions(-) (limited to 'Source') diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 3e7c120..40d0ec2 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -47,6 +47,12 @@ namespace RehauSku return _priceListPath; } } + + set + { + _priceListPath = value; + _RootKey.SetValue("PriceListPath", value); + } } public static ResponseOrder StoreResponseOrder diff --git a/Source/Forms/Dialog.cs b/Source/Forms/Dialog.cs index 1953816..170cc81 100644 --- a/Source/Forms/Dialog.cs +++ b/Source/Forms/Dialog.cs @@ -11,7 +11,7 @@ namespace RehauSku.Forms using (OpenFileDialog dialog = new OpenFileDialog()) { - dialog.Filter = "Все файлы (*.*)|*.*"; + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; if (dialog.ShowDialog() == DialogResult.OK) { @@ -28,7 +28,7 @@ namespace RehauSku.Forms using (OpenFileDialog dialog = new OpenFileDialog()) { - dialog.Filter = "Все файлы (*.*)|*.*"; + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; dialog.Multiselect = true; if (dialog.ShowDialog() == DialogResult.OK) diff --git a/Source/PriceListTools/ExportTool.cs b/Source/PriceListTools/ExportTool.cs index 02def5b..0a28bf3 100644 --- a/Source/PriceListTools/ExportTool.cs +++ b/Source/PriceListTools/ExportTool.cs @@ -74,12 +74,30 @@ namespace RehauSku.PriceListTools public void ExportToNewFile() { + if (SkuAmount.Count < 1) + { + return; + } + string exportFile = PriceListUtil.CreateNewExportFile(); Workbook wb = ExcelApp.Workbooks.Open(exportFile); - PriceList priceList = new PriceList(wb); - if (priceList.IsValid()) + try + { + PriceList priceList = new PriceList(wb); priceList.Fill(SkuAmount); + } + + catch(Exception ex) + { + System.Windows.Forms.MessageBox.Show + ($"{RegistryUtil.PriceListPath} не является файлом прайслиста \n\n {ex.Message}", + "Неверный файл прайс-листа!", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Error); + + wb.Close(); + } } public void Dispose() diff --git a/Source/PriceListTools/MergeTool.cs b/Source/PriceListTools/MergeTool.cs index 21da41d..6b0644d 100644 --- a/Source/PriceListTools/MergeTool.cs +++ b/Source/PriceListTools/MergeTool.cs @@ -22,23 +22,56 @@ namespace RehauSku.PriceListTools foreach (string file in files) { Workbook wb = ExcelApp.Workbooks.Open(file); - PriceList priceList = new PriceList(wb); - if (priceList.IsValid()) + try + { + PriceList priceList = new PriceList(wb); SkuAmount.AddValues(priceList); + } - wb.Close(); + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show + ( $"{wb.Name} не является файлом прайслиста \n\n {ex.Message}", + "Неверный файл прайс-листа!", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Error); + } + + finally + { + wb.Close(); + } } ExcelApp.ScreenUpdating = true; } public void ExportToNewFile(string exportFile) { + if (SkuAmount.Count < 1) + { + return; + } + Workbook wb = ExcelApp.Workbooks.Open(exportFile); - PriceList priceList = new PriceList(wb); + PriceList priceList; - if (priceList.IsValid()) + try + { + priceList = new PriceList(wb); priceList.Fill(SkuAmount); + } + + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show + ($"{RegistryUtil.PriceListPath} не является файлом прайслиста \n\n {ex.Message}", + "Неверный файл прайс-листа!", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Error); + + wb.Close(); + } } public void Dispose() diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs index 0090761..df6f327 100644 --- a/Source/Ribbon/RibbonController.cs +++ b/Source/Ribbon/RibbonController.cs @@ -17,11 +17,11 @@ namespace RehauSku.Ribbon -