⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectioninfo.cs

📁 股票操作员每日一记 源程序 股票操作员每日一记 源程序
💻 CS
字号:
using System;
using System.Configuration;
using System.Xml;
 
namespace stock_Log
{
	/// <summary>
	/// ConnectionInfo 的摘要说明。
	/// </summary>
	public class ConnectionInfo
	{
		//本地数据库连接字符串
		//public static readonly string GetConnString() = ConfigurationSettings.AppSettings["ConnString"];
		//public static readonly string GetConnString() = "Server=192.168.0.242;User ID=sa;Password=;Database=LocalCost; Max Pool Size=75; Min Pool Size=5";		

		public ConnectionInfo()
		{
			
		}

        public static string GetConnString(string filename, String key)
		{
            //string dir1 = AppDomain.CurrentDomain.BaseDirectory;
            //string dir2 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            //string dir3 = (string)AppDomain.CurrentDomain.GetData("APPBASE");


			string strPath =AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
			//string strPath2 = @"C:\config.xml";
			string CONN_STRING = string.Empty ;

			// Create an instance of an XML document
			XmlDocument doc = new XmlDocument();

			try
			{
				// Load into memory the specified config file
				doc.Load(strPath + filename);

				// Find the appsettings add nodes
				XmlNodeList nodes = doc.SelectNodes("/configuration/appSettings/add");

				// For each app setting found in web.config, set the value if it is a connection string
				foreach(XmlNode node in nodes)
				{
                    if (node.Attributes["key"].Value == key)
					{
					    CONN_STRING = node.Attributes["value"].Value;
                        break;
					}
				}
			}
			catch(Exception e)
			{
				Console.Write(e.Message );   
				    	
			}
            return CONN_STRING;
		}

        public static string GetSyncString(string filename)
        {

            string strPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            //string strPath2 = @"C:\config.xml";
            string SYNC_STRING = string.Empty;

            // Create an instance of an XML document
            XmlDocument doc = new XmlDocument();

            try
            {
                // Load into memory the specified config file
                doc.Load(strPath + filename);

                // Find the appsettings add nodes
                XmlNodeList nodes = doc.SelectNodes("/configuration/appSettings/add");

                // For each app setting found in web.config, set the value if it is a connection string
                foreach (XmlNode node in nodes)
                {
                    switch (node.Attributes["key"].Value)
                    {
                        case "SYNC_PATH":
                            SYNC_STRING = node.Attributes["value"].Value;
                            break;
                        default:
                            // Don't do anything
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);

            }
            return SYNC_STRING;
        }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -