2022-01-27 09:59:33 +03:00
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
|
|
|
|
using System;
|
2022-01-27 10:22:30 +03:00
|
|
|
|
using System.Collections.Generic;
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
|
|
|
|
namespace RehauSku.PriceListTools
|
|
|
|
|
{
|
2022-01-27 10:22:30 +03:00
|
|
|
|
internal class Source : PriceList
|
2022-01-27 09:59:33 +03:00
|
|
|
|
{
|
2022-01-28 11:41:35 +03:00
|
|
|
|
public Dictionary<Position, double> PositionAmount { get; private set; }
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
2022-01-27 10:22:30 +03:00
|
|
|
|
public Source(Workbook workbook)
|
2022-01-27 09:59:33 +03:00
|
|
|
|
{
|
2022-01-28 12:44:37 +03:00
|
|
|
|
if (workbook == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Нет рабочего файла");
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 09:59:33 +03:00
|
|
|
|
Sheet = workbook.ActiveSheet;
|
2022-01-27 10:22:30 +03:00
|
|
|
|
Name = workbook.Name;
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
|
|
|
|
amountCell = Sheet.Cells.Find(amountHeader);
|
|
|
|
|
skuCell = Sheet.Cells.Find(skuHeader);
|
|
|
|
|
groupCell = Sheet.Cells.Find(groupHeader);
|
2022-01-28 11:41:35 +03:00
|
|
|
|
nameCell = Sheet.Cells.Find(nameHeader);
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
2022-01-28 11:41:35 +03:00
|
|
|
|
if (amountCell == null || skuCell == null || groupCell == null || nameCell == null)
|
2022-01-27 09:59:33 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
throw new ArgumentException($"Файл {Name} не распознан");
|
2022-01-27 09:59:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 11:41:35 +03:00
|
|
|
|
CreatePositionsDict();
|
2022-01-27 09:59:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 11:41:35 +03:00
|
|
|
|
private void CreatePositionsDict()
|
2022-01-27 09:59:33 +03:00
|
|
|
|
{
|
2022-01-28 11:41:35 +03:00
|
|
|
|
PositionAmount = new Dictionary<Position, double>();
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
2022-01-28 15:59:47 +03:00
|
|
|
|
for (int row = amountCell.Row + 1; row < Sheet.AutoFilter.Range.Rows.Count; row++)
|
2022-01-27 09:59:33 +03:00
|
|
|
|
{
|
2022-01-28 15:59:47 +03:00
|
|
|
|
object amount = Sheet.Cells[row, amountCell.Column].Value2;
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
|
|
|
|
if (amount != null && (double)amount != 0)
|
|
|
|
|
{
|
2022-01-28 15:59:47 +03:00
|
|
|
|
object group = Sheet.Cells[row, groupCell.Column].Value2;
|
|
|
|
|
object name = Sheet.Cells[row, nameCell.Column].Value2;
|
|
|
|
|
object sku = Sheet.Cells[row, skuCell.Column].Value2;
|
|
|
|
|
|
2022-01-28 11:41:35 +03:00
|
|
|
|
Position p = new Position(group.ToString(), sku.ToString(), name.ToString());
|
2022-01-27 09:59:33 +03:00
|
|
|
|
|
2022-01-28 11:41:35 +03:00
|
|
|
|
if (PositionAmount.ContainsKey(p))
|
|
|
|
|
{
|
|
|
|
|
PositionAmount[p] += (double)amount;
|
|
|
|
|
}
|
2022-01-27 09:59:33 +03:00
|
|
|
|
else
|
2022-01-28 11:41:35 +03:00
|
|
|
|
{
|
|
|
|
|
PositionAmount.Add(p, (double)amount);
|
|
|
|
|
}
|
2022-01-27 09:59:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|