using System; using System.Collections.Generic; using System.Text; using System.Configuration; namespace HH.WMS.Utils { /// ///   ///  常用工具类——Web.Config操作类 ///  -------------------------------------------------------------- ///  GetConfigString:得到AppSettings中的配置字符串信息 ///  GetConnectionString:得到Connection中配置字符串信息 ///  GetConfigBool:得到AppSettings中的配置Bool信息 ///  GetConfigDecimal:得到AppSettings中的配置Decimal信息 ///  GetConfigDecimal:得到AppSettings中的配置int信息 /// public class ZConfig { #region Asp.NET的Web.config #region 得到AppSettings中的配置字符串信息 /// /// 得到AppSettings中的配置字符串信息 /// /// AppSetting中关键字KEY /// AppSettings中的配置字符串信息 public static string GetConfigString(string key) { string AppStr = ConfigurationManager.AppSettings[key].ToString(); return AppStr; } #endregion #region 得到Connection中配置字符串信息 /// /// 得到Connection中配置字符串信息 /// /// Connection中name的值 /// Connection中name的值 public static string GetConnectionString(string key) { string ConnStr = ConfigurationManager.ConnectionStrings[key].ToString(); return ConnStr; } #endregion #region 得到AppSettings中的配置Bool信息 /// /// 得到AppSettings中的配置Bool信息 /// /// /// 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; } #endregion #region 得到AppSettings中的配置Decimal信息 /// /// 得到AppSettings中的配置Decimal信息 /// /// /// 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; } #endregion #region 得到AppSettings中的配置int信息 /// /// 得到AppSettings中的配置int信息 /// /// /// 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; } #endregion #endregion } }