#region Comments

// ¹¦ÄÜ£ºWinFormºÍWebFormµÄÍ¨ÓÃÅäÖÃ¹ÜÀíÀà£¬½öÄÜÔÚ±¾³ÌÐò¼¯ÄÚÊ¹ÓÃ¡£
// ×÷Õß£ºAnders Cui
// ÈÕÆÚ£º2007-03-13

// ×î½üÐÞ¸Ä£ºAnders Cui
// ×î½üÐÞ¸ÄÈÕÆÚ£º2007-04-01
// ÐÞ¸ÄÄÚÈÝ£ºÌí¼ÓÍêÕû×¢ÊÍ¡£
// TODO£º

#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Andersc.CodeLib.Common
{
    /// <summary>
    /// WinFormºÍWebFormµÄÍ¨ÓÃÅäÖÃ¹ÜÀíÀà£¬½öÄÜÔÚ±¾³ÌÐò¼¯ÄÚÊ¹ÓÃ¡£
    /// </summary>
    internal class ConfigManager
    {
        ///// <summary>
        ///// ¸ù¾ÝÖ¸¶¨¼üÖµÅÐ¶ÏappSettingsÅäÖÃ½ÚÖÐÒ»¸öÅäÖÃÏîÊÇ·ñ´æÔÚ¡£
        ///// </summary>
        ///// <param name="key">Òª²éÕÒµÄappSettingsÅäÖÃÏîµÄ¼üÖµ¡£</param>
        ///// <returns>Èç¹û¸ÃÏî´æÔÚ£¬·µ»Øtrue£¬·ñÔò·µ»Øfalse¡£</returns>
        //public static bool IsAppSettingExisted(string key)
        //{
        //    if (key == null)
        //    {
        //        throw new ArgumentNullException("key", "ÅäÖÃÏîµÄ¼üÖµ²»¿ÉÒÔÎªnull¡£");
        //    }

        //    bool exists = false;
        //    string[] keys = ConfigurationManager.AppSettings.;
        //    for (int i = 0; i < keys.Length; i++)
        //    {
        //        if (keys[i] == key)
        //        {
        //            exists = true;
        //            break;
        //        }
        //    }

        //    return exists;
        //}

        /// <summary>
        /// »ñÈ¡appSettingsÅäÖÃ½ÚÖÐÖ¸¶¨ÅäÖÃÏîµÄÅäÖÃÐÅÏ¢¡£
        /// </summary>
        /// <param name="key">Òª²éÕÒµÄappSettingsÅäÖÃÏîµÄ¼üÖµ</param>
        /// <returns>Èç¹û¿ÉÒÔÖ¸¶¨µÄÏî´æÔÚ£¬·µ»ØÖ¸¶¨ÅäÖÃÏîµÄÅäÖÃÐÅÏ¢£»Èç¹û²»´æÔÚ£¨°üÀ¨keyÖµÎªnull£©£¬·µ»Ønull</returns>
        public static string GetAppSetting(string key)
        {
            return ConfigurationManager.AppSettings[key];
        }

        /// <summary>
        /// »ñÈ¡¾ßÓÐÖ¸¶¨Ãû³ÆµÄÁ¬½Ó×Ö·û´®ÅäÖÃÏîµÄÖµ£¨connectionStringÊôÐÔ£©¡£
        /// </summary>
        /// <param name="name">Á¬½Ó×Ö·û´®ÅäÖÃÏîµÄÃû³Æ¡£</param>
        /// <returns></returns>
        public static string GetConnectionString(string name)
        {
            return ConfigurationManager.ConnectionStrings[name].ConnectionString;
        }

    }
}
