From 9b205a5b3eb3d680e1664fc30d07e7c65692c764 Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Thu, 22 Feb 2024 18:09:27 +0300 Subject: [PATCH] Ensure price list exists on Excel open --- .../Controllers/RibbonController.cs | 19 +++++++++++-------- RhSolutions.AddIn/Tools/EventsUtil.cs | 7 +------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/RhSolutions.AddIn/Controllers/RibbonController.cs b/RhSolutions.AddIn/Controllers/RibbonController.cs index f7fdd1d..b33f6d6 100644 --- a/RhSolutions.AddIn/Controllers/RibbonController.cs +++ b/RhSolutions.AddIn/Controllers/RibbonController.cs @@ -1,16 +1,10 @@ using ExcelDna.Integration.CustomUI; +using System.IO; using System.Reflection; using System.Runtime.InteropServices; -#if! NET472 -using System.Runtime.Versioning; -#endif -using System.Windows.Forms; namespace RhSolutions.Controllers; -#if !NET472 -[SupportedOSPlatform("windows")] -#endif [ComVisible(true)] public class RibbonController : ExcelRibbon { @@ -114,7 +108,7 @@ public class RibbonController : ExcelRibbon public string GetPriceListPathLabel(IRibbonControl control) { string name = RhSolutionsAddIn.Configuration.GetPriceListFileName(); - return string.IsNullOrEmpty(name) ? "Шаблонный файл" : name; + return string.IsNullOrEmpty(name) ? "Указать шаблонный файл" : name; } public static void UpdateWorkbookValidation() @@ -128,4 +122,13 @@ public class RibbonController : ExcelRibbon _workbookIsValid = worksheet.IsValidSource(); } } + + public static void EnsurePriseListExists() + { + string pricelistPath = RhSolutionsAddIn.Configuration.GetPriceListPath(); + if (!File.Exists(pricelistPath)) + { + RhSolutionsAddIn.Configuration.SetPriceListPath(string.Empty); + } + } } diff --git a/RhSolutions.AddIn/Tools/EventsUtil.cs b/RhSolutions.AddIn/Tools/EventsUtil.cs index 6723835..5522c10 100644 --- a/RhSolutions.AddIn/Tools/EventsUtil.cs +++ b/RhSolutions.AddIn/Tools/EventsUtil.cs @@ -1,17 +1,12 @@ using RhSolutions.Controllers; -#if !NET472 -using System.Runtime.Versioning; -#endif namespace RhSolutions.Tools; -#if !NET472 -[SupportedOSPlatform("windows")] -#endif internal static class EventsUtil { public static void Initialize() { + RibbonController.EnsurePriseListExists(); RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton; RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons; RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;