public bool XoaThongTinHocSinh(string MaHS) { string strDelete = "Delete from HocSinh where MaHS='" + MaHS + "'"; SqlParameter[] pars = new SqlParameter[6]; HocSinh objHocSinh = new HocSinh(); pars[0] = new SqlParameter("@Ho", SqlDbType.NChar, 20); pars[0].Value = objHocSinh.Ho; pars[1] = new SqlParameter("@Ten", SqlDbType.NChar, 20); pars[1].Value = objHocSinh.Ten; pars[2] = new SqlParameter("@MaHS", SqlDbType.NVarChar, 5); pars[2].Value = objHocSinh.MaHS; pars[3] = new SqlParameter("@MaLop", SqlDbType.NVarChar, 5); pars[3].Value = objHocSinh.MaLop; pars[4] = new SqlParameter("@NgaySinh", SqlDbType.Date); pars[4].Value = objHocSinh.NgaySinh; pars[5] = new SqlParameter("@GioiTinh", SqlDbType.NChar, 5); pars[5].Value = objHocSinh.GioiTinh; return(DataProvider.ThucHienChucNang(strDelete, pars)); }
public bool ThemMoiHocSinh(HocSinh objHocSinh) { string strInsert = "Insert into HocSinh(Ho,Ten,MaHS,MaLop,NgaySinh,GioiTinh) values(@Ho,@Ten,@MaHS,@MaLop,@NgaySinh,@GioiTinh)"; SqlParameter[] pars = new SqlParameter[6]; pars[0] = new SqlParameter("@Ho", SqlDbType.NChar, 20); pars[0].Value = objHocSinh.Ho; pars[1] = new SqlParameter("@Ten", SqlDbType.NChar, 20); pars[1].Value = objHocSinh.Ten; pars[2] = new SqlParameter("@MaHS", SqlDbType.NVarChar, 5); pars[2].Value = objHocSinh.MaHS; pars[3] = new SqlParameter("@MaLop", SqlDbType.NChar, 10); pars[3].Value = objHocSinh.MaLop; pars[4] = new SqlParameter("@NgaySinh", SqlDbType.Date); pars[4].Value = objHocSinh.NgaySinh; pars[5] = new SqlParameter("@GioiTinh", SqlDbType.NChar, 10); pars[5].Value = objHocSinh.GioiTinh; return(DataProvider.ThucHienChucNang(strInsert, pars)); }
public bool CapNhatThongTinHS(HocSinh objHocSinh) { string strUpdate = "Update HocSinh set Ho=@Ho,Ten=@Ten,MaHS=@MaHS,MaLop=@MaLop,NgaySinh=@NgaySinh,GioiTinh=@GioiTinh"; SqlParameter[] pars = new SqlParameter[6]; pars[0] = new SqlParameter("@Ho", SqlDbType.NChar, 20); pars[0].Value = objHocSinh.Ho; pars[1] = new SqlParameter("@Ten", SqlDbType.NChar, 20); pars[1].Value = objHocSinh.Ten; pars[2] = new SqlParameter("@MaHS", SqlDbType.NVarChar, 5); pars[2].Value = objHocSinh.MaHS; pars[3] = new SqlParameter("@MaLop", SqlDbType.NVarChar, 5); pars[3].Value = objHocSinh.MaLop; pars[4] = new SqlParameter("@NgaySinh", SqlDbType.Date); pars[4].Value = objHocSinh.NgaySinh; pars[5] = new SqlParameter("@GioiTinh", SqlDbType.NChar, 5); pars[5].Value = objHocSinh.GioiTinh; return(DataProvider.ThucHienChucNang(strUpdate, pars));; }
private void btnThucHien_Click(object sender, EventArgs e) { bool Insert = true; HocSinh objHocSinh = new HocSinh(); if (!string.IsNullOrEmpty(MaHS)) { Insert = false; } objHocSinh.Ho = txtHo.Text; objHocSinh.Ten = txtTen.Text; objHocSinh.MaHS = txtMaHS.Text; objHocSinh.NgaySinh = dtNgaySinh.Value; objHocSinh.MaLop = txtMaLop.Text; string GioiTinh = "" + cbGioiTinh.SelectedItem; objHocSinh.GioiTinh = GioiTinh; bool ketQua = false; if (Insert) { ketQua = DataProvider.lstDanhSach.ThemMoiHocSinh(objHocSinh); } else { ketQua = DataProvider.lstDanhSach.CapNhatThongTinHS(objHocSinh); } if (ketQua) { MessageBox.Show("Thực hiện thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); this.Close(); } }
private void HienThiThongTinHocSinh() { LuuTruDanhSach service = new LuuTruDanhSach(); HocSinh objHocSinh = service.HienThiThongTinHocSinhTheoMaHS(MaHS); if (objHocSinh != null) { txtHo.Text = objHocSinh.Ho; txtTen.Text = objHocSinh.Ten; txtMaHS.Text = objHocSinh.MaHS; txtMaLop.Text = objHocSinh.MaLop; dtNgaySinh.Value = objHocSinh.NgaySinh; cbGioiTinh.SelectedValue = objHocSinh.GioiTinh; } }
public HocSinh HienThiThongTinHocSinhTheoMaHS(string MaHS) { string str = "Select * from HocSinh where MaHS='" + MaHS + "'"; HocSinh objHocSinh = null; DataTable dt = DataProvider.LayDanhSach(str); if (dt.Rows.Count > 0) { objHocSinh = new HocSinh(); objHocSinh.Ho = "" + dt.Rows[0]["Ho"]; objHocSinh.Ten = "" + dt.Rows[0]["Ten"]; objHocSinh.MaHS = "" + dt.Rows[0]["MaHS"]; DateTime ngay = DateTime.Today; DateTime.TryParse("" + dt.Rows[0]["NgaySinh"], out ngay); objHocSinh.NgaySinh = ngay; objHocSinh.GioiTinh = "" + dt.Rows[0]["GioiTinh"]; objHocSinh.MaLop = "" + dt.Rows[0]["MaLop"]; } return(objHocSinh); }