Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var db = new FormDbService.DbInfo();
                db.Id       = Convert.ToInt32(txtId.Text);
                db.Server   = TxtSqlServer.Text;
                db.UserName = TxtSqlUserName.Text;
                db.Password = TxtSqlPwd.Text;
                db.Database = TxtSqlDataBase.Text;
                if (db.Server.Length == 0 ||
                    db.UserName.Length == 0 ||
                    db.Password.Length == 0 ||
                    db.Database.Length == 0)
                {
                    MessageBox.Show("抱歉,以上所有项均不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                btnSave.Enabled = false;
                string connection = GetConnectionString();
                var    thread     = new Thread(() =>
                {
                    UpdateUI(() => { lblStatus.Text = "测试连接中,请稍后..."; });
                    if (CheckConnection(connection))
                    {
                        FormDbService.EditDb(db);
                        UpdateUI(() =>
                        {
                            lblStatus.Text  = "";
                            btnSave.Enabled = true;
                            MessageBox.Show("操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        });
                    }
                    else
                    {
                        UpdateUI(() =>
                        {
                            lblStatus.Text  = "";
                            btnSave.Enabled = true;
                            MessageBox.Show("抱歉,数据库连接失败,数据未保存\n请检查配置参数准确性后再试!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        });
                        return;
                    }

                    UpdateUI(() =>
                    {
                        btnSave.Enabled = true;
                        Bind();
                    });
                });
                thread.IsBackground = true;
                thread.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("操作异常:" + ex, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 2
0
        private void InitAdd()
        {
            var db = new FormDbService.DbInfo();

            txtId.Text          = db.Id.ToString();
            TxtSqlServer.Text   = db.Server;
            TxtSqlDataBase.Text = db.Database;
            TxtSqlUserName.Text = db.UserName;
            TxtSqlPwd.Text      = db.Password;
            btnDel.Enabled      = false;
        }