aboutsummaryrefslogtreecommitdiff
path: root/Source/PriceListTools/PriceListUtil.cs
blob: 14797d99f961be2c9aebfe3ca380c685fd212944 (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
using System.Collections.Generic;
using System.IO;

namespace RehauSku.PriceListTools
{
    static class PriceListUtil
    {
        public static string CreateNewExportFile()
        {
            string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath);
            string path = Path.GetTempFileName() + fileExtension;

            File.Copy(RegistryUtil.PriceListPath, path);
            return path;
        }

        public static void AddValues(this Dictionary<string, double> SkuAmount, PriceList priceList)
        {
            object[,] amountCells = priceList.ActiveSheet.amountCells;
            object[,] skuCells = priceList.ActiveSheet.skuCells;

            for (int row = priceList.ActiveSheet.headerRow.Value + 1; row < amountCells.GetLength(0); row++)
            {
                object amount = amountCells[row, 1];
                object sku = skuCells[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);
                }
            }
        }
    }
}