aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn/RegistryUtil.cs
blob: ceee2fe8d56f26af39b70a3fe05b054f9ab17b54 (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
75
76
using Microsoft.Win32;
using System.IO;
using RehauSku.Forms;
using System.Windows.Forms;
using ExcelDna.Integration;

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))
                {
                    //MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    string fileName = Dialog.GetFilePath();
                    priceListPath = fileName;
                    RootKey.SetValue("PriceListPath", fileName);
                    return priceListPath;
                }

                else
                {
                    return priceListPath;
                }
            }

            set
            {
                priceListPath = value;
                RootKey.SetValue("PriceListPath", value);
            }
        }

        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;
                }
            }
        }
    }
}