aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-01-28 18:15:13 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-01-28 18:15:13 +0300
commit60006126b97131e383a8fee137cf89a13672f042 (patch)
treedb17aa2ff99cc986254919f8f9fa9ec3deb60c4b /src/PriceListTools
parent5b4888be12b223294309d92c30c154a28006737e (diff)
Add not found positions to target file
Diffstat (limited to 'src/PriceListTools')
-rw-r--r--src/PriceListTools/CombineTool.cs2
-rw-r--r--src/PriceListTools/ConvertTool.cs2
-rw-r--r--src/PriceListTools/MergeTool.cs2
-rw-r--r--src/PriceListTools/PriceListTool.cs126
-rw-r--r--src/PriceListTools/Target.cs3
5 files changed, 114 insertions, 21 deletions
diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs
index a654a92..dc0f2af 100644
--- a/src/PriceListTools/CombineTool.cs
+++ b/src/PriceListTools/CombineTool.cs
@@ -21,7 +21,7 @@ namespace RehauSku.PriceListTools
newColumnHeader.Value2 = $"{source.Name}";
newColumnHeader.WrapText = true;
- FillColumn(source.PositionAmount, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
+ FillColumnsWithDictionary(source.PositionAmount, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
}
FilterByAmount();
diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs
index 651e9c7..48e93d2 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.PositionAmount, TargetFile.amountCell.Column);
+ FillColumnsWithDictionary(Current.PositionAmount, TargetFile.amountCell.Column);
FilterByAmount();
ExcelApp.ScreenUpdating = true;
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs
index 8d3e9ed..0d3e8eb 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.PositionAmount, TargetFile.amountCell.Column);
+ FillColumnsWithDictionary(source.PositionAmount, TargetFile.amountCell.Column);
}
FilterByAmount();
diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs
index bf658f8..9d898e7 100644
--- a/src/PriceListTools/PriceListTool.cs
+++ b/src/PriceListTools/PriceListTool.cs
@@ -2,6 +2,8 @@
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
+using System.Windows.Forms;
+using Application = Microsoft.Office.Interop.Excel.Application;
namespace RehauSku.PriceListTools
{
@@ -22,48 +24,70 @@ namespace RehauSku.PriceListTools
catch (Exception ex)
{
- System.Windows.Forms.MessageBox.Show
+ MessageBox.Show
(ex.Message,
"Ошибка открытия шаблонного прайс-листа",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Information);
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
wb.Close();
throw ex;
}
}
- protected private void FillColumn(IEnumerable<KeyValuePair<Position, double>> dictionary, params int[] columns)
+ protected private void FillColumnsWithDictionary(IEnumerable<KeyValuePair<Position, double>> dictionary, params int[] columns)
{
Missing = new List<KeyValuePair<Position, double>>();
- foreach (var kvp in dictionary)
+ foreach (var positionAmount in dictionary)
{
- FillPosition(kvp, columns);
+ FillPositionAmountToColumns(positionAmount, columns);
}
if (Missing.Count > 0)
- {
- System.Windows.Forms.MessageBox.Show
+ {
+ DialogResult result =
+ MessageBox.Show
($"{Missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath} Попробовать найти новый вариант?",
"Отсутствует позиция в конечной таблице заказов",
- System.Windows.Forms.MessageBoxButtons.YesNo,
- System.Windows.Forms.MessageBoxIcon.Information);
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Information);
+
+ if (result == DialogResult.Yes)
+ {
+ var lookUp = new List<KeyValuePair<Position, double>>(Missing);
+
+ foreach (var missingPosition in lookUp)
+ {
+ TryFillVariantlessSkuToColumns(missingPosition, columns);
+ }
+ }
+ }
+
+ if (Missing.Count > 0)
+ {
+ FillMissing();
+ MessageBox.Show
+ ($"{Missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath}\n" +
+ $"Под основной таблицей составлен список не найденных артикулов",
+ "Отсутствует позиция в конечной таблице заказов",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
}
}
- protected private void FillPosition(KeyValuePair<Position, double> kvp, int[] columns)
+ protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, int[] columns)
{
- Range foundCell = TargetFile.skuCell.EntireColumn.Find(kvp.Key.Sku);
+ Range foundCell = TargetFile.skuCell.EntireColumn.Find(positionAmount.Key.Sku);
if (foundCell == null)
{
- Missing.Add(kvp);
+ Missing.Add(positionAmount);
return;
}
string foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
- while (foundCell != null && foundCellGroup != kvp.Key.Group)
+ while (foundCell != null && foundCellGroup != positionAmount.Key.Group)
{
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
@@ -71,7 +95,7 @@ namespace RehauSku.PriceListTools
if (foundCell == null)
{
- Missing.Add(kvp);
+ Missing.Add(positionAmount);
}
else
@@ -79,19 +103,87 @@ namespace RehauSku.PriceListTools
foreach (var column in columns)
{
Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column];
+
if (sumCell.Value2 == null)
{
- sumCell.Value2 = kvp.Value;
+ sumCell.Value2 = positionAmount.Value;
}
else
{
- sumCell.Value2 += kvp.Value;
+ sumCell.Value2 += positionAmount.Value;
}
}
}
}
+ protected private void TryFillVariantlessSkuToColumns(KeyValuePair<Position, double> positionAmount, int[] columns)
+ {
+ string sku = positionAmount.Key.Sku.Substring(1, 6);
+
+ Range foundCell = TargetFile.skuCell.EntireColumn.Find(sku);
+
+ if (foundCell == null)
+ {
+ return;
+ }
+
+ string foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
+
+ while (foundCell != null && foundCellGroup != positionAmount.Key.Group)
+ {
+ foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
+ foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
+ }
+
+ if (foundCell == null)
+ {
+ return;
+ }
+
+ foreach (var column in columns)
+ {
+ Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column];
+
+ if (sumCell.Value2 == null)
+ {
+ sumCell.Value2 = positionAmount.Value;
+ }
+
+ else
+ {
+ sumCell.Value2 += positionAmount.Value;
+ }
+ }
+
+ Missing.Remove(positionAmount);
+ }
+
+ protected private void FillMissing()
+ {
+ int startRow =
+ TargetFile.Sheet.AutoFilter.Range.Row +
+ TargetFile.Sheet.AutoFilter.Range.Rows.Count + 5;
+
+ for (int i = 0; i < Missing.Count; i++)
+ {
+ Range group = TargetFile.Sheet.Cells[startRow + i, TargetFile.groupCell.Column];
+ Range sku = TargetFile.Sheet.Cells[startRow + i, TargetFile.skuCell.Column];
+ Range name = TargetFile.Sheet.Cells[startRow + i, TargetFile.nameCell.Column];
+ Range amount = TargetFile.Sheet.Cells[startRow + i, TargetFile.amountCell.Column];
+
+ group.Value2 = Missing[i].Key.Group;
+ sku.Value2 = Missing[i].Key.Sku;
+ name.Value2 = Missing[i].Key.Name;
+ amount.Value2 = Missing[i].Value;
+
+ group.ClearFormats();
+ sku.ClearFormats();
+ name.ClearFormats();
+ amount.ClearFormats();
+ }
+ }
+
protected private void FilterByAmount()
{
AutoFilter filter = TargetFile.Sheet.AutoFilter;
diff --git a/src/PriceListTools/Target.cs b/src/PriceListTools/Target.cs
index 7abe9e2..a7e87ec 100644
--- a/src/PriceListTools/Target.cs
+++ b/src/PriceListTools/Target.cs
@@ -13,8 +13,9 @@ 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 } не является прайс-листом");
}