zoukankan      html  css  js  c++  java
  • 使用webconfig,联动配置程序

    只需要在appSettings中指定当前使用哪个系统,而不用到处配置

    只需要访问自定义的配置文件,就可以读取所有的节点数据

    第一步:


      <configSections>
        <sectionGroup name="AllApp">
          <section name = "App_1" type="System.Configuration.SingleTagSectionHandler"/>
          <section name = "App_2"  type = "System.Configuration.SingleTagSectionHandler" />
          <section name = "App_3"  type = "System.Configuration.SingleTagSectionHandler" />
        </sectionGroup>
      </configSections >

      <AllApp>
        <JIT SystemID="App_1"
             SystemTitle="系统_1"
             ConnectionString="Data Source=192.1.1.1;Initial Catalog=DB_1;User ID=sa;Password=1"/>
        <PIT SystemID="App_2"
             SystemTitle="系统_2"
             ConnectionString="Data Source=192.1.1.1;Initial Catalog=DB_2;User ID=sa;Password=1"/>
        <PKT SystemID="App_3"
             SystemTitle="系统_3"
             ConnectionString="Data Source=192.1.1.1;Initial Catalog=DB_3;User ID=sa;Password=1"/>
      </AllApp>

      <appSettings>
        <add key="CurrentApp" value="AllApp/JIT"/>
      </appSettings>
      第二步:

    public class MyConfig
    {
        static Hashtable table = null;
        public static void Init()
        {
            table = new Hashtable();
            string app = System.Configuration.ConfigurationManager.AppSettings["CurrentApp"];
            table = (Hashtable)ConfigurationManager.GetSection(app);
        }

        public static string SystemID
        {
            get
            {
                if (table == null)
                    Init();
                return table["SystemID"].ToString();
            }
        }
        public static string SystemTitle
        {
            get
            {
                if (table == null)
                    Init();
                return table["SystemTitle"].ToString();
            }
        }
        public static string ConnectionString
        {
            get
            {
                if (table == null)
                    Init();
                return table["ConnectionString"].ToString();
            }
        }
    }

    第三步:


    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string systitle = MyConfig.SystemTitle;

  • 相关阅读:
    第一篇:GCD的使用
    第一篇:线程的安全
    内存问题
    第一篇:多线程的概念
    第一篇:NSOperation的概念
    存储问题
    第一篇:NSTread线程的创建
    第一篇:多线程使用
    遍历所有表,取每个表的MAXID更新到ID控制表
    <转载>SQL查询数据库各表所占空间
  • 原文地址:https://www.cnblogs.com/zzlchn/p/1850624.html
Copyright © 2011-2022 走看看