diff options
Diffstat (limited to 'src/PriceListTools/MergeTool.cs')
-rw-r--r-- | src/PriceListTools/MergeTool.cs | 108 |
1 files changed, 42 insertions, 66 deletions
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 2dbe61d..4f5522c 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -1,87 +1,63 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; +using Microsoft.Office.Interop.Excel; using System; -using System.Collections.Generic; namespace RehauSku.PriceListTools { - class MergeTool : ConjoinTool, IDisposable, IConjoinTool + internal class MergeTool : AbstractPriceListTool, IDisposable { - private Dictionary<string, double> SkuAmount { get; set; } - - public MergeTool() + public override void FillPriceList() { - ExcelApp = (Application)ExcelDnaUtil.Application; - SkuAmount = new Dictionary<string, double>(); - } + PriceListSheet offer = NewPriceList.OfferSheet; + offer.Sheet.Activate(); - public void CollectSkuAmount(string[] files) - { - ExcelApp.ScreenUpdating = false; - foreach (string file in files) - { - Workbook wb = ExcelApp.Workbooks.Open(file); - - try - { - PriceList priceList = new PriceList(wb); - SkuAmount.AddValuesFromPriceList(priceList); - } + int exportedValues = 0; - 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 + foreach (var priceList in sourcePriceLists) + { + foreach (var sheet in priceList.Sheets) { - wb.Close(); + if (sheet.SkuAmount.Count == 0) + continue; + + foreach (var kvp in sheet.SkuAmount) + { + Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); + + if (cell == null) + { + System.Windows.Forms.MessageBox.Show + ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}", + "Отсутствует позиция в конечной таблице заказов", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); + } + + else + { + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber]; + + if (sumCell.Value2 == null) + sumCell.Value2 = kvp.Value; + else + sumCell.Value2 += kvp.Value; + + exportedValues++; + } + } } } - ExcelApp.ScreenUpdating = true; - } - - public void ExportToFile(string exportFile) - { - if (SkuAmount.Count < 1) - { - return; - } - Workbook wb = ExcelApp.Workbooks.Open(exportFile); - PriceList priceList; + AutoFilter filter = offer.Sheet.AutoFilter; + int firstFilterColumn = filter.Range.Column; - try - { - priceList = new PriceList(wb); - priceList.FillWithValues(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(); - } + filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>"); + offer.Sheet.Range["A1"].Activate(); + offer.Sheet.Application.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; } public void Dispose() { - Dispose(true); GC.SuppressFinalize(this); } - - protected virtual void Dispose(bool disposing) - { - - } } } |