diff --git a/src/PriceListTools/AbstractPriceListTool.cs b/src/PriceListTools/AbstractPriceListTool.cs index 3511a13..b1fd70b 100644 --- a/src/PriceListTools/AbstractPriceListTool.cs +++ b/src/PriceListTools/AbstractPriceListTool.cs @@ -17,6 +17,14 @@ namespace RehauSku.PriceListTools sourcePriceLists = new List(); } + protected private void FilterByAmount() + { + AutoFilter filter = NewPriceList.Sheet.AutoFilter; + + filter.Range.AutoFilter(NewPriceList.amountCell.Column, "<>"); + NewPriceList.Sheet.Range["A1"].Activate(); + } + public void OpenNewPrice(string path) { Workbook wb = ExcelApp.Workbooks.Open(path); diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index a9c02a9..2e5995c 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -7,9 +7,6 @@ namespace RehauSku.PriceListTools { public override void FillPriceList() { - PriceList offer = NewPriceList; - offer.Sheet.Activate(); - int exportedValues = 0; foreach (var sheet in sourcePriceLists) @@ -17,13 +14,13 @@ namespace RehauSku.PriceListTools if (sheet.SkuAmount.Count == 0) continue; - offer.Sheet.Columns[offer.amountCell.Column] + NewPriceList.Sheet.Columns[NewPriceList.amountCell.Column] .EntireColumn .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); foreach (var kvp in sheet.SkuAmount) { - Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); + Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key); if (cell == null) { @@ -36,8 +33,8 @@ namespace RehauSku.PriceListTools else { - offer.Sheet.Cells[cell.Row, offer.amountCell.Column - 1].Value2 = kvp.Value; - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column]; + NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column - 1].Value2 = kvp.Value; + Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -47,17 +44,12 @@ namespace RehauSku.PriceListTools exportedValues++; } - offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column - 1].Value2 = $"{sheet.Name}"; + NewPriceList.Sheet.Cells[NewPriceList.amountCell.Row, NewPriceList.amountCell.Column - 1].Value2 = $"{sheet.Name}"; } } - AutoFilter filter = offer.Sheet.AutoFilter; - - filter.Range.AutoFilter(offer.amountCell.Column, "<>"); - offer.Sheet.Range["A1"].Activate(); - + FilterByAmount(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; - Forms.Dialog.SaveWorkbookAs(); } diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 813df03..5ff52d2 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -107,14 +107,8 @@ namespace RehauSku.PriceListTools exportedValues++; } } - - AutoFilter filter = offer.Sheet.AutoFilter; - int firstFilterColumn = filter.Range.Column; - - filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1, "<>"); - offer.Sheet.Range["A1"].Activate(); - AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}"; - + FilterByAmount(); + AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}"; Forms.Dialog.SaveWorkbookAs(); } diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 57f49a0..6440d4b 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -7,9 +7,6 @@ namespace RehauSku.PriceListTools { public override void FillPriceList() { - PriceList offer = NewPriceList; - offer.Sheet.Activate(); - int exportedValues = 0; foreach (var sheet in sourcePriceLists) @@ -19,7 +16,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in sheet.SkuAmount) { - Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); + Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key); if (cell == null) { @@ -32,7 +29,7 @@ namespace RehauSku.PriceListTools else { - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column]; + Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -44,12 +41,8 @@ namespace RehauSku.PriceListTools } } - AutoFilter filter = offer.Sheet.AutoFilter; - - filter.Range.AutoFilter(offer.amountCell.Column, "<>"); - offer.Sheet.Range["A1"].Activate(); + FilterByAmount(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; - Forms.Dialog.SaveWorkbookAs(); } diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index 588a0bc..1bf9663 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -18,24 +18,7 @@ namespace RehauSku.PriceListTools public readonly Range skuCell; public readonly Range groupCell; - public Dictionary Map { get; private set; } - - public PriceList(Worksheet sheet) - { - Sheet = sheet; - Name = sheet.Name; - - amountCell = Sheet.Cells.Find(amountHeader); - skuCell = Sheet.Cells.Find(skuHeader); - groupCell = Sheet.Cells.Find(groupHeader); - - if (amountCell == null || skuCell == null || groupCell == null) - { - throw new ArgumentException($"Лист { Name } не распознан"); - } - - FillSkuAmount(); - } + //public Dictionary Map { get; private set; } public PriceList(Workbook workbook) {