RhSolutions-AddIn/src/AddIn/RegistryUtil.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2021-12-17 09:07:03 +03:00
using Microsoft.Win32;
2022-02-02 09:46:47 +03:00
using RehauSku.Interface;
using System;
using System.IO;
2021-12-24 16:22:03 +03:00
using System.Windows.Forms;
2021-12-17 09:07:03 +03:00
namespace RehauSku
{
static class RegistryUtil
{
2022-01-09 15:47:54 +03:00
private static string priceListPath;
private static int? storeResponseOrder;
private static RegistryKey RootKey { get; set; }
2021-12-22 17:07:37 +03:00
public static void Initialize()
2021-12-17 09:07:03 +03:00
{
2022-01-09 15:47:54 +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()
{
2022-01-09 15:47:54 +03:00
RootKey.Close();
2021-12-23 15:31:23 +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
{
if (string.IsNullOrEmpty(priceListPath) || !File.Exists(priceListPath))
2021-12-22 17:07:37 +03:00
{
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("Нет файла шаблона");
2021-12-22 17:07:37 +03:00
}
2021-12-17 09:07:03 +03:00
2021-12-22 17:07:37 +03:00
else
{
2022-01-09 15:47:54 +03:00
return priceListPath;
2021-12-22 17:07:37 +03:00
}
}
2021-12-24 17:42:20 +03:00
set
{
2022-01-09 15:47:54 +03:00
priceListPath = value;
RootKey.SetValue("PriceListPath", value);
2021-12-24 17:42:20 +03:00
}
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
{
2022-01-09 15:47:54 +03:00
if (storeResponseOrder == null)
2021-12-22 17:07:37 +03:00
{
2022-01-09 15:47:54 +03:00
RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default);
storeResponseOrder = (int)ResponseOrder.Default;
return (ResponseOrder)storeResponseOrder.Value;
2021-12-22 17:07:37 +03:00
}
2021-12-22 08:26:54 +03:00
2021-12-22 17:07:37 +03:00
else
{
2022-01-09 15:47:54 +03:00
return (ResponseOrder)storeResponseOrder.Value;
2021-12-22 17:07:37 +03:00
}
}
2021-12-17 09:07:03 +03:00
}
}
}