aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/SourceFile.cs
blob: 20d110dc6bca7bb50b85ba0174ddad9e6eb57442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 =
            //}
        }
    }
}