diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index c634309..6550179 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -20,8 +20,8 @@ namespace RehauSku.PriceListTools TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1].Value2 = $"{source.Name}"; - FillColumn(source.SkuAmount, TargetFile.amountCell.Column - 1); - FillColumn(source.SkuAmount, TargetFile.amountCell.Column); + FillColumn(source.PositionAmount, TargetFile.amountCell.Column - 1); + FillColumn(source.PositionAmount, TargetFile.amountCell.Column); } FilterByAmount(); diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index 1af27f5..651e9c7 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -27,7 +27,7 @@ namespace RehauSku.PriceListTools public void FillTarget() { ExcelApp.ScreenUpdating = false; - FillColumn(Current.SkuAmount, TargetFile.amountCell.Column); + FillColumn(Current.PositionAmount, TargetFile.amountCell.Column); FilterByAmount(); ExcelApp.ScreenUpdating = true; diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index fc9e42d..8bf274a 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -31,6 +31,46 @@ namespace RehauSku.PriceListTools Forms.Dialog.SaveWorkbookAs(); } + private void FillColumn(IEnumerable> dictionary, int column) + { + List> missing = new List>(); + + foreach (var kvp in dictionary) + { + Range cell = TargetFile.skuCell.EntireColumn.Find(kvp.Key); + + if (cell == null) + { + missing.Add(kvp); + } + + else + { + Range sumCell = TargetFile.Sheet.Cells[cell.Row, column]; + + if (sumCell.Value2 == null) + { + sumCell.Value2 = kvp.Value; + } + + else + { + sumCell.Value2 += kvp.Value; + } + } + } + + if (missing.Count > 0) + { + System.Windows.Forms.MessageBox.Show + ($"{missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath} Попробовать найти новый вариант?", + "Отсутствует позиция в конечной таблице заказов", + System.Windows.Forms.MessageBoxButtons.YesNo, + System.Windows.Forms.MessageBoxIcon.Information); + } + } + + private void GetSelected() { object[,] cells = Selection.Value2; diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 75804a0..8d3e9ed 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -13,7 +13,7 @@ namespace RehauSku.PriceListTools foreach (Source source in SourceFiles) { - FillColumn(source.SkuAmount, TargetFile.amountCell.Column); + FillColumn(source.PositionAmount, TargetFile.amountCell.Column); } FilterByAmount(); diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index 5ec870e..65ff3df 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -7,10 +7,12 @@ namespace RehauSku.PriceListTools protected const string amountHeader = "Кол-во"; protected const string skuHeader = "Актуальный материал"; protected const string groupHeader = "Программа"; + protected const string nameHeader = "Наименование"; public Range amountCell { get; protected set; } public Range skuCell { get; protected set; } public Range groupCell { get; protected set; } + public Range nameCell { get; protected set; } public Worksheet Sheet { get; protected set; } public string Name { get; protected set; } diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs index 819bcc6..127912b 100644 --- a/src/PriceListTools/PriceListTool.cs +++ b/src/PriceListTools/PriceListTool.cs @@ -31,13 +31,13 @@ namespace RehauSku.PriceListTools } } - protected private void FillColumn(IEnumerable> dictionary, int column) + protected private void FillColumn(IEnumerable> dictionary, int column) { - List> missing = new List>(); + List> missing = new List>(); foreach (var kvp in dictionary) { - Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key); + Range cell = TargetFile.skuCell.EntireColumn.Find(kvp.Key.Sku); if (cell == null) { diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/Source.cs index 92de551..8c71130 100644 --- a/src/PriceListTools/Source.cs +++ b/src/PriceListTools/Source.cs @@ -6,7 +6,7 @@ namespace RehauSku.PriceListTools { internal class Source : PriceList { - public Dictionary SkuAmount { get; private set; } + public Dictionary PositionAmount { get; private set; } public Source(Workbook workbook) { @@ -16,37 +16,63 @@ namespace RehauSku.PriceListTools amountCell = Sheet.Cells.Find(amountHeader); skuCell = Sheet.Cells.Find(skuHeader); groupCell = Sheet.Cells.Find(groupHeader); + nameCell = Sheet.Cells.Find(nameHeader); - if (amountCell == null || skuCell == null || groupCell == null) + if (amountCell == null || skuCell == null || groupCell == null || nameCell == null) { throw new ArgumentException($"Файл {Name} не распознан"); } - CreateAmountDict(); + CreatePositionsDict(); } - private void CreateAmountDict() + private void CreatePositionsDict() { - SkuAmount = new Dictionary(); + PositionAmount = new Dictionary(); - object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; - object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2; + var aColumn = amountCell.EntireColumn; + + object[,] amountColumn = amountCell.EntireColumn.Value2; + object[,] skuColumn = skuCell.EntireColumn.Value2; + object[,] nameColumn = nameCell.EntireColumn.Value2; + object[,] groupColumn = nameCell.EntireColumn.Value2; for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++) { object amount = amountColumn[row, 1]; + object group = groupColumn[row, 1]; + object name = nameColumn[row, 1]; object sku = skuColumn[row, 1]; if (amount != null && (double)amount != 0) { - if (SkuAmount.ContainsKey(sku.ToString())) - SkuAmount[sku.ToString()] += (double)amount; + Position p = new Position(group.ToString(), sku.ToString(), name.ToString()); + if (PositionAmount.ContainsKey(p)) + { + PositionAmount[p] += (double)amount; + } else - SkuAmount.Add(sku.ToString(), (double)amount); + { + PositionAmount.Add(p, (double)amount); + } } } } } + + public class Position + { + public string SkuGroup { get; private set; } + public string Sku { get; private set; } + public string Name { get; private set; } + + public Position(string group, string sku, string name) + { + SkuGroup = group; + Sku = sku; + Name = name; + } + } }