RhSolutions-AddIn/src/PriceListTools/MergeTool.cs

66 lines
2.3 KiB
C#
Raw Normal View History

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