Add FillColumn method

This commit is contained in:
Sergey Chebotar 2022-01-27 20:43:19 +03:00
parent 935d48fc5f
commit 7bb0a82ffb
4 changed files with 39 additions and 47 deletions

View File

@ -11,42 +11,23 @@ namespace RehauSku.PriceListTools
public void FillTarget() public void FillTarget()
{ {
ExcelApp.ScreenUpdating = false; ExcelApp.ScreenUpdating = false;
FillAmountColumn(SourceFiles.Select(x => x.SkuAmount).ToArray());
AddAndFillSourceColumns();
FilterByAmount();
ExcelApp.ScreenUpdating = true;
Forms.Dialog.SaveWorkbookAs(); foreach (Source source in SourceFiles)
}
private void AddAndFillSourceColumns()
{
foreach (var source in SourceFiles)
{ {
if (source.SkuAmount.Count == 0)
continue;
TargetFile.Sheet.Columns[TargetFile.amountCell.Column] TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
.EntireColumn .EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1].Value2 = $"{source.Name}"; TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1].Value2 = $"{source.Name}";
foreach (var kvp in source.SkuAmount) FillColumn(source.SkuAmount, TargetFile.amountCell.Column - 1);
{ FillColumn(source.SkuAmount, TargetFile.amountCell.Column);
Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key);
if (cell == null)
{
continue;
}
else
{
TargetFile.Sheet.Cells[cell.Row, TargetFile.amountCell.Column - 1].Value2 = kvp.Value;
}
}
} }
FilterByAmount();
ExcelApp.ScreenUpdating = true;
Forms.Dialog.SaveWorkbookAs();
} }
} }
} }

View File

@ -24,7 +24,7 @@ namespace RehauSku.PriceListTools
{ {
ExcelApp.ScreenUpdating = false; ExcelApp.ScreenUpdating = false;
GetSelected(); GetSelected();
FillAmountColumn(new [] {SkuAmount}); FillColumn(SkuAmount, TargetFile.amountCell.Column);
FilterByAmount(); FilterByAmount();
ExcelApp.ScreenUpdating = true; ExcelApp.ScreenUpdating = true;
@ -67,12 +67,18 @@ namespace RehauSku.PriceListTools
} }
if (sku == null || amount == null) if (sku == null || amount == null)
{
continue; continue;
}
if (SkuAmount.ContainsKey(sku)) if (SkuAmount.ContainsKey(sku))
{
SkuAmount[sku] += amount.Value; SkuAmount[sku] += amount.Value;
}
else else
{
SkuAmount.Add(sku, amount.Value); SkuAmount.Add(sku, amount.Value);
}
} }
} }
} }

View File

@ -10,7 +10,12 @@ namespace RehauSku.PriceListTools
public void FillTarget() public void FillTarget()
{ {
ExcelApp.ScreenUpdating = false; ExcelApp.ScreenUpdating = false;
FillAmountColumn(SourceFiles.Select(x => x.SkuAmount).ToArray());
foreach (Source source in SourceFiles)
{
FillColumn(source.SkuAmount, TargetFile.amountCell.Column);
}
FilterByAmount(); FilterByAmount();
ExcelApp.ScreenUpdating = true; ExcelApp.ScreenUpdating = true;

View File

@ -31,37 +31,37 @@ namespace RehauSku.PriceListTools
} }
} }
protected private void FillAmountColumn(Dictionary<string, double>[] dictionaries) protected private void FillColumn(Dictionary<string, double> dictionary, int column)
{ {
foreach (var dictionary in dictionaries) foreach (var kvp in dictionary)
{ {
if (dictionary.Count == 0) Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key);
continue;
foreach (var kvp in dictionary) if (cell == null)
{ {
Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].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) else
{
Range sumCell = TargetFile.Sheet.Cells[cell.Row, column];
if (sumCell.Value2 == null)
{ {
System.Windows.Forms.MessageBox.Show sumCell.Value2 = kvp.Value;
($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
"Отсутствует позиция в конечной таблице заказов",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
} }
else else
{ {
Range sumCell = TargetFile.Sheet.Cells[cell.Row, TargetFile.amountCell.Column]; sumCell.Value2 += kvp.Value;
if (sumCell.Value2 == null)
sumCell.Value2 = kvp.Value;
else
sumCell.Value2 += kvp.Value;
} }
} }
} }
} }
protected private void FilterByAmount() protected private void FilterByAmount()