RhSolutions-AddIn/src/AddIn/RegistryUtil.cs

77 lines
2.3 KiB
C#
Raw Normal View History

2021-12-17 09:07:03 +03:00
using Microsoft.Win32;
2021-12-22 17:07:37 +03:00
using System.IO;
2021-12-24 16:22:03 +03:00
using RehauSku.Forms;
using System.Windows.Forms;
2021-12-17 09:07:03 +03:00
namespace RehauSku
{
static class RegistryUtil
{
2021-12-22 17:07:37 +03:00
private static string _priceListPath;
private static int? _storeResponseOrder;
private static RegistryKey _RootKey { get; set; }
public static void Initialize()
2021-12-17 09:07:03 +03:00
{
2021-12-22 17:07:37 +03:00
_RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
_priceListPath = _RootKey.GetValue("PriceListPath") as string;
_storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?;
2021-12-17 09:07:03 +03:00
}
2021-12-23 15:31:23 +03:00
public static void Uninitialize()
{
_RootKey.Close();
2021-12-24 16:22:03 +03:00
2021-12-23 15:31:23 +03:00
}
2021-12-22 17:07:37 +03:00
public static bool IsPriceListPathEmpty()
2021-12-17 09:07:03 +03:00
{
2021-12-22 17:07:37 +03:00
return string.IsNullOrEmpty(_priceListPath);
2021-12-22 08:26:54 +03:00
}
2021-12-17 09:07:03 +03:00
2021-12-22 17:07:37 +03:00
public static string PriceListPath
2021-12-22 08:26:54 +03:00
{
get
2021-12-17 09:07:03 +03:00
{
2021-12-22 17:07:37 +03:00
if (IsPriceListPathEmpty() || !File.Exists(_priceListPath))
{
2021-12-24 16:22:03 +03:00
MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning);
string fileName = Dialog.GetFilePath();
2021-12-22 17:07:37 +03:00
_priceListPath = fileName;
_RootKey.SetValue("PriceListPath", fileName);
return _priceListPath;
}
2021-12-17 09:07:03 +03:00
2021-12-22 17:07:37 +03:00
else
{
return _priceListPath;
}
}
2021-12-24 17:42:20 +03:00
set
{
_priceListPath = value;
_RootKey.SetValue("PriceListPath", value);
}
2021-12-22 08:26:54 +03:00
}
2021-12-17 09:07:03 +03:00
2021-12-22 17:07:37 +03:00
public static ResponseOrder StoreResponseOrder
2021-12-17 09:07:03 +03:00
{
2021-12-22 17:07:37 +03:00
get
{
if (_storeResponseOrder == null)
{
_RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default);
_storeResponseOrder = (int)ResponseOrder.Default;
return (ResponseOrder)_storeResponseOrder.Value;
}
2021-12-22 08:26:54 +03:00
2021-12-22 17:07:37 +03:00
else
{
return (ResponseOrder)_storeResponseOrder.Value;
}
}
2021-12-17 09:07:03 +03:00
}
}
}