Ejemplo n.º 1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var user = dataGridView1.Rows[e.RowIndex].DataBoundItem as TB_User;

            if (e.ColumnIndex < 0 || dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
            {
                return;
            }
            string buttonText = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

            HandleData(() =>
            {
                switch (buttonText)
                {
                case "重置密码":
                    var succeed = BLLOperate.ModifyPassword(user.Id, "1");
                    MessageBox.Show(this, succeed ? "重置成功!" : "重置失败");
                    break;

                case "删除用户":
                    var id = BLLOperate.DeleteItem <TB_User>(user.Id);
                    MessageBox.Show(this, id > 0 ? "删除成功!" : "删除失败");
                    LoadUsers();
                    break;
                }
            }, s => MessageBox.Show(this, s));
        }
Ejemplo n.º 2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            var oldPassword    = txtOldPassword.Text;
            var newPassword    = txtNewPassword.Text;
            var affirmPassword = txtAffirmPassword.Text;

            if (VerifyRequired(txtOldPassword, lbMessage, "旧密码") ||
                VerifyRequired(txtNewPassword, lbMessage, "新密码") ||
                VerifyStringLength(txtNewPassword, 16, lbMessage, "新密码"))
            {
                return;
            }
            if (oldPassword.Trim() != GlobalData.Current.CurrentUser.Password)
            {
                lbMessage.ForeColor = Color.Red;
                lbMessage.Text      = "旧密码不匹配";
                txtOldPassword.Focus();
                return;
            }
            if (oldPassword == newPassword)
            {
                lbMessage.ForeColor = Color.Red;
                lbMessage.Text      = "新密码不能与旧密码相同";
                txtNewPassword.Focus();
                return;
            }
            if (affirmPassword != newPassword)
            {
                lbMessage.ForeColor = Color.Red;
                lbMessage.Text      = "确认密码与新密码不符";
                txtAffirmPassword.Focus();
                return;
            }
            HandleData(() =>
            {
                var succeed = BLLOperate.ModifyPassword(GlobalData.Current.CurrentUser.Id, newPassword);
                if (succeed)
                {
                    GlobalData.Current.CurrentUser.Password = newPassword;
                    MessageBox.Show(this, "修改成功!");
                    Close();
                }
                else
                {
                    lbMessage.ForeColor = Color.Red;
                    lbMessage.Text      = "修改失败";
                }
            }, s =>
            {
                lbMessage.ForeColor = Color.Red;
                lbMessage.Text      = "修改失败";
            });
        }