public bool CheckLogin(string username, string password, int mode) { DataSet ds = new DataSet(); if (username == "" || password == "") { fault = new InfoFault(); fault.Type = "ArgumentException"; fault.Message = "Username and Password is not null"; throw new FaultException<InfoFault>(fault); } else { switch (mode) { case 0: { string query = "Select * From tbl_SinhVien Where MSSV = '" + username + "' And MatKhau = '" + password + "'"; try { connect.Open_Connect(); SqlDataAdapter adap = new SqlDataAdapter(query, connect.con); adap.Fill(ds); connect.Close_Connect(); if (ds.Tables[0].Rows.Count != 0) { return true; } else return false; } catch (Exception) { return false; } } case 1: { string query = "Select * From tbl_SinhVien Where MSSV = '" + username + "' And MatKhauGD = '" + password + "'"; try { connect.Open_Connect(); SqlDataAdapter adap = new SqlDataAdapter(query, connect.con); adap.Fill(ds); connect.Close_Connect(); if (ds.Tables[0].Rows.Count != 0) { return true; } else return false; } catch (Exception) { return false; } } case 2: { string query = "Select * From tbl_GiangVien Where MSGV = '" + username + "' And MatKhau = '" + password + "'"; try { connect.Open_Connect(); SqlDataAdapter adap = new SqlDataAdapter(query, connect.con); adap.Fill(ds); connect.Close_Connect(); if (ds.Tables[0].Rows.Count != 0) { return true; } else return false; } catch (Exception) { return false; } } default: { return false; } } } }
public bool Update_Info_Stu(Student Stu) { lstFault = new List<InfoFault>(); if (Stu.Diachi == "" || Stu.Dantoc == "" || Stu.Quoctich == "" || Stu.Tongiao == "") { fault = new InfoFault(); fault.Type = "Required Info"; fault.Message = "Yêu cầu nhập đầy đủ các thông bắt buộc (*): Địa chỉ, Quốc tịch, Dân tộc, Tôn giáo"; lstFault.Add(fault); } if (Stu.Dienthoai != "") { if (IsNumber(Stu.Dienthoai) == false) { fault = new InfoFault(); fault.Type = "Correctness"; fault.Message = "Số điện thoại phải là số"; lstFault.Add(fault); } else if (Stu.Dienthoai.Length < 8 || Stu.Dienthoai.Length > 12) { fault = new InfoFault(); fault.Type = "Correctness"; fault.Message = "Số điện thoại ít nhất 8 số, nhiều nhất 12 số"; lstFault.Add(fault); } } if (Stu.Email != "") { if (IsValidEmail(Stu.Email) == false) { fault = new InfoFault(); fault.Type = "Correctness"; fault.Message = "Email không đúng dạng"; lstFault.Add(fault); } } if (lstFault.Count != 0) throw new FaultException<InfoFault[]>(lstFault.ToArray()); else { connect.Open_Connect(); string query = "Update tbl_SinhVien" + " Set DiaChi = N'" + Stu.Diachi + "', DienThoai = '" + Stu.Dienthoai + "', Email = '" + Stu.Email + "', QuocTich = N'" + Stu.Quoctich + "', TonGiao = N'" + Stu.Tongiao + "', DanToc = N'" + Stu.Dantoc + "',HoTenCha = N'" + Stu.Hotencha + "', NgheNghiepCha = N'" + Stu.Nghenghiepcha + "', HoTenMe = N'" + Stu.Hotenme + "', NghenghiepMe = N'" + Stu.Nghenghiepme + "'" + " Where MSSV = '" + Stu.Mssv + "'"; SqlCommand cmd = new SqlCommand(query, connect.con); int roweff = cmd.ExecuteNonQuery(); connect.Close_Connect(); if (roweff != 0) { return true; } else return false; } }