protected override void BtnOK_Click(object sender, EventArgs e) { string strDBIP = Functions.FormatString(txtDBIP.Text); string strUserName = Functions.FormatString(txtUserName.Text); string strUserPassword = Functions.FormatString(txtUserPassword.Text); //地址 if (string.IsNullOrEmpty(strDBIP) || strDBIP.Equals("")) { txtDBIP.Focus(); CMessageBox.ShowError(string.Format("请输入数据库地址!"), Config.DialogTitle); return; } //名称 if (string.IsNullOrEmpty(strUserName) || strUserName.Equals("")) { txtUserName.Focus(); CMessageBox.ShowError(string.Format("请输入数据库用户名!"), Config.DialogTitle); return; } DBLinkTestForm objModal = new DBLinkTestForm(string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database=mysql;allow user variables=true", strDBIP, "3308", strUserName, strUserPassword, System.Text.Encoding.Default.HeaderName.ToString())); if (objModal.ShowDialog() == DialogResult.OK) { _DBSetting = new DBSetting() { DB_IP = strDBIP, DB_User = strUserName, DB_Password = strUserPassword }; this.DialogResult = DialogResult.OK; } else if (objModal.ShowDialog() == DialogResult.No) { CMessageBox.ShowError(string.Format("目的服务器配置错误,原因可能是数据库未安装或则用户名密码错误,请重新设置和排查!"), Config.DialogTitle); } else { Application.Exit(); } }
private void BtnCheckDBSetting_Click(object sender, EventArgs e) { DBSetting objDBSetting = GetSettingFromUI(); if (!CheckDBSettings(objDBSetting, out string strErrInfo)) { CMessageBox.ShowError(string.Format("数据库配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle); return; } DBLinkTestForm objModal = new DBLinkTestForm(string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDBSetting.DB_IP, "3308", objDBSetting.DB_User, objDBSetting.DB_Password, System.Text.Encoding.Default.HeaderName.ToString(), objDBSetting.DB_Name)); if (objModal.ShowDialog() == DialogResult.OK) { CMessageBox.ShowSucc(string.Format("恭喜您,数据库连接成功!"), Config.DialogTitle); } else if (objModal.ShowDialog() == DialogResult.No) { CMessageBox.ShowError(string.Format("对不起,数据库连接失败!请重新配置软件参数!"), Config.DialogTitle); File.Delete(RunVariable.IniPathAndFileName); } }