diff --git a/src/PriceListTools/AbstractPriceListTool.cs b/src/PriceListTools/AbstractPriceListTool.cs index 1aef0be..65ddb3f 100644 --- a/src/PriceListTools/AbstractPriceListTool.cs +++ b/src/PriceListTools/AbstractPriceListTool.cs @@ -25,11 +25,11 @@ namespace RehauSku.PriceListTools { NewPriceList = new PriceList(wb); - if (NewPriceList.Sheets.Count == 0) - throw new ArgumentException($"Не найдены листы с артикулами в {wb.Name}"); + //if (NewPriceList.Sheet.Count == 0) + // throw new ArgumentException($"Не найдены листы с артикулами в {wb.Name}"); - if (NewPriceList.OfferSheet == null) - 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 cf02059..59259ac 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -7,7 +7,7 @@ namespace RehauSku.PriceListTools { public override void FillPriceList() { - PriceListSheet offer = NewPriceList.OfferSheet; + PriceListSheet offer = NewPriceList.Sheet; offer.Sheet.Activate(); int exportedValues = 0; @@ -15,45 +15,44 @@ namespace RehauSku.PriceListTools foreach (var priceList in sourcePriceLists) { - foreach (var sheet in priceList.Sheets) + PriceListSheet sheet = priceList.Sheet; + + if (sheet.SkuAmount.Count == 0) + continue; + + offer.Sheet.Columns[offer.amountColumnNumber] + .EntireColumn + .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); + + exportedLists++; + + foreach (var kvp in sheet.SkuAmount) { - if (sheet.SkuAmount.Count == 0) - continue; + Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); - offer.Sheet.Columns[offer.amountColumnNumber] - .EntireColumn - .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); - - exportedLists++; - - foreach (var kvp in sheet.SkuAmount) + if (cell == null) { - 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 - { - offer.Sheet.Cells[cell.Row, offer.amountColumnNumber].Value2 = kvp.Value; - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber + exportedLists]; - - if (sumCell.Value2 == null) - sumCell.Value2 = kvp.Value; - else - sumCell.Value2 += kvp.Value; - - exportedValues++; - } - - offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}"; + System.Windows.Forms.MessageBox.Show + ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}", + "Отсутствует позиция в конечной таблице заказов", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); } + + else + { + offer.Sheet.Cells[cell.Row, offer.amountColumnNumber].Value2 = kvp.Value; + Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber + exportedLists]; + + if (sumCell.Value2 == null) + sumCell.Value2 = kvp.Value; + else + sumCell.Value2 += kvp.Value; + + exportedValues++; + } + + offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}"; } } diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index a93097d..9bf165b 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.OfferSheet; + PriceListSheet offer = NewPriceList.Sheet; offer.Sheet.Activate(); int exportedValues = 0; diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 493f8a8..4f5b727 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -7,42 +7,41 @@ namespace RehauSku.PriceListTools { public override void FillPriceList() { - PriceListSheet offer = NewPriceList.OfferSheet; + PriceListSheet offer = NewPriceList.Sheet; offer.Sheet.Activate(); int exportedValues = 0; foreach (var priceList in sourcePriceLists) { - foreach (var sheet in priceList.Sheets) + PriceListSheet sheet = priceList.Sheet; + + if (sheet.SkuAmount.Count == 0) + continue; + + foreach (var kvp in sheet.SkuAmount) { - if (sheet.SkuAmount.Count == 0) - continue; + Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); - foreach (var kvp in sheet.SkuAmount) + if (cell == null) { - Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key); + System.Windows.Forms.MessageBox.Show + ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}", + "Отсутствует позиция в конечной таблице заказов", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); + } - 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 - { - Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber]; + sumCell.Value2 += kvp.Value; - if (sumCell.Value2 == null) - sumCell.Value2 = kvp.Value; - else - sumCell.Value2 += kvp.Value; - - exportedValues++; - } + exportedValues++; } } } diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index bc11a17..b8bd7b7 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -1,4 +1,5 @@ using Microsoft.Office.Interop.Excel; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,25 +9,34 @@ namespace RehauSku.PriceListTools internal class PriceList { public readonly string Name; - public readonly PriceListSheet OfferSheet; - public List Sheets { get; private set; } + //public readonly PriceListSheet OfferSheet; + public PriceListSheet Sheet { get; private set; } - private const string offerSheetHeader = "КП"; + + //private const string offerSheetHeader = "КП"; public PriceList(Workbook workbook) { Name = workbook.Name; - Sheets = new List(); + Sheet = new PriceListSheet(workbook.ActiveSheet); - foreach (Worksheet worksheet in workbook.Sheets) - { - PriceListSheet priceListSheet = new PriceListSheet(worksheet); + //foreach (Worksheet worksheet in workbook.Sheets) + //{ + // try + // { + // PriceListSheet priceListSheet = new PriceListSheet(worksheet); + // //priceListSheet.FillSkuAmount(); + // Sheets.Add(priceListSheet); + // } + // catch (Exception ex) + // { + // throw ex; + // } + //} - if (priceListSheet.FillSkuAmount()) - Sheets.Add(priceListSheet); - } - OfferSheet = Sheets.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); + + //OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); } public static string CreateNewFile() diff --git a/src/PriceListTools/PriceListPosition.cs b/src/PriceListTools/PriceListPosition.cs new file mode 100644 index 0000000..30be153 --- /dev/null +++ b/src/PriceListTools/PriceListPosition.cs @@ -0,0 +1,23 @@ +using RehauSku.Assistant; +using System; + +namespace RehauSku.PriceListTools +{ + internal class PriceListPosition + { + public readonly string Group; + public readonly string Sku; + + public PriceListPosition(string group, string sku) + { + if (!sku.IsRehauSku()) + throw new ArgumentException("Wrong SKU"); + + else + { + Group = group; + Sku = sku; + } + } + } +} diff --git a/src/PriceListTools/PriceListSheet.cs b/src/PriceListTools/PriceListSheet.cs index 8a34c2f..9ac2af1 100644 --- a/src/PriceListTools/PriceListSheet.cs +++ b/src/PriceListTools/PriceListSheet.cs @@ -1,5 +1,6 @@ using Microsoft.Office.Interop.Excel; using System.Collections.Generic; +using System; namespace RehauSku.PriceListTools { @@ -7,13 +8,22 @@ namespace RehauSku.PriceListTools { 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; } + + Range amountCell { get; set; } + Range skuCell { get; set; } + Range groupCell { get; set; } + 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) { @@ -21,28 +31,28 @@ namespace RehauSku.PriceListTools 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(); } - public bool FillSkuAmount() + private void FillSkuAmount() { - Range amountCell = Sheet.Cells.Find(amountHeader); - Range skuCell = Sheet.Cells.Find(skuHeader); - - if (amountCell == null || skuCell == null) - { - AddIn.Excel.StatusBar = $"Лист {Name} не распознан"; - return false; - } - headerRowNumber = amountCell.Row; skuColumnNumber = skuCell.Column; amountColumnNumber = amountCell.Column; - object[,] amountColumn = Sheet.Columns[amountColumnNumber].Value2; - object[,] skuColumn = Sheet.Columns[skuColumnNumber].Value2; + object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; + object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2; - for (int row = headerRowNumber + 1; row < amountColumn.GetLength(0); row++) + for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++) { object amount = amountColumn[row, 1]; object sku = skuColumn[row, 1]; @@ -56,8 +66,25 @@ namespace RehauSku.PriceListTools SkuAmount.Add(sku.ToString(), (double)amount); } } - return true; } + + //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 2c6792c..d5d7947 100644 --- a/src/RehauSku.Assist.csproj +++ b/src/RehauSku.Assist.csproj @@ -125,6 +125,7 @@ +