RhSolutions-AddIn/src/PriceListTools/Source.cs

53 lines
1.6 KiB
C#
Raw Normal View History

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
{
public Dictionary<string, double> SkuAmount { get; private set; }
2022-01-27 10:22:30 +03:00
public Source(Workbook workbook)
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);
if (amountCell == null || skuCell == null || groupCell == null)
{
throw new ArgumentException($"Лист { Name } не распознан");
}
CreateAmountDict();
}
private void CreateAmountDict()
{
SkuAmount = new Dictionary<string, double>();
object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2;
object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;
for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++)
{
object amount = amountColumn[row, 1];
object sku = skuColumn[row, 1];
if (amount != null && (double)amount != 0)
{
if (SkuAmount.ContainsKey(sku.ToString()))
SkuAmount[sku.ToString()] += (double)amount;
else
SkuAmount.Add(sku.ToString(), (double)amount);
}
}
}
}
}