Fix Export Tool to use Price List Tool base methods

This commit is contained in:
Sergey Chebotar 2022-01-31 17:54:18 +03:00
parent 913de67a02
commit cfb15d1279
3 changed files with 16 additions and 46 deletions

View File

@ -7,7 +7,7 @@ namespace RehauSku.PriceListTools
{
internal class ExportTool : PriceListTool
{
private Dictionary<string, double> SkuAmount { get; set; }
private Dictionary<Position, double> PositionAmount;
private Range Selection;
public void TryGetSelection()
@ -19,62 +19,23 @@ namespace RehauSku.PriceListTools
throw new Exception("Неверный диапазон");
}
}
public void FillTarget()
{
ExcelApp.ScreenUpdating = false;
GetSelected();
FillColumn(SkuAmount, TargetFile.amountCell.Column);
FillColumnsWithDictionary(PositionAmount, TargetFile.amountCell.Column);
FilterByAmount();
ExcelApp.ScreenUpdating = true;
Forms.Dialog.SaveWorkbookAs();
}
private void FillColumn(IEnumerable<KeyValuePair<string, double>> dictionary, int column)
{
List<KeyValuePair<string, double>> missing = new List<KeyValuePair<string, double>>();
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;
SkuAmount = new Dictionary<string, double>();
Dictionary<string, double> SkuAmount = new Dictionary<string, double>();
PositionAmount = new Dictionary<Position, double>();
int rowsCount = Selection.Rows.Count;
for (int row = 1; row <= rowsCount; row++)
@ -115,11 +76,17 @@ namespace RehauSku.PriceListTools
{
SkuAmount[sku] += amount.Value;
}
else
{
SkuAmount.Add(sku, amount.Value);
}
}
foreach (var kvp in SkuAmount)
{
PositionAmount.Add(new Position(null, kvp.Key, null), kvp.Value);
}
}
}
}

View File

@ -13,5 +13,4 @@
Name = name;
}
}
}
}

View File

@ -89,6 +89,8 @@ namespace RehauSku.PriceListTools
while (foundCell != null && foundCellGroup != positionAmount.Key.Group)
{
if (positionAmount.Key.Group == null) break;
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
}
@ -132,6 +134,8 @@ namespace RehauSku.PriceListTools
while (foundCell != null && foundCellGroup != positionAmount.Key.Group)
{
if (positionAmount.Key.Group == null) break;
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
}