//Hàm check cái thành phần hợp lệ public String kiemTraSinhVien(SINHVIENDTO sv) { // Nội dung kiểm tra var validationContext = new ValidationContext(sv, null, null); // Danh sách chứa kết quả kiểm tra var validationResults = new List <ValidationResult>(); // Biến hợp lệ hay không var isValid = Validator.TryValidateObject(sv, validationContext, validationResults); // Nếu hợp lệ if (isValid == true) { return(null); } // Nếu không hợp lệ else { // Những lỗi không hợp lệ String result = String.Empty; foreach (var r in validationResults) { result += r.ErrorMessage; } // Trả về những giá trị không hợp lệ return(result); } }
public IEnumerable <SINHVIEN> TimSV(SINHVIENDTO sv) { // Hàm tìm sinh viên theo các điều kiện IEnumerable <SINHVIEN> result = _sv.TimSV(sv); return(result); }
public SINHVIEN chuyenDoiSVDTOThanhSV(SINHVIENDTO sv) { SINHVIEN result = new SINHVIEN(); result.DiaChi = sv.DiaChi; result.MaSV = sv.MaSV; result.NgaySinh = sv.NgaySinh; result.SoCMND = sv.SoCMND; result.SoDT = sv.SoDT; result.TenSV = sv.TenSV; return(result); }
public String SuaSV(SINHVIENDTO sv) { // Kiểm tra thông tin sửa sinh viên có hợp lệ không String check = kiemTraSinhVien(sv); // Không hợp lệ if (check != null) { return(check); } // Hợp lệ else { // Kiểm tra sinh viên muốn sửa có tồn tại không ???? SINHVIEN checkSVTonTai = _sv.TimSVTheoMaSV(sv.MaSV); // Không tồn tại if (checkSVTonTai == null) { return("Không tìm thấy thông tin cần sửa, xin vui lòng thử lại!"); } // Tồn tại else { // Sửa sinh viên SINHVIEN result = _sv.SuaSV(sv); // Kiểm tra kết quả của hàm sửa if (result == null) { return("Đã xảy ra lỗi trong quá trình sửa thông tin, xin vui lòng thử lại!"); } else { return(null); } } } }
//Hàm thêm sinh viên public String ThemSV(SINHVIENDTO sv) { // Kiểm tra mã sinh viên đã tồn tại chưa ? SINHVIEN kiemTraSVTonTai = _sv.TimSVTheoMaSV(sv.MaSV); // Nếu mã chưa tồn tại if (kiemTraSVTonTai == null) { // Kiểm tra sinh viên có hợp lệ không ? String check = kiemTraSinhVien(sv); // Không hợp lệ if (check != null) { return(check); } // Hợp lệ else { // Hàm thêm sinh viên SINHVIEN result = _sv.ThemSV(sv); // Kiếm tra kết quả của hàm thêm if (result != null) { return(null); } else { return("Đã xảy ra lỗi trong quá trình thêm sinh viên, xin vui lòng thử lại!"); } } } // Nếu mã đã tồn tại else { return("Mã sinh viên đã tồn tại!"); } }
public static SINHVIENDTO laySinhVien(string username, string password) { SINHVIENDTO svDTO = null; try { Connect_Helper cnn = new Connect_Helper(); cnn.OpenSection(); string query = string.Format(@"Select * FROM SINHVIEN Where MSSV = '{0}' AND PasswordHash = HASHBYTES('SHA2_512', '{1}'+CAST(Salt AS NVARCHAR(36)))" , username, password ); SqlCommand cmd = new SqlCommand(query, cnn.connect); SqlDataReader dr = null; dr = cmd.ExecuteReader(); while (dr.Read()) { svDTO = new SINHVIENDTO(); svDTO.MSSV = Convert.ToString(dr["MSSV"]); svDTO.TenSV = Convert.ToString(dr["TenSV"]); svDTO.STD = Convert.ToString(dr["SDT"]); } } catch (SqlException ex) { throw ex; } finally { } return(svDTO); }
private void button1_Click(object sender, EventArgs e) { if (this.attempt == 3) { MessageBox.Show("too many login failures So the Program terminated!"); Application.Exit(); } if (radioSV.Checked) { string mssv = txt_mssv.Text; string pwd = txt_pwd.Text; SINHVIENDTO svDTO = null; //svDTO = new SINHVIENDTO(); //svDTO.TenSV=SINHVIEN_BUS.LoginStyleStoreProcedure(mssv, pwd); svDTO = SINHVIEN_BUS.laySinhVien(mssv, pwd); if (svDTO == null) { this.attempt++; MessageBox.Show("INVALID LOGIN"); return; } //MessageBox.Show(svDTO.TenSV); else { //SINHVIEN rb = new SINHVIEN(); //this.Hide(); //rb.Show(); this.DN_StudentID = txt_mssv.Text; this.DN_StudentName = svDTO.TenSV; MessageBox.Show("Đăng nhập thành công " + this.DN_StudentID + " " + this.DN_StudentName); MAINFORM mfr = new MAINFORM(this.DN_StudentID, this.DN_StudentName); this.Hide(); mfr.Show(); } } else if (radioGV.Checked) { //lacking string mssv = txt_mssv.Text; string pwd = txt_pwd.Text; GIAOVIENDTO gvDTO = null; gvDTO = GIAOVIEN_BUS.LayGV(mssv, pwd); if (gvDTO == null) { this.attempt++; MessageBox.Show("INVALID LOGIN"); return; } //string tengv = GIAOVIEN_BUS.DangNhap(mssv, pwd); //if(tengv == "Incorrect Password") //{ // MessageBox.Show("Incorrect Password"); // return; //} //else if(tengv == "Invalid Login") //{ // MessageBox.Show("Invalid Login"); // return; //} //else if(tengv != "") //{ // this.DN_StudentName = tengv; // this.DN_StudentID = txt_mssv.Text; // MAINFORM mfr = new MAINFORM(this.DN_StudentID, this.DN_StudentName); // this.Hide(); // mfr.Show(); //} //else if (tengv == "") //{ // MessageBox.Show("CLGT"); // return; //} else { //SINHVIEN rb = new SINHVIEN(); //this.Hide(); //rb.Show(); this.DN_StudentID = txt_mssv.Text; this.DN_StudentName = gvDTO.TenGV; MessageBox.Show("Đăng nhập thành công " + this.DN_StudentID + " " + this.DN_StudentName); MAINFORM mfr = new MAINFORM(this.DN_StudentID, this.DN_StudentName); this.Hide(); mfr.Show(); } } else if (radioQTV.Checked) { if (this.attempt == 3) { MessageBox.Show("too many login failures So the Program terminated!"); Application.Exit(); } //lacking if (ADMIN_BUS.XacMinh(txt_mssv.Text, txt_pwd.Text)) { MessageBox.Show("HI ADMIN"); } else { this.attempt++; MessageBox.Show("INVALID LOGIN"); return; } } else { MessageBox.Show("Ban chua chon loai nguoi dung!"); return; } }