Esempio n. 1
0
        /// <summary>
        /// 保存数据库连接到用户设置
        /// </summary>
        private void SaveConnectionToFile()
        {
            Config.History history = Config.History.Load();
            switch (tcDatabase.SelectedIndex)
            {
            case 0:
                history.DatabaseType = Model.DatabaseTypes.Access;
                history.AccessConn   = accessConn1.ConnectionString;
                break;

            case 2:
                history.DatabaseType = Model.DatabaseTypes.MySql;
                history.MySqlConn    = mySqlConn1.ConnectionString;
                break;

            case 3:
                history.DatabaseType = Model.DatabaseTypes.Oracle;
                history.OracleConn   = oracleConn1.ConnectionString;
                break;

            case 4:
                history.DatabaseType = Model.DatabaseTypes.SQLite;
                history.SQLiteConn   = sqLiteConn1.ConnectionString;
                break;

            case 1:
            default:
                history.DatabaseType  = sqlConn1.IsSql2005 ? Model.DatabaseTypes.Sql2005 : Model.DatabaseTypes.Sql2000;
                history.SqlServerConn = sqlConn1.ConnectionString;
                break;
            }
            Config.History.Save(history);
        }
Esempio n. 2
0
        /// <summary>
        /// 从设置文件中加载数据库连接
        /// </summary>
        private void LoadConnectionFromFile()
        {
            try
            {
                Config.History history = Config.History.Load();
                if (!string.IsNullOrEmpty(history.AccessConn))
                {
                    accessConn1.ConnectionString = history.AccessConn;
                }
                if (!string.IsNullOrEmpty(history.SqlServerConn))
                {
                    sqlConn1.ConnectionString = history.SqlServerConn;
                    sqlConn1.IsSql2005        = history.DatabaseType == Model.DatabaseTypes.Sql2005;
                }
                if (!string.IsNullOrEmpty(history.MySqlConn))
                {
                    mySqlConn1.ConnectionString = history.MySqlConn;
                }
                if (!string.IsNullOrEmpty(history.OracleConn))
                {
                    oracleConn1.ConnectionString = history.OracleConn;
                }
                if (!string.IsNullOrEmpty(history.SQLiteConn))
                {
                    sqLiteConn1.ConnectionString = history.SQLiteConn;
                }

                switch (history.DatabaseType)
                {
                case Model.DatabaseTypes.Access:
                    tcDatabase.SelectedIndex = 0;
                    break;

                case Model.DatabaseTypes.MySql:
                    tcDatabase.SelectedIndex = 2;
                    break;

                case Model.DatabaseTypes.Oracle:
                    tcDatabase.SelectedIndex = 3;
                    break;

                case Model.DatabaseTypes.SQLite:
                    tcDatabase.SelectedIndex = 4;
                    break;

                case Model.DatabaseTypes.Sql2000:
                case Model.DatabaseTypes.Sql2005:
                default:
                    tcDatabase.SelectedIndex = 1;
                    break;
                }
            }
            catch
            {
                // 加载失败无需操作
            }
        }