2022-01-09 10:37:25 +03:00
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
2022-01-27 17:34:03 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
|
|
|
|
namespace RehauSku.PriceListTools
|
|
|
|
|
{
|
2022-01-27 10:22:30 +03:00
|
|
|
|
internal class CombineTool : PriceListTool
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
public List<Source> SourceFiles;
|
|
|
|
|
|
|
|
|
|
public void FillTarget()
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
ExcelApp.ScreenUpdating = false;
|
|
|
|
|
FillAmountColumn(SourceFiles.Select(x => x.SkuAmount).ToArray());
|
|
|
|
|
AddAndFillSourceColumns();
|
|
|
|
|
FilterByAmount();
|
|
|
|
|
ExcelApp.ScreenUpdating = true;
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
Forms.Dialog.SaveWorkbookAs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddAndFillSourceColumns()
|
|
|
|
|
{
|
|
|
|
|
foreach (var source in SourceFiles)
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
if (source.SkuAmount.Count == 0)
|
2022-01-26 17:41:46 +03:00
|
|
|
|
continue;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
|
2022-01-26 17:41:46 +03:00
|
|
|
|
.EntireColumn
|
|
|
|
|
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1].Value2 = $"{source.Name}";
|
|
|
|
|
|
|
|
|
|
foreach (var kvp in source.SkuAmount)
|
2022-01-26 17:41:46 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key);
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
if (cell == null)
|
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
continue;
|
2022-01-26 17:41:46 +03:00
|
|
|
|
}
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
TargetFile.Sheet.Cells[cell.Row, TargetFile.amountCell.Column - 1].Value2 = kvp.Value;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
}
|
2022-01-07 19:04:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|