diff options
author | Serghei Cebotari <51533848+schebotar@users.noreply.github.com> | 2022-01-09 15:48:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-09 15:48:16 +0300 |
commit | bca7f64880bdbcade4a613c8223f82353a326b44 (patch) | |
tree | d14ea8875b8b348c1f3e03256ec304ea992d635f /src/PriceListTools/MergeTool.cs | |
parent | 72908aaaf7da74fe1b3de4d939faaf829d4a80e2 (diff) | |
parent | 846547d6d905e0dbee73cd9c62760ea43bb88134 (diff) |
Merge pull request #11 from schebotar/dev
Dev
Diffstat (limited to 'src/PriceListTools/MergeTool.cs')
-rw-r--r-- | src/PriceListTools/MergeTool.cs | 103 |
1 files changed, 40 insertions, 63 deletions
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index ddf74d2..493f8a8 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -1,88 +1,65 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; +using Microsoft.Office.Interop.Excel; using System; -using System.Collections.Generic; namespace RehauSku.PriceListTools { - class MergeTool : IDisposable + internal class MergeTool : AbstractPriceListTool, IDisposable { - private Application ExcelApp; - private Dictionary<string, double> SkuAmount { get; set; } - - public MergeTool() + public override void FillPriceList() { - this.ExcelApp = (Application)ExcelDnaUtil.Application; - this.SkuAmount = new Dictionary<string, double>(); - } + PriceListSheet offer = NewPriceList.OfferSheet; + offer.Sheet.Activate(); - public void AddSkuAmountToDict(string[] files) - { - ExcelApp.ScreenUpdating = false; - foreach (string file in files) - { - Workbook wb = ExcelApp.Workbooks.Open(file); + int exportedValues = 0; - try + foreach (var priceList in sourcePriceLists) + { + foreach (var sheet in priceList.Sheets) { - PriceList priceList = new PriceList(wb); - SkuAmount.AddValues(priceList); - } + if (sheet.SkuAmount.Count == 0) + continue; - catch (Exception ex) - { - System.Windows.Forms.MessageBox.Show - ( $"{wb.Name} не является файлом прайс-листа \n\n {ex.Message}", - "Неверный файл прайс-листа!", - System.Windows.Forms.MessageBoxButtons.OK, - System.Windows.Forms.MessageBoxIcon.Error); - } + foreach (var kvp in sheet.SkuAmount) + { + Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); - finally - { - wb.Close(); - } - } - ExcelApp.ScreenUpdating = true; - } + if (cell == null) + { + System.Windows.Forms.MessageBox.Show + ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}", + "Отсутствует позиция в конечной таблице заказов", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); + } - public void ExportToNewFile(string exportFile) - { - if (SkuAmount.Count < 1) - { - return; - } + else + { + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber]; - Workbook wb = ExcelApp.Workbooks.Open(exportFile); - PriceList priceList; + if (sumCell.Value2 == null) + sumCell.Value2 = kvp.Value; + else + sumCell.Value2 += kvp.Value; - try - { - priceList = new PriceList(wb); - priceList.Fill(SkuAmount); + exportedValues++; + } + } + } } - catch (Exception ex) - { - System.Windows.Forms.MessageBox.Show - ($"{RegistryUtil.PriceListPath} не является файлом прайс-листа \n\n {ex.Message}", - "Неверный файл прайс-листа!", - System.Windows.Forms.MessageBoxButtons.OK, - System.Windows.Forms.MessageBoxIcon.Error); + AutoFilter filter = offer.Sheet.AutoFilter; + int firstFilterColumn = filter.Range.Column; - wb.Close(); - } + filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>"); + offer.Sheet.Range["A1"].Activate(); + AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; + + Forms.Dialog.SaveWorkbookAs(); } public void Dispose() { - Dispose(true); GC.SuppressFinalize(this); } - - protected virtual void Dispose(bool disposing) - { - - } } } |