aboutsummaryrefslogtreecommitdiff
path: root/Source/AddIn/RegistryUtil.cs
blob: ef1398eb2d3205948b12864849ff618e75a297c0 (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
using Microsoft.Win32;
using System.IO;

namespace RehauSku
{
    static class RegistryUtil
    {
        private static string _priceListPath;
        private static int? _storeResponseOrder;
        private static RegistryKey _RootKey { get; set; }

        public static void Initialize()
        {
            _RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); 
            _priceListPath = _RootKey.GetValue("PriceListPath") as string;
            _storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?;
        }

        public static void Uninitialize()
        {
            _RootKey.Close();
        }

        public static bool IsPriceListPathEmpty()
        {
            return string.IsNullOrEmpty(_priceListPath);
        }

        public static string PriceListPath
        {
            get
            {
                if (IsPriceListPathEmpty() || !File.Exists(_priceListPath))
                {
                    string fileName = FileDialog.GetFilePath();
                    _priceListPath = fileName;
                    _RootKey.SetValue("PriceListPath", fileName);
                    return _priceListPath;
                }

                else
                {
                    return _priceListPath;
                }
            }
        }

        public static ResponseOrder StoreResponseOrder
        {
            get
            {
                if (_storeResponseOrder == null)
                {
                    _RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default);
                    _storeResponseOrder = (int)ResponseOrder.Default;
                    return (ResponseOrder)_storeResponseOrder.Value;
                }

                else
                {
                    return (ResponseOrder)_storeResponseOrder.Value;
                }
            }
        }
    }
}