Esempio n. 1
0
        //Click vào button Sign In
        private void buttonSignIn_Click(object sender, EventArgs e)
        {
            if (tBUPass.Text == "" || tBUName.Text == "" ||
                tBUName.Text == "Nhập tên tài khoản" || tBUPass.Text == "Nhập mật khẩu")     //check trường hợp sai cơ bản
            {
                MessageBox.Show("Có gì đó sai.");
                return;
            }
            else
            {
                if (controller.checkExistUsername(tBUName.Text) == false)   //check Username đã tồn tại chưa? để check Password
                {
                    MessageBox.Show("Tên tài khoản không tồn tại.");
                    return;
                }
                else if (controller.checkUser(tBUName.Text, tBUPass.Text) == true)  //check Username và Password đăng nhập đúng ko?
                {
                    int KEY = controller.GetUkey(tBUName.Text);
                    int n   = controller.getPosition(KEY.ToString());

                    if (n == 0)
                    {
                        FMain admin = new FMain(tBUName.Text, KEY, 0);
                        this.Hide();
                        admin.ShowDialog();
                        this.Show();
                    }
                    else
                    {
                        if (controller.getStatus(KEY.ToString()) == 0)
                        {
                            MessageBox.Show("Tài khoản của bạn đã bị chặn." +
                                            "\nNếu có bất kì thắc mắc nào vui lòng liên hệ Quản trị viên." +
                                            "\nHoặc liên hệ công ty qua: [email protected]");
                            return;
                        }
                        FMain f = new FMain(tBUName.Text, KEY, n);
                        this.Hide();
                        f.ShowDialog();
                        this.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Mật khẩu không đúng. Vui lòng thử lại!");    //thông báo Password sai
                }
            }
        }
        //Click button Lưu thay đổi trong groupbox Đổi Mật Khẩu
        private void BtSavePass_Click(object sender, EventArgs e)
        {
            Login_Controller account = new Login_Controller();

            if (tBCurPass.Text == "Nhập mật khẩu hiện tại" ||
                tBNewPass.Text == "Nhập mật khẩu mới" ||
                tBRePass.Text == "Xác nhận lại mật khẩu mới")
            {
                MessageBox.Show("Thông tin trống. Vui lòng nhập đầy đủ", "Thông báo");
                return;
            }
            if (tBNewPass.Text != tBRePass.Text)
            {
                MessageBox.Show("Mật khẩu xác nhận lại bị sai.", "Thông báo");
            }
            else
            {
                if (account.checkUser(MyAccount, tBCurPass.Text) == false)
                {
                    MessageBox.Show("Mật khẩu hiện tại sai.", "Thông báo");
                }
                else
                {
                    var window = MessageBox.Show("Bạn chắc chắn muốn thay đổi mật khẩu?", "Thoát Ứng Dụng", MessageBoxButtons.YesNo);
                    if (window == DialogResult.Yes)
                    {
                        controller.changeUserPass(tBCurPass.Text, tBNewPass.Text, MyAccount);
                        MessageBox.Show("Thay đổi mật khẩu thành công!", "Thông báo");
                        tBNewPass.Text = "";
                        tBNewPass_Leave(sender, e);
                        tBCurPass.Text = "";
                        tBCurPass_Leave(sender, e);
                        tBRePass.Text = "";
                        tBRePass_Leave(sender, e);
                    }
                }
            }
        }