aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn/RegistryUtil.cs
blob: dabd74df001b667f6350f8e2b31e30374645e355 (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
77
78
79
80
81
using Microsoft.Win32;
using RehauSku.Interface;
using System;
using System.IO;
using System.Windows.Forms;

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 string PriceListPath
        {
            get
            {
                if (string.IsNullOrEmpty(priceListPath) || !File.Exists(priceListPath))
                {
                    DialogResult result = MessageBox.Show("Прайс-лист отсутствует или неверный файл шаблона прайс-листа. " +
                        "Укажите файл шаблона прайс-листа.",
                        "Нет файла шаблона",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    if (result == DialogResult.OK)
                    {
                        string fileName = Dialog.GetFilePath();
                        priceListPath = fileName;
                        RootKey.SetValue("PriceListPath", fileName);
                        return priceListPath;
                    }

                    else
                        throw new Exception("Нет файла шаблона");
                }

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