private void btn_OK_Click(object sender, EventArgs e) { if (uc == null) { return; } if (String.IsNullOrEmpty(txt_DBCode.Text)) { txt_DBCode.ErrorText = "数据库别名不能为空!"; return; } var db = uc.DoConfig(); if (db == null) { return; } //MessageBox.Show(db.GetConnectionStr()); INIDBConfig i = new INIDBConfig(); i.SetDBCode(txt_DBCode.Text); i.SetConnStr(db.GetConnectionStr()); i.SetProviderName(db.ProviderName); this.DialogResult = DialogResult.OK; this.Close(); }
bool LoadSysConfig() { INIDBConfig i = new INIDBConfig(); string DBCode = i.GetDBCode(); string ConnnectionString = i.GetConnStr(); string ProviderName = i.GetProviderName(); var validate = DatabaseFactory.Validate(ConnnectionString, ProviderName); if (validate == true) { Loginer.CurrentLoginer.SystemDBCode = DBCode; System_DBCode = DBCode; System_Model.ConnnectionString = ConnnectionString; System_Model.ProviderName = ProviderName; } return(validate); }
private void btn_OK_Click(object sender, EventArgs e) { if (uc == null) { return; } if (String.IsNullOrEmpty(txt_DBCode.Text)) { txt_DBCode.ErrorText = "数据库别名不能为空!"; return; } if (String.IsNullOrEmpty(txt_DBText.Text)) { txt_DBText.ErrorText = "数据库名不能为空!"; return; } //判断编号是否存在 if (ConvertLib.ToString(txt_DBCode.EditValue) != "") { if (bll.DBCodeExists(txt_DBCode.EditValue.ToString()) == true) { txt_DBCode.ErrorText = "数据库编号已经存在!"; return; } } var db = uc.DoConfig(); if (db == null) { return; } INIDBConfig i = new INIDBConfig(); string ProviderName = db.ProviderName; string ConStr = db.GetConnectionStr(); //string ConnStr = Encrypt.DESEncrypt(db.GetConnectionStr(), Globals.KeyConnectionStr); var fac = System.Data.Common.DbProviderFactories.GetFactory(ProviderName); using (var conn = fac.CreateConnection()) { conn.ConnectionString = ConStr; conn.Open(); DataTable dt = bll.GetTableStruct(sys_DataBaseList._TableName); DataRow row = dt.Rows.Add(); row[sys_DataBaseList.DBCode] = txt_DBCode.EditValue; row[sys_DataBaseList.DBDisplayText] = txt_DBText.EditValue; row[sys_DataBaseList.DBProviderName] = ProviderName; row[sys_DataBaseList.DBServer] = conn.DataSource; row[sys_DataBaseList.DBName] = conn.Database; row[sys_DataBaseList.DBConnection] = Encrypt.DESEncrypt(ConStr, Globals.KeyConnectionStr); bll.Update(dt); Data = dt; conn.Close(); } this.DialogResult = DialogResult.OK; this.Close(); }