aboutsummaryrefslogtreecommitdiff
path: root/src/Services/RegistryUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Services/RegistryUtil.cs')
-rw-r--r--src/Services/RegistryUtil.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/Services/RegistryUtil.cs b/src/Services/RegistryUtil.cs
new file mode 100644
index 0000000..8b165ea
--- /dev/null
+++ b/src/Services/RegistryUtil.cs
@@ -0,0 +1,74 @@
+using Microsoft.Win32;
+using RhSolutions.Controllers;
+using RhSolutions.Models;
+using System;
+using System.IO;
+using System.Windows.Forms;
+
+namespace RhSolutions.Services
+{
+ static class RegistryUtil
+ {
+ private static string priceListPath;
+ private static RegistryKey RootKey { get; set; }
+
+ public static void Initialize()
+ {
+ RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
+ priceListPath = RootKey.GetValue("PriceListPath") as string;
+ }
+
+ 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();
+
+ if (string.IsNullOrEmpty(fileName))
+ {
+ throw new Exception("Нет файла шаблона");
+ }
+
+ priceListPath = fileName;
+ RootKey.SetValue("PriceListPath", fileName);
+ return priceListPath;
+ }
+
+ else
+ throw new Exception("Нет файла шаблона");
+ }
+
+ else
+ {
+ return priceListPath;
+ }
+ }
+
+ set
+ {
+ priceListPath = value;
+ RootKey.SetValue("PriceListPath", value);
+ RibbonController.RefreshControl("setPriceList");
+ }
+ }
+
+ public static string GetPriceListName()
+ {
+ return Path.GetFileName(priceListPath);
+ }
+ }
+}