Exemplo n.º 1
0
        //保存连接-1:修改配置文件信息;2、存入日志 数据库历史信息中
        private void btn_Save_Click(object sender, EventArgs e)
        {
            ConfDataBaseInfo info = new ConfDataBaseInfo();

            if (comboBox_DB.Text == "")
            {
                MessageBox.Show("请选择数据库名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            info.IP         = txt_IP.Text;
            info.User       = txt_UserName.Text;
            info.Password   = txt_Password.Text;
            info.ServerName = comboBox_DB.Text;

            if (config.UpdateDBInfo(info, out string errMsg))
            {
                if (config.SaveDBInfo(info, out errMsg))
                {
                    MessageBox.Show("保存连接成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ReadDBHistory();
                }
                else
                {
                    MessageBox.Show("保存连接历史信息失败!," + errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("保存连接信息失败!," + errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        //快速切换数据库配置 / 删除
        private void DGV_History_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            ConfDataBaseInfo info = new ConfDataBaseInfo();
            int curIndex          = e.RowIndex;

            DGV_History.Rows[curIndex].Selected = true;
            info.IP         = Convert.ToString(DGV_History.Rows[curIndex].Cells["HostName"].Value);
            info.ServerName = Convert.ToString(DGV_History.Rows[curIndex].Cells["DBName"].Value);
            info.User       = Convert.ToString(DGV_History.Rows[curIndex].Cells["UserName"].Value);
            info.Password   = Convert.ToString(DGV_History.Rows[curIndex].Cells["PassWord"].Value);

            txt_IP.Text       = info.IP;
            txt_UserName.Text = info.User;
            txt_Password.Text = info.Password;
            comboBox_DB.Text  = info.ServerName;

            if (e.ColumnIndex == 6)
            {
                if (config.DeleteSignleDBHistory(info, out string errMsg))
                {
                    MessageBox.Show("清除历史成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DGV_History.Rows.RemoveAt(curIndex);
                }
                else
                {
                    MessageBox.Show("清除历史失败!," + errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 3
0
        //数据库下拉列表
        private void comboBox_DB_DropDown(object sender, EventArgs e)
        {
            ConfDataBaseInfo info = new ConfDataBaseInfo();

            if (string.IsNullOrWhiteSpace(txt_IP.Text))
            {
                MessageBox.Show("请输入服务器名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(txt_UserName.Text))
            {
                MessageBox.Show("请输入登录名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(txt_Password.Text))
            {
                MessageBox.Show("请输入密码!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            info.IP       = txt_IP.Text;
            info.User     = txt_UserName.Text;
            info.Password = txt_Password.Text;

            List <string> list = config.GetDBList(info, out string errMsg);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                MessageBox.Show("获取数据库列表失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                comboBox_DB.Items.Clear();
                foreach (string name in list)
                {
                    comboBox_DB.Items.Add(name);
                }
                comboBox_DB.SelectedItem = Config.envConfigInfo.confProjectInfo.ServerName;
            }
        }
Exemplo n.º 4
0
        //测试连接
        private void btn_Test_Click(object sender, EventArgs e)
        {
            ConfDataBaseInfo info = new ConfDataBaseInfo();

            if (comboBox_DB.Text == "")
            {
                MessageBox.Show("请选择数据库名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            info.IP         = txt_IP.Text;
            info.User       = txt_UserName.Text;
            info.Password   = txt_Password.Text;
            info.ServerName = comboBox_DB.Text;

            if (config.CheckDBConnect(info, out string errMsg))
            {
                MessageBox.Show("测试连接成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("测试连接失败!," + errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }