From c0139ca228bdca91df0a66201f59f8074c6a0db6 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 17:50:07 +0300 Subject: [PATCH] Remove unnecessary fields --- src/PriceListTools/CombineTool.cs | 12 ++++++------ src/PriceListTools/ExportTool.cs | 6 +++--- src/PriceListTools/MergeTool.cs | 6 +++--- src/PriceListTools/PriceList.cs | 22 ---------------------- src/PriceListTools/PriceListSheet.cs | 15 +++------------ 5 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 59259ac..d285ab0 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -20,7 +20,7 @@ namespace RehauSku.PriceListTools if (sheet.SkuAmount.Count == 0) continue; - offer.Sheet.Columns[offer.amountColumnNumber] + offer.Sheet.Columns[offer.amountCell.Column] .EntireColumn .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); @@ -28,7 +28,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in sheet.SkuAmount) { - Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); + Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); if (cell == null) { @@ -41,8 +41,8 @@ namespace RehauSku.PriceListTools else { - offer.Sheet.Cells[cell.Row, offer.amountColumnNumber].Value2 = kvp.Value; - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber + exportedLists]; + offer.Sheet.Cells[cell.Row, offer.amountCell.Column].Value2 = kvp.Value; + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column + exportedLists]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -52,14 +52,14 @@ namespace RehauSku.PriceListTools exportedValues++; } - offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}"; + offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column].Value2 = $"{priceList.Name}\n{sheet.Name}"; } } AutoFilter filter = offer.Sheet.AutoFilter; int firstFilterColumn = filter.Range.Column; - filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1 + exportedLists, "<>"); + filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1 + exportedLists, "<>"); offer.Sheet.Range["A1"].Activate(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 9bf165b..76a5c6f 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -84,7 +84,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in SkuAmount) { - Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); + Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); if (cell == null) { @@ -97,7 +97,7 @@ namespace RehauSku.PriceListTools else { - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber]; + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -111,7 +111,7 @@ namespace RehauSku.PriceListTools AutoFilter filter = offer.Sheet.AutoFilter; int firstFilterColumn = filter.Range.Column; - filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>"); + filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1, "<>"); offer.Sheet.Range["A1"].Activate(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}"; diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 4f5b727..76df6ee 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -21,7 +21,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in sheet.SkuAmount) { - Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); + Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); if (cell == null) { @@ -34,7 +34,7 @@ namespace RehauSku.PriceListTools else { - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber]; + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -49,7 +49,7 @@ namespace RehauSku.PriceListTools AutoFilter filter = offer.Sheet.AutoFilter; int firstFilterColumn = filter.Range.Column; - filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>"); + filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1, "<>"); offer.Sheet.Range["A1"].Activate(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index e6aa826..e2fd142 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -9,34 +9,12 @@ namespace RehauSku.PriceListTools internal class PriceList { public readonly string Name; - //public readonly PriceListSheet OfferSheet; public PriceListSheet Sheet { get; private set; } - - //private const string offerSheetHeader = "КП"; - public PriceList(Workbook workbook) { Name = workbook.Name; Sheet = new PriceListSheet(workbook.ActiveSheet); - - //foreach (Worksheet worksheet in workbook.Sheets) - //{ - // try - // { - // PriceListSheet priceListSheet = new PriceListSheet(worksheet); - // //priceListSheet.FillSkuAmount(); - // Sheets.Add(priceListSheet); - // } - // catch (Exception ex) - // { - // throw ex; - // } - //} - - - - //OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); } } } diff --git a/src/PriceListTools/PriceListSheet.cs b/src/PriceListTools/PriceListSheet.cs index 9ac2af1..13bb37c 100644 --- a/src/PriceListTools/PriceListSheet.cs +++ b/src/PriceListTools/PriceListSheet.cs @@ -14,17 +14,12 @@ namespace RehauSku.PriceListTools public readonly string Name; public Dictionary SkuAmount { get; private set; } - Range amountCell { get; set; } - Range skuCell { get; set; } - Range groupCell { get; set; } + public readonly Range amountCell; + public readonly Range skuCell; + public readonly Range groupCell; - public int headerRowNumber { get; private set; } - public int amountColumnNumber { get; private set; } - public int skuColumnNumber { get; private set; } - public int groupColumnNumber { get; private set; } public Dictionary Map { get; private set; } - public PriceListSheet(Worksheet sheet) { Sheet = sheet; @@ -45,10 +40,6 @@ namespace RehauSku.PriceListTools private void FillSkuAmount() { - headerRowNumber = amountCell.Row; - skuColumnNumber = skuCell.Column; - amountColumnNumber = amountCell.Column; - object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;