void Nhap() { if (SignIn(txtbTenDN.Text, txtMK.Text) == "Hãy nhập đủ tên đăng nhập và mật khẩu!") { MessageBox.Show("Hãy nhập đủ tên đăng nhập và mật khẩu", "Thông báo"); txtbTenDN.Focus(); txtMK.Focus(); } else { KiemTra k = new KiemTra(); if (k.Check(txtbTenDN.Text, txtMK.Text) == 1) { //this.Hide(); //FrmMain f = new FrmMain(); //f.ShowDialog(); //this.Close(); } else { MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng. Hãy nhập lại!", "Lỗi!"); } } }
void Nhap() { errorProvider1.Clear(); if (txtUser.Text == "") { errorProvider1.SetError(txtUser, "Nhập tên người dùng!"); } if (txtPass.Text == "") { errorProvider1.SetError(txtPass, "Nhập mật khẩu!"); } if (txtConf.Text == "") { errorProvider1.SetError(txtConf, "Xác nhận lại mật khẩu!"); } else if (txtPass.Text.Length < 5) { errorProvider1.SetError(txtPass, "Sử dụng 5 kí tự trở lên cho mật khẩu!"); txtConf.Clear(); txtPass.Focus(); } else if (txtPass.Text.Length > 50) { errorProvider1.SetError(txtPass, "Sử dụng 50 kí tự trở xuống cho mật khẩu!"); } else if (txtPass.Text != txtConf.Text) { txtConf.Clear(); txtConf.Focus(); errorProvider1.SetError(txtConf, "Xác nhận mật khẩu không đúng. Hãy nhập lại!"); } else { errorProvider1.Clear(); KiemTra k = new KiemTra(); if (k.Check(txtUser.Text, txtPass.Text) == 1) { MessageBox.Show("Đã tồn tại. Hãy tạo tài khoản khác!"); txtUser.Clear(); txtPass.Clear(); txtConf.Clear(); txtUser.Focus(); } else if (k.Check(txtUser.Text, txtPass.Text) == 0) { con.Open(); //mở kết nối var cmd = new SqlCommand("INSERT INTO TaoTaiKhoan(TenNguoiDung,MatKhau) VALUES((N'" + txtUser.Text + "'),('" + txtPass.Text + "'))", con); //lấy dữ liệu từ textbox để lưu cmd.ExecuteNonQuery(); //thực thi lệnh con.Close(); //đóng kết nôi DialogResult r = MessageBox.Show("Đã tạo tài khoản thành công. Hãy đăng nhập vào hệ thống!", "Thông báo", MessageBoxButtons.OK); if (r == DialogResult.OK) { this.Hide(); DangNhap n = new DangNhap(); n.ShowDialog(); this.Close(); } } } }