diff options
author | Serghei Cebotari <51533848+schebotar@users.noreply.github.com> | 2021-12-26 19:37:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-26 19:37:46 +0300 |
commit | fc870d19555cc77b0e08912b4dab21d496b2321f (patch) | |
tree | ac8b9aa1e883a85339a594b2797ab319cca73c4e /src/PriceListTools/MergeTool.cs | |
parent | 0525ec1b42d5857b740dd0dae7f6d9baeb7088d1 (diff) | |
parent | 54fc3320e7d64d7903b4d091fe0d5c15df01fd78 (diff) |
Merge pull request #9 from schebotar/dev
Move to /src
Diffstat (limited to 'src/PriceListTools/MergeTool.cs')
-rw-r--r-- | src/PriceListTools/MergeTool.cs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs new file mode 100644 index 0000000..ddf74d2 --- /dev/null +++ b/src/PriceListTools/MergeTool.cs @@ -0,0 +1,88 @@ +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<string, double> SkuAmount { get; set; } + + public MergeTool() + { + this.ExcelApp = (Application)ExcelDnaUtil.Application; + this.SkuAmount = new Dictionary<string, double>(); + } + + public void AddSkuAmountToDict(string[] files) + { + ExcelApp.ScreenUpdating = false; + foreach (string file in files) + { + Workbook wb = ExcelApp.Workbooks.Open(file); + + try + { + PriceList priceList = new PriceList(wb); + SkuAmount.AddValues(priceList); + } + + 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; + + 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() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + + } + } +} |