using Microsoft.Win32; using RhSolutions.Interface; using System; using System.IO; using System.Windows.Forms; namespace RhSolutions { 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); } } }