From 24024b5729c1c44bb01cb29813868743d1753e31 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 24 Dec 2021 16:22:03 +0300 Subject: MergeTool, MemoryUtil anf stuff --- Source/PriceListTools/MergeTool.cs | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Source/PriceListTools/MergeTool.cs (limited to 'Source/PriceListTools/MergeTool.cs') diff --git a/Source/PriceListTools/MergeTool.cs b/Source/PriceListTools/MergeTool.cs new file mode 100644 index 0000000..21da41d --- /dev/null +++ b/Source/PriceListTools/MergeTool.cs @@ -0,0 +1,55 @@ +using ExcelDna.Integration; +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; + +namespace RehauSku.PriceListTools +{ + class MergeTool : IDisposable + { + private Application ExcelApp; + private Dictionary SkuAmount { get; set; } + + public MergeTool() + { + this.ExcelApp = (Application)ExcelDnaUtil.Application; + this.SkuAmount = new Dictionary(); + } + + public void AddSkuAmountToDict(string[] files) + { + ExcelApp.ScreenUpdating = false; + foreach (string file in files) + { + Workbook wb = ExcelApp.Workbooks.Open(file); + PriceList priceList = new PriceList(wb); + + if (priceList.IsValid()) + SkuAmount.AddValues(priceList); + + wb.Close(); + } + ExcelApp.ScreenUpdating = true; + } + + public void ExportToNewFile(string exportFile) + { + Workbook wb = ExcelApp.Workbooks.Open(exportFile); + PriceList priceList = new PriceList(wb); + + if (priceList.IsValid()) + priceList.Fill(SkuAmount); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + + } + } +} -- cgit v1.2.3 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/PriceListTools/MergeTool.cs | 43 +++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'Source/PriceListTools/MergeTool.cs') 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() -- cgit v1.2.3