diff --git a/src/PriceListTools/AbstractPriceListTool.cs b/src/PriceListTools/AbstractPriceListTool.cs index 65ddb3f..3511a13 100644 --- a/src/PriceListTools/AbstractPriceListTool.cs +++ b/src/PriceListTools/AbstractPriceListTool.cs @@ -24,12 +24,6 @@ namespace RehauSku.PriceListTools try { NewPriceList = new PriceList(wb); - - //if (NewPriceList.Sheet.Count == 0) - // throw new ArgumentException($"Не найдены листы с артикулами в {wb.Name}"); - - //if (NewPriceList.OfferSheet == null) - // throw new ArgumentException($"Нет листа для коммерческого предложения в {wb.Name}"); } catch (Exception ex) diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index d285ab0..a9c02a9 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -7,16 +7,13 @@ namespace RehauSku.PriceListTools { public override void FillPriceList() { - PriceListSheet offer = NewPriceList.Sheet; + PriceList offer = NewPriceList; offer.Sheet.Activate(); int exportedValues = 0; - int exportedLists = 0; - foreach (var priceList in sourcePriceLists) + foreach (var sheet in sourcePriceLists) { - PriceListSheet sheet = priceList.Sheet; - if (sheet.SkuAmount.Count == 0) continue; @@ -24,8 +21,6 @@ namespace RehauSku.PriceListTools .EntireColumn .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); - exportedLists++; - foreach (var kvp in sheet.SkuAmount) { Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); @@ -41,8 +36,8 @@ namespace RehauSku.PriceListTools else { - offer.Sheet.Cells[cell.Row, offer.amountCell.Column].Value2 = kvp.Value; - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column + exportedLists]; + offer.Sheet.Cells[cell.Row, offer.amountCell.Column - 1].Value2 = kvp.Value; + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column]; if (sumCell.Value2 == null) sumCell.Value2 = kvp.Value; @@ -52,14 +47,13 @@ namespace RehauSku.PriceListTools exportedValues++; } - offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column].Value2 = $"{priceList.Name}\n{sheet.Name}"; + offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column - 1].Value2 = $"{sheet.Name}"; } } AutoFilter filter = offer.Sheet.AutoFilter; - int firstFilterColumn = filter.Range.Column; - filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1 + exportedLists, "<>"); + filter.Range.AutoFilter(offer.amountCell.Column, "<>"); offer.Sheet.Range["A1"].Activate(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 76a5c6f..813df03 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -77,7 +77,7 @@ namespace RehauSku.PriceListTools { if (SkuAmount.Count < 1) return; - PriceListSheet offer = NewPriceList.Sheet; + PriceList offer = NewPriceList; offer.Sheet.Activate(); int exportedValues = 0; diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 76df6ee..57f49a0 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -7,15 +7,13 @@ namespace RehauSku.PriceListTools { public override void FillPriceList() { - PriceListSheet offer = NewPriceList.Sheet; + PriceList offer = NewPriceList; offer.Sheet.Activate(); int exportedValues = 0; - foreach (var priceList in sourcePriceLists) + foreach (var sheet in sourcePriceLists) { - PriceListSheet sheet = priceList.Sheet; - if (sheet.SkuAmount.Count == 0) continue; @@ -47,9 +45,8 @@ namespace RehauSku.PriceListTools } AutoFilter filter = offer.Sheet.AutoFilter; - int firstFilterColumn = filter.Range.Column; - filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1, "<>"); + filter.Range.AutoFilter(offer.amountCell.Column, "<>"); offer.Sheet.Range["A1"].Activate(); AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index e2fd142..588a0bc 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -1,21 +1,100 @@ using Microsoft.Office.Interop.Excel; -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; +using System; namespace RehauSku.PriceListTools { internal class PriceList { + private const string amountHeader = "Кол-во"; + private const string skuHeader = "Актуальный материал"; + private const string groupHeader = "Программа"; + + public readonly Worksheet Sheet; public readonly string Name; - public PriceListSheet Sheet { get; private set; } + public Dictionary SkuAmount { get; private set; } + + public readonly Range amountCell; + 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 PriceList(Workbook workbook) { - Name = workbook.Name; - Sheet = new PriceListSheet(workbook.ActiveSheet); + Sheet = workbook.ActiveSheet; + Name = workbook.Name + '\n' + 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(); } + + private void FillSkuAmount() + { + SkuAmount = new Dictionary(); + + object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; + object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2; + + for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++) + { + object amount = amountColumn[row, 1]; + object sku = skuColumn[row, 1]; + + if (amount != null && (double)amount != 0) + { + if (SkuAmount.ContainsKey(sku.ToString())) + SkuAmount[sku.ToString()] += (double)amount; + + else + SkuAmount.Add(sku.ToString(), (double)amount); + } + } + } + + //public void CreateMap() + //{ + // Range amountCell = Sheet.Cells.Find(amountHeader); + // Range skuCell = Sheet.Cells.Find(skuHeader); + // Range groupCell = Sheet.Cells.Find(groupHeader); + + // headerRowNumber = amountCell.Row; + // skuColumnNumber = skuCell.Column; + // amountColumnNumber = amountCell.Column; + // groupColumnNumber = groupCell.Column; + + // for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++) + // { + // string sku = + // } + + //} } + } diff --git a/src/PriceListTools/PriceListSheet.cs b/src/PriceListTools/PriceListSheet.cs deleted file mode 100644 index 13bb37c..0000000 --- a/src/PriceListTools/PriceListSheet.cs +++ /dev/null @@ -1,82 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using System.Collections.Generic; -using System; - -namespace RehauSku.PriceListTools -{ - internal class PriceListSheet - { - private const string amountHeader = "Кол-во"; - private const string skuHeader = "Актуальный материал"; - private const string groupHeader = "Программа"; - - public readonly Worksheet Sheet; - public readonly string Name; - public Dictionary SkuAmount { get; private set; } - - public readonly Range amountCell; - public readonly Range skuCell; - public readonly Range groupCell; - - public Dictionary Map { get; private set; } - - public PriceListSheet(Worksheet sheet) - { - Sheet = sheet; - Name = sheet.Name; - SkuAmount = new Dictionary(); - - 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(); - } - - private void FillSkuAmount() - { - object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; - object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2; - - for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++) - { - object amount = amountColumn[row, 1]; - object sku = skuColumn[row, 1]; - - if (amount != null && (double)amount != 0) - { - if (SkuAmount.ContainsKey(sku.ToString())) - SkuAmount[sku.ToString()] += (double)amount; - - else - SkuAmount.Add(sku.ToString(), (double)amount); - } - } - } - - //public void CreateMap() - //{ - // Range amountCell = Sheet.Cells.Find(amountHeader); - // Range skuCell = Sheet.Cells.Find(skuHeader); - // Range groupCell = Sheet.Cells.Find(groupHeader); - - // headerRowNumber = amountCell.Row; - // skuColumnNumber = skuCell.Column; - // amountColumnNumber = amountCell.Column; - // groupColumnNumber = groupCell.Column; - - // for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++) - // { - // string sku = - // } - - //} - } - -} - diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj index d5d7947..968e8c0 100644 --- a/src/RehauSku.Assist.csproj +++ b/src/RehauSku.Assist.csproj @@ -124,9 +124,8 @@ - - +