aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/Source.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-01-27 10:22:30 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-01-27 10:22:30 +0300
commit72ac236b15603e84f18ec346749186b6cb2c2bdf (patch)
treebf47c7f4e92e1008fe1b4a34851b642d15ee0c98 /src/PriceListTools/Source.cs
parent8e3dff1788905c203509f866921957b027cb2643 (diff)
Refactoring tolls classes
Diffstat (limited to 'src/PriceListTools/Source.cs')
-rw-r--r--src/PriceListTools/Source.cs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/Source.cs
new file mode 100644
index 0000000..40ac257
--- /dev/null
+++ b/src/PriceListTools/Source.cs
@@ -0,0 +1,52 @@
+using Microsoft.Office.Interop.Excel;
+using System;
+using System.Collections.Generic;
+
+namespace RehauSku.PriceListTools
+{
+ internal class Source : PriceList
+ {
+ public Dictionary<string, double> SkuAmount { get; private set; }
+
+ public Source(Workbook workbook)
+ {
+ Sheet = workbook.ActiveSheet;
+ Name = workbook.Name;
+
+ 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);
+ }
+ }
+ }
+ }
+}
+