private void btnThemmoi_Click(object sender, EventArgs e) { if (txtMaSV.Text.Trim() == "") { MessageBox.Show("Chưa nhập mã sinh viên", "Thông báo"); } else { if (context.tblSINH_VIEN.Find(txtMaSV.Text.Trim()) != null) { MessageBox.Show("Mã sinh viên đã tồn tại ", "Thông báo"); } else { SINHVIENF f = new SINHVIENF(); tblSINH_VIEN g = new tblSINH_VIEN(); g.MaSv = txtMaSV.Text; g.HoTen = txtHoTen.Text; g.NgaySinh = dateNgaysinh.Value.ToString(); g.DiaChi = txtDiaChi.Text; g.GioiTinh = cboGioiTinh.Text; g.MaLop = cboMalop.Text; f.Insert(g); dgrDSSV.DataSource = context.tblSINH_VIEN.ToList(); txtMaSV.Clear(); txtHoTen.Clear(); txtDiaChi.Clear(); dateNgaysinh.Text = ""; cboGioiTinh.Text = ""; cboMalop.Text = ""; } } }
public bool Delete(tblSINH_VIEN model) { tblSINH_VIEN dbEntry = context.tblSINH_VIEN.Find(model.MaSv); if (dbEntry == null) { return(false); } context.tblSINH_VIEN.Remove(dbEntry); context.SaveChanges(); return(true); }
public bool Insert(tblSINH_VIEN model) { tblSINH_VIEN dbEntry = context.tblSINH_VIEN.Find(model.MaSv); if (dbEntry != null) { return(false); } context.tblSINH_VIEN.Add(model); context.SaveChanges(); return(true); }
private void btnXoa_Click(object sender, EventArgs e) { string id = txtMaSV.Text.Trim(); if (MessageBox.Show(string.Format("Xóa sinh viên có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { tblSINH_VIEN g = new tblSINH_VIEN(); g.MaSv = txtMaSV.Text; SINHVIENF f = new SINHVIENF(); f.Delete(g); context = new HSGVDbContext(); dgrDSSV.DataSource = context.tblSINH_VIEN.ToList(); } }
public bool Update(tblSINH_VIEN model) { tblSINH_VIEN dbEntry = context.tblSINH_VIEN.Find(model.MaSv); if (dbEntry == null) { return(false); } dbEntry.MaSv = model.MaSv; dbEntry.HoTen = model.HoTen; dbEntry.GioiTinh = model.GioiTinh; dbEntry.NgaySinh = model.NgaySinh; dbEntry.DiaChi = model.DiaChi; dbEntry.MaLop = model.MaLop; context.SaveChanges(); return(true); }
private void btnSua_Click(object sender, EventArgs e) { string id = txtMaSV.Text.Trim(); if (MessageBox.Show(string.Format("Sửa sinh viên có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { tblSINH_VIEN g = new tblSINH_VIEN(); g.MaSv = txtMaSV.Text; g.HoTen = txtHoTen.Text; g.NgaySinh = dateNgaysinh.Text; g.DiaChi = txtDiaChi.Text; g.GioiTinh = cboGioiTinh.Text; g.MaLop = cboMalop.Text; SINHVIENF f = new SINHVIENF(); f.Update(g); context = new HSGVDbContext(); dgrDSSV.DataSource = context.tblSINH_VIEN.ToList(); } }
public tblSINH_VIEN FindEntity(string ID) { tblSINH_VIEN dbEntry = context.tblSINH_VIEN.Find(ID); return(dbEntry); }