From 682eba0aaf922e69dfafe05fb6c1bbdbf3a0e04a Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周一, 29 9月 2025 14:35:53 +0800
Subject: [PATCH] 优化

---
 DEmon/iWareCommon/Utils/ConfigHelper.cs |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/DEmon/iWareCommon/Utils/ConfigHelper.cs b/DEmon/iWareCommon/Utils/ConfigHelper.cs
new file mode 100644
index 0000000..609a02a
--- /dev/null
+++ b/DEmon/iWareCommon/Utils/ConfigHelper.cs
@@ -0,0 +1,106 @@
+锘縰sing System;
+using System.Configuration;
+
+namespace iWareCommon.Utils
+{
+	/// <summary>
+	/// web.config鎿嶄綔绫�
+    /// Copyright (C) TBEA.WMS
+	/// </summary>
+	public sealed class ConfigHelper
+	{
+		/// <summary>
+		/// 寰楀埌AppSettings涓殑閰嶇疆瀛楃涓蹭俊鎭�
+		/// </summary>
+		/// <param name="key"></param>
+		/// <returns></returns>
+		public static string GetConfigString(string key)
+		{
+            string CacheKey = "AppSettings-" + key;
+            object objModel = DataCache.GetCache(CacheKey);
+            if (objModel == null)
+            {
+                try
+                {
+                    objModel = ConfigurationManager.AppSettings[key]; 
+                    if (objModel != null)
+                    {                        
+                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(180), TimeSpan.Zero);
+                    }
+                }
+                catch
+                { }
+            }
+            return objModel.ToString();
+		}
+
+		/// <summary>
+		/// 寰楀埌AppSettings涓殑閰嶇疆Bool淇℃伅
+		/// </summary>
+		/// <param name="key"></param>
+		/// <returns></returns>
+		public static bool GetConfigBool(string key)
+		{
+			bool result = false;
+			string cfgVal = GetConfigString(key);
+			if(null != cfgVal && string.Empty != cfgVal)
+			{
+				try
+				{
+					result = bool.Parse(cfgVal);
+				}
+				catch(FormatException)
+				{
+					// Ignore format exceptions.
+				}
+			}
+			return result;
+		}
+		/// <summary>
+		/// 寰楀埌AppSettings涓殑閰嶇疆Decimal淇℃伅
+		/// </summary>
+		/// <param name="key"></param>
+		/// <returns></returns>
+		public static decimal GetConfigDecimal(string key)
+		{
+			decimal result = 0;
+			string cfgVal = GetConfigString(key);
+			if(null != cfgVal && string.Empty != cfgVal)
+			{
+				try
+				{
+					result = decimal.Parse(cfgVal);
+				}
+				catch(FormatException)
+				{
+					// Ignore format exceptions.
+				}
+			}
+
+			return result;
+		}
+		/// <summary>
+		/// 寰楀埌AppSettings涓殑閰嶇疆int淇℃伅
+		/// </summary>
+		/// <param name="key"></param>
+		/// <returns></returns>
+		public static int GetConfigInt(string key)
+		{
+			int result = 0;
+			string cfgVal = GetConfigString(key);
+			if(null != cfgVal && string.Empty != cfgVal)
+			{
+				try
+				{
+					result = int.Parse(cfgVal);
+				}
+				catch(FormatException)
+				{
+					// Ignore format exceptions.
+				}
+			}
+
+			return result;
+		}
+	}
+}

--
Gitblit v1.9.3