2022-01-09 10:37:25 +03:00
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
2022-01-07 19:04:07 +03:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace RehauSku.PriceListTools
|
|
|
|
|
{
|
2022-01-09 10:37:25 +03:00
|
|
|
|
internal class CombineTool : AbstractPriceListTool, IDisposable
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-01-09 10:37:25 +03:00
|
|
|
|
public override void FillPriceList()
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-01-26 17:41:46 +03:00
|
|
|
|
PriceListSheet offer = NewPriceList.Sheet;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
offer.Sheet.Activate();
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
2022-01-09 10:37:25 +03:00
|
|
|
|
int exportedValues = 0;
|
|
|
|
|
int exportedLists = 0;
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
2022-01-09 10:37:25 +03:00
|
|
|
|
foreach (var priceList in sourcePriceLists)
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-01-26 17:41:46 +03:00
|
|
|
|
PriceListSheet sheet = priceList.Sheet;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
if (sheet.SkuAmount.Count == 0)
|
|
|
|
|
continue;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
offer.Sheet.Columns[offer.amountColumnNumber]
|
|
|
|
|
.EntireColumn
|
|
|
|
|
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
exportedLists++;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
foreach (var kvp in sheet.SkuAmount)
|
|
|
|
|
{
|
|
|
|
|
Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key);
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
if (cell == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show
|
|
|
|
|
($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
|
|
|
|
|
"Отсутствует позиция в конечной таблице заказов",
|
|
|
|
|
System.Windows.Forms.MessageBoxButtons.OK,
|
|
|
|
|
System.Windows.Forms.MessageBoxIcon.Information);
|
|
|
|
|
}
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
offer.Sheet.Cells[cell.Row, offer.amountColumnNumber].Value2 = kvp.Value;
|
|
|
|
|
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber + exportedLists];
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
if (sumCell.Value2 == null)
|
|
|
|
|
sumCell.Value2 = kvp.Value;
|
|
|
|
|
else
|
|
|
|
|
sumCell.Value2 += kvp.Value;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
|
2022-01-26 17:41:46 +03:00
|
|
|
|
exportedValues++;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
}
|
2022-01-26 17:41:46 +03:00
|
|
|
|
|
|
|
|
|
offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}";
|
2022-01-07 19:04:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 10:37:25 +03:00
|
|
|
|
AutoFilter filter = offer.Sheet.AutoFilter;
|
|
|
|
|
int firstFilterColumn = filter.Range.Column;
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
2022-01-09 10:37:25 +03:00
|
|
|
|
filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1 + exportedLists, "<>");
|
|
|
|
|
offer.Sheet.Range["A1"].Activate();
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
2022-01-09 15:47:54 +03:00
|
|
|
|
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
|
|
|
|
|
|
|
|
|
|
Forms.Dialog.SaveWorkbookAs();
|
2022-01-07 19:04:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|