public SinhVienBDO GetSinhVienByID(string id) { SinhVienBDO SinhVien = new SinhVienBDO(); using (SqlConnection connection = new SqlConnection(ConnectionInformation.ConnectionString)) { using (SqlCommand command = new SqlCommand("spGetSinhVien", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Masv", id); connection.Open(); SqlDataAdapter SinhVienAdapter = new SqlDataAdapter(); DataTable SinhVienTable = new DataTable(); SinhVienAdapter.SelectCommand = command; SinhVienAdapter.Fill(SinhVienTable); if (SinhVienTable.Rows.Count > 0) { SinhVien.MaSV = (string)SinhVienTable.Rows[0]["Masv"]; SinhVien.HoSV = (string)SinhVienTable.Rows[0]["Hosv"]; SinhVien.TenSV = (string)SinhVienTable.Rows[0]["tensv"]; SinhVien.GioiTinh = (bool)SinhVienTable.Rows[0]["phai"]; SinhVien.NgaySinh = (DateTime)SinhVienTable.Rows[0]["ngaysinh"]; SinhVien.NoiSinh = (string)SinhVienTable.Rows[0]["noisinh"]; SinhVien.MaKhoa = (string)SinhVienTable.Rows[0]["Makhoa"]; SinhVien.HocBong = (int)SinhVienTable.Rows[0]["Hocbong"]; } } } return(SinhVien); }
public List <SinhVienBDO> GetAllSinhVien() { List <SinhVienBDO> ListSinhVien = new List <SinhVienBDO>(); using (SqlConnection connection = new SqlConnection(ConnectionInformation.ConnectionString)) { using (SqlCommand command = new SqlCommand("spGetSinhVien", connection)) { command.CommandType = CommandType.StoredProcedure; connection.Open(); SqlDataAdapter SinhVienAdapter = new SqlDataAdapter(); DataTable SinhVienTable = new DataTable(); SinhVienAdapter.SelectCommand = command; SinhVienAdapter.Fill(SinhVienTable); if (SinhVienTable.Rows.Count > 0) { for (int i = 0; i < SinhVienTable.Rows.Count; i++) { SinhVienBDO SinhVien = new SinhVienBDO(); SinhVien.MaSV = (string)SinhVienTable.Rows[i]["Masv"]; SinhVien.HoSV = (string)SinhVienTable.Rows[i]["Hosv"]; SinhVien.TenSV = (string)SinhVienTable.Rows[i]["tensv"]; SinhVien.GioiTinh = (bool)SinhVienTable.Rows[i]["phai"]; SinhVien.NgaySinh = (DateTime)SinhVienTable.Rows[i]["ngaysinh"]; SinhVien.NoiSinh = (string)SinhVienTable.Rows[i]["noisinh"]; SinhVien.MaKhoa = (string)SinhVienTable.Rows[i]["Makhoa"]; SinhVien.HocBong = (int)SinhVienTable.Rows[i]["Hocbong"]; ListSinhVien.Add(SinhVien); } } } } return(ListSinhVien); }
public bool Update(SinhVienBDO sv) { if (sv != null) { if (sv.MaSV != null && sv.MaKhoa != null) { sinhvienDAL.Update(sv); return(true); } } return(false); }
public bool Update(SinhVienBDO sv) { try { sinhvienBUS.Update(sv); return(true); } catch (FaultException) { throw; } }
static void Main(string[] args) { SinhVienServiceClient client = new SinhVienServiceClient(); SinhVienBDO SinhVien = client.GetSinhVien("A01"); List <SinhVienBDO> ListSinhVien = client.GetAllSinhVien().ToList(); Console.WriteLine("\n---Test GetSinhVienByID(A01)---\n"); Console.WriteLine(SinhVien.MaSV + " " + SinhVien.HoSV + " " + SinhVien.TenSV + " " + SinhVien.MaKhoa + " " + SinhVien.GioiTinh + " " + SinhVien.NgaySinh + " " + SinhVien.NoiSinh + " " + SinhVien.HocBong + "\n"); Console.WriteLine("\n\n---Test GetAllSinhVien()---\n"); for (int i = 0; i < ListSinhVien.Capacity; i++) { Console.WriteLine(ListSinhVien[i].MaSV + " " + ListSinhVien[i].HoSV + " " + ListSinhVien[i].TenSV + " " + ListSinhVien[i].MaKhoa + " " + ListSinhVien[i].GioiTinh + " " + ListSinhVien[i].NgaySinh + " " + ListSinhVien[i].NoiSinh + " " + ListSinhVien[i].HocBong + "\n"); } Console.ReadLine(); }
public bool Delete(string MaSV) { if (MaSV != null && MaSV != String.Empty) { SinhVienBDO sv = new SinhVienBDO(); sv.MaSV = MaSV; sv.HoSV = ""; sv.TenSV = ""; sv.GioiTinh = true; //demo nen de dai gia tri sv.NgaySinh = DateTime.Now; //demo nen cho dai gia tri sv.NoiSinh = ""; sv.MaKhoa = ""; //Theo khoa ngoai thi cho nay khong null nhung ma day la demo nen khong check ki~. sv.HocBong = 1; //demo nen cho dai gia tri. sinhvienDAL.Delete(sv); return(true); } return(false); }
public int Delete(SinhVienBDO sv) { using (SqlConnection connection = new SqlConnection(ConnectionInformation.ConnectionString)) { using (SqlCommand command = new SqlCommand("spEditSinhVien", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@StatementType", ConnectionInformation.Delete); command.Parameters.AddWithValue("@Masv", sv.MaSV); command.Parameters.AddWithValue("@Hosv", sv.HoSV); command.Parameters.AddWithValue("@tensv", sv.TenSV); command.Parameters.AddWithValue("@phai", sv.GioiTinh); command.Parameters.AddWithValue("@ngaysinh", sv.NgaySinh); command.Parameters.AddWithValue("@noisinh", sv.NoiSinh); command.Parameters.AddWithValue("@MaKhoa", sv.MaKhoa); command.Parameters.AddWithValue("@Hocbong", sv.HocBong); connection.Open(); return(command.ExecuteNonQuery()); } } }