示例#1
0
 public void Add(DataConnInfo dc)
 {
     if (null != this[dc.Name])
     {
         this.BaseRemove(dc.Name);
     }
     this.BaseAdd(dc);
 }
示例#2
0
        /// <summary>
        /// 指定数据源连接名称,数据访问资源文件名称
        /// </summary>
        /// <param name="itemname">指定数据源连接名称</param>
        /// <param name="xmlfile">XML数据资源文件</param>
        public DataAccRes(string itemname, string xmlfile)
        {
            DataConnSection conn     = DefaultSection;
            DataConnInfo    conninfo = null;

            if (!string.IsNullOrEmpty(itemname))
            {
                conninfo = conn.DataConnList[itemname];
            }
            if (null == conninfo)
            {
                conninfo = DefaultDataConnInfo;
            }
            this._DbType   = conninfo.DAType;
            this._sConn    = conninfo.Value;
            this._sXmlFile = xmlfile;
        }
示例#3
0
        protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
            if (Session["userid"] == null)
            {
                this.Response.Write("<script language=\"javascript\">");
                this.Response.Write("alert('您未正常登录,请登录后再使用,谢谢!')");
                this.Response.Write("</script>");
                this.Response.Redirect("index.htm");
            }
            exePath = this.Request.PhysicalApplicationPath;                         // "D:\\hmcrm\\HMApp\\"
            string bakPath = this.Request.PhysicalApplicationPath + "backup\\";     // "D:\\hmcrm\\HMApp\backup"
            string userkey = this.Request.QueryString["userkey"];
            string dbsvr = this.Request.QueryString["dbsvr"];
            string dbname = this.Request.QueryString["dbname"];
            string dbuser = this.Request.QueryString["dbuser"];
            string dbpwd = this.Request.QueryString["dbpwd"];
            string abook = this.Request.QueryString["abook"];
            string abookval = this.Request.QueryString["abookval"];
            string dbpath = this.Request.QueryString["dbpath"];
            string xmlstr = "";
            if (!CreateDataBaseByBak(dbsvr, dbuser, dbpwd, dbname, dbpath, bakPath))
            {
                xmlstr = "<table><result>数据库建立失败!</result></table>";
                Response.ContentType = "text/xml";
                Response.Expires = -1;
                Response.Clear();
                Response.Write("<?xml version='1.0' encoding='GB2312'?>");
                Response.Write(xmlstr);
                //Response.End();
                return;
            }
            //根据sendkey来返回web.config的配置信息
            if (userkey != null)
            {
                return;
            }

            
            Process.Start("iisreset");

            Configuration config = DataAccRes.DefaultConfiguration;
            System.IO.FileInfo FileInfo = new System.IO.FileInfo(config.FilePath);
            if (!FileInfo.Exists)
                return;
            KeyValueConfigurationCollection settings = config.AppSettings.Settings;
            AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
            string[] appKeys = appSettings.Settings.AllKeys;
            DataConnSection connsection = config.GetSection("CustomSection") as DataConnSection;
            DataConnInfo conn = connsection.DataConnList[dbname];
            string dbtype = "SqlClient";
            string strcn = String.Format("server={0};user id={1};password={2};database={3};Min Pool Size=10;Connection Lifetime=240;Connection Timeout=120;"
            , dbsvr, dbuser, dbpwd);
            if (null == conn)
            {
                conn = new DataConnInfo(dbuser, dbtype, strcn);
                connsection.DataConnList.Add(conn);
            }
            else
            {
                conn.DbType = dbtype;
                conn.Value = strcn;
            }
            config.Save();
            SqlConnection CN = new SqlConnection();
            string strCn = DataAccRes.DefaultDataConnInfo.Value;
            CN.ConnectionString = strCn;
            CN.Open();
            if (CN.State == ConnectionState.Open) CN.Close();
            xmlstr = "<table><result>数据库建立成功!</result></table>";
            Response.ContentType = "text/xml";
            Response.Expires = -1;
            Response.Clear();
            Response.Write("<?xml version='1.0' encoding='GB2312'?>");
            Response.Write(xmlstr);
            //Response.End();

		}
示例#4
0
 public void Add(DataConnInfo dc)
 {
     if (null != this[dc.Name])
         this.BaseRemove(dc.Name);
     this.BaseAdd(dc);
 }
 /// <summary>
 /// 根据参数设置系统信息配置,修改配置文件
 /// 在系统数据源文件是system,数据源是"系统信息配置"
 /// </summary>
 /// <param name="param">系统配置参数</param>
 private void ConfigSystem(NameObjectList[] paramList)
 {
     Configuration   config=DataAccRes.DefaultConfiguration;
     KeyValueConfigurationCollection settings = config.AppSettings.Settings;
     DataConnSection connsection = config.GetSection("CustomSection") as DataConnSection;
     int icount = paramList.Length;
     for (int i = 0; i < icount; i++)
     {
         NameObjectList param = paramList[i];
         if ("appSettings" == param["配置类别"].ToString())
         {
             string strname = param["名称"].ToString();
             if (null == settings[strname])
                 settings.Add(strname, param["配置值"].ToString());
             else
                 settings[strname].Value = param["配置值"].ToString();
         }
         else
         {
             string strname = param["名称"].ToString();
             DataConnInfo conn = connsection.DataConnList[strname];
             if (null == conn)
             {
                 conn = new DataConnInfo(strname, param["数据库类别"].ToString(), param["配置值"].ToString());
                 connsection.DataConnList.Add(conn);
             }
             else
             {
                 conn.DbType = param["数据库类别"].ToString();
                 conn.Value = param["配置值"].ToString();
             }
             
         }
     }
     config.Save();
 }