diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-22 17:07:37 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-22 17:07:37 +0300 |
commit | ce5597d042062c820288c63b4e571ee77ac23ab0 (patch) | |
tree | 9400511fce89ae4b6d4df205b605f560778dcb57 /Source/AddIn | |
parent | f97d344f39c46b5e2f883765e8859e78007a11b0 (diff) |
RegistryUtil and some fixes
Diffstat (limited to 'Source/AddIn')
-rw-r--r-- | Source/AddIn/AddIn.cs | 1 | ||||
-rw-r--r-- | Source/AddIn/FileDialog.cs | 24 | ||||
-rw-r--r-- | Source/AddIn/RegistryUtil.cs | 57 |
3 files changed, 63 insertions, 19 deletions
diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 4a26f55..08b6dcf 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -22,6 +22,7 @@ namespace RehauSku { RegisterFunctions(); IntelliSenseServer.Install(); + RegistryUtil.Initialize(); } public void AutoClose() diff --git a/Source/AddIn/FileDialog.cs b/Source/AddIn/FileDialog.cs new file mode 100644 index 0000000..a7e2144 --- /dev/null +++ b/Source/AddIn/FileDialog.cs @@ -0,0 +1,24 @@ +using System.Windows.Forms; + +namespace RehauSku +{ + static class FileDialog + { + public static string GetFilePath() + { + string filePath = string.Empty; + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Все файлы (*.*)|*.*"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + filePath = dialog.FileName; + } + } + + return filePath; + } + } +} diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 6ab7682..19f48b8 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -1,42 +1,61 @@ using Microsoft.Win32; +using System.IO; namespace RehauSku { static class RegistryUtil { - public static string PriceListPath + private static string _priceListPath; + private static int? _storeResponseOrder; + private static RegistryKey _RootKey { get; set; } + + public static void Initialize() { - get => (string)_RootKey.GetValue("PriceListPath"); + _RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); + _priceListPath = _RootKey.GetValue("PriceListPath") as string; + _storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?; } - public static ResponseOrder StoreResponseOrder + public static bool IsPriceListPathEmpty() { - get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder"); + return string.IsNullOrEmpty(_priceListPath); } - private static RegistryKey _RootKey + public static string PriceListPath { get { - return _OpenRootKey() ?? _CreateRootKey(); - } - } + if (IsPriceListPathEmpty() || !File.Exists(_priceListPath)) + { + string fileName = FileDialog.GetFilePath(); + _priceListPath = fileName; + _RootKey.SetValue("PriceListPath", fileName); + return _priceListPath; + } - private static RegistryKey _OpenRootKey() - { - return Registry.CurrentUser - .OpenSubKey(@"SOFTWARE\REHAU\SkuAssist"); + else + { + return _priceListPath; + } + } } - private static RegistryKey _CreateRootKey() + public static ResponseOrder StoreResponseOrder { - RegistryKey key = Registry.CurrentUser - .CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); - - key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm"); - key.SetValue("StoreResponseOrder", 0); + get + { + if (_storeResponseOrder == null) + { + _RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default); + _storeResponseOrder = (int)ResponseOrder.Default; + return (ResponseOrder)_storeResponseOrder.Value; + } - return key; + else + { + return (ResponseOrder)_storeResponseOrder.Value; + } + } } } } |