private void btnSelectDB_Click(object sender, EventArgs e) { if (m_ServerDB == null || m_ServerDB.Rows.Count == 0) { m_ServerDB = DataBaseManager.GetDataBase(dbType, BuildConn(this.dbType)); } FrmSelectDataBases frmSelectDb = new FrmSelectDataBases(m_ServerDB); if (frmSelectDb.ShowDialog() == DialogResult.OK) { LoadDatabase = frmSelectDb.LoadDataBase; foreach (DataRow dr in LoadDatabase.Rows) { txtDB.Text += dr[0] + @","; } txtDB.Text = txtDB.Text.TrimEnd(','); } }
/// <summary>连接 /// 连接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { if (!CheckInput()) { return; } #if !DEBUG if (txtDB.Text.Trim() == string.Empty) { m_ServerDB = DataBaseManager.GetDataBase(dbType, BuildConn(this.dbType)); if (m_ServerDB.Rows.Count > 5) { dialog = MessageBox.Show(@"一共需要加载【" + m_ServerDB.Rows.Count + "】个数据库,需要时间较长,建议按需加载", "提示", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { btnSelectDB_Click(null, null); return; } } } #endif #if DEBUG LoadDatabase = new DataTable(); LoadDatabase.Columns.Add("name", typeof(string)); DataRow dr = LoadDatabase.NewRow(); dr["name"] = GlobalHelp.DefauleDatabase; LoadDatabase.Rows.Add(dr); #endif bool flag = TestConn(this.dbType); if (flag) { if (chkRem.Checked) { DataSet ds = m_dalConn.GetList("IP='" + cboServer.Text.Trim() + "'"); if (ds.Tables[0].Rows.Count > 0) { m_dalConn.DeleteByCond("IP='" + cboServer.Text.Trim() + "'"); } DbConnect model = new DbConnect { IP = cboServer.Text.Trim(), Pwd = DESEncryptHelper.Encrypt(txtPassword.Text.Trim(), "test332211"), User = cboUser.Text.Trim(), Remark = this.dbType.ToString(), CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; m_dalConn.Add(model); } DBConn = BuildConn(this.dbType); Server = cboServer.Text.Trim(); UID = cboUser.Text.Trim(); PWD = txtPassword.Text.Trim(); if (this.dbType == SqlType.MySql) { Port = cboLogin.Text.Trim(); } List <string> lstLoadType = new List <string>(); foreach (CCBoxItem item in chkAllowType.CheckedItems) { lstLoadType.Add(item.Name); } LoadType = lstLoadType; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"连接失败"); } }