public static void saveConfig(SQLConnConfig config) { //IObjectContainer db = Db4oFactory.OpenFile(SQLConnConfig.configFilePath); IObjectContainer db = staticClass.db; try { IList <SQLConnConfig> list = db.Query <SQLConnConfig>(delegate(SQLConnConfig cf) { return(cf.dbType == config.dbType); } ); if (list.Count <= 0) { db.Store(config); } else { SQLConnConfig.copy(config, list[0]); db.Store(list[0]); } } finally { //db.Close(); } }
private void initialForm() { appConfig appconfig = appConfig.getDefaultConfig(); if (appconfig != null) { this.type = appconfig.dbType; } //DBType type = ConfigManager.GetCurrentDBType(); SQLConnConfig config = SQLConnConfig.getDefaultDBConfig(type); //type = config.dbType; if (type == DBType.sqlserver) { this.comboBox1.SelectedIndex = 0; } else if (type == DBType.sqlite) { this.comboBox1.SelectedIndex = 1; } //string connStr = ConfigManager.GetDBConnectString(type); if (config != null) { this.connectString = config.connectString; } this.txtConnString.Text = connectString; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { SQLConnConfig config = null; switch (this.comboBox1.SelectedIndex) { case 0: //ConfigManager.SaveCurrentDBType(DBType.sqlserver); config = SQLConnConfig.getDefaultDBConfig(DBType.sqlserver); if (config != null) { this.txtConnString.Text = config.connectString; } else { this.txtConnString.Text = string.Empty; } //this.txtConnString.Text = ConfigManager.GetDBConnectString(DBType.sqlserver); break; case 1: config = SQLConnConfig.getDefaultDBConfig(DBType.sqlite); if (config != null) { this.txtConnString.Text = config.connectString; } else { this.txtConnString.Text = string.Empty; } //ConfigManager.SaveCurrentDBType(DBType.sqlite); //this.txtConnString.Text = ConfigManager.GetDBConnectString(DBType.sqlite); break; } }
public static bool checkDBSetting() { if (staticClass.currentDbType == DBType.None) { appConfig appconfig = appConfig.getDefaultConfig(); if (appconfig != null) { staticClass.currentDbType = appconfig.dbType; SQLConnConfig config = SQLConnConfig.getDefaultDBConfig(staticClass.currentDbType); if (config != null) { staticClass.currentDBConnectString = config.connectString; } else { return(false); } } else { return(false); } } return(true); }
private void button1_Click(object sender, EventArgs e) { if (this.checkValidation() == false) { return; } if (SQLConnConfig.testConnection(type, this.txtConnString.Text)) { MessageBox.Show("连接测试成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("连接测试失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static string rtConnection() { if (connectString == string.Empty) { appConfig appconfig = appConfig.getDefaultConfig(); if (appconfig != null) { SQLConnConfig config = null; config = SQLConnConfig.getDefaultDBConfig(appconfig.dbType); if (config != null) { connectString = config.connectString; } } } return(connectString); }
private void button2_Click(object sender, EventArgs e) { if (this.checkValidation() == false) { return; } appConfig appConfig = new appConfig(this.type); appConfig.saveConfig(appConfig); SQLConnConfig config = new SQLConnConfig(this.type, this.connectString); SQLConnConfig.saveConfig(config); staticClass.currentDbType = this.type; staticClass.currentDBConnectString = this.connectString; this.Close(); //initialForm(); //switch (this.comboBox1.SelectedIndex) //{ // case 0: // if (ConfigManager.SaveDBConnectString(DBType.sqlserver, this.txtConnString.Text)) // { // MessageBox.Show("保存成功!"); // } // else // { // MessageBox.Show("保存失败!"); // } // break; // case 1: // if (ConfigManager.SaveDBConnectString(DBType.sqlite, this.txtConnString.Text)) // { // MessageBox.Show("保存成功!"); // } // else // { // MessageBox.Show("保存失败!"); // } // break; //} }
public static SQLConnConfig getDefaultDBConfig(DBType type) { SQLConnConfig config = null; // IObjectContainer db = Db4oFactory.OpenFile(SQLConnConfig.configFilePath); IObjectContainer db = staticClass.db; try { IList <SQLConnConfig> list = db.Query <SQLConnConfig>(delegate(SQLConnConfig cf) { return(cf.dbType == type); } ); if (list.Count > 0) { config = list[0]; } } finally { //db.Close(); } return(config); }
public static void copy(SQLConnConfig source, SQLConnConfig dest) { dest.configName = source.configName; dest.dbType = source.dbType; dest.connectString = source.connectString; }
public frmSQLConfig() { InitializeComponent(); mySQLConnectionTest = new SQLConnConfig(); }