aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/SourceFile.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-01-27 09:59:33 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-01-27 09:59:33 +0300
commit8e3dff1788905c203509f866921957b027cb2643 (patch)
tree7d671c8f01be532bc013322c366bba35fcccaab0 /src/PriceListTools/SourceFile.cs
parent233c91c71b5c68ed7c51f26731b491dac8423771 (diff)
Extract PriceList Base Class
Diffstat (limited to 'src/PriceListTools/SourceFile.cs')
-rw-r--r--src/PriceListTools/SourceFile.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/PriceListTools/SourceFile.cs b/src/PriceListTools/SourceFile.cs
new file mode 100644
index 0000000..20d110d
--- /dev/null
+++ b/src/PriceListTools/SourceFile.cs
@@ -0,0 +1,74 @@
+using Microsoft.Office.Interop.Excel;
+using System.Collections.Generic;
+using System;
+
+namespace RehauSku.PriceListTools
+{
+ internal class SourceFile : PriceList
+ {
+ public Dictionary<string, double> SkuAmount { get; private set; }
+
+ public SourceFile(Workbook workbook)
+ {
+ Sheet = workbook.ActiveSheet;
+ Name = workbook.Name + '\n' + Sheet.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);
+ }
+ }
+ }
+ }
+
+ internal class NewFile : PriceList
+ {
+ public Dictionary<PriceListPosition, Range> Map { get; private set; }
+
+ public void CreateMap()
+ {
+ Range amountCell = Sheet.Cells.Find(amountHeader);
+ Range skuCell = Sheet.Cells.Find(skuHeader);
+ Range groupCell = Sheet.Cells.Find(groupHeader);
+
+ //headerRowNumber = amountCell.Row;
+ //skuColumnNumber = skuCell.Column;
+ //amountColumnNumber = amountCell.Column;
+ //groupColumnNumber = groupCell.Column;
+
+ //for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++)
+ //{
+ // string sku =
+ //}
+ }
+ }
+}
+