public static int ThemPhongBan(PhongBan phongBan) { using (var context = new VeTauEntities(false)) { context.PhongBans.Add(phongBan); return context.SaveChanges(); } }
public static int CapNhatPhongBan(PhongBan phongBan) { using (var context = new VeTauEntities(false)) { var doiTuong = context.PhongBans.SingleOrDefault(pb => pb.Id == phongBan.Id); if (doiTuong != null) { doiTuong.TenPhongBan = phongBan.TenPhongBan; doiTuong.RuleBaoCao = phongBan.RuleBaoCao; doiTuong.RuleChuyenTau = phongBan.RuleChuyenTau; doiTuong.RuleLichTrinh = phongBan.RuleLichTrinh; doiTuong.RuleNhanSu = phongBan.RuleNhanSu; doiTuong.RuletBanVe = phongBan.RuletBanVe; doiTuong.RuleQuanTri = phongBan.RuleQuanTri; } return context.SaveChanges(); } }
private void btnThem_Click(object sender, EventArgs e) { if (KiemTraHopLeVaThongBao()) { var phongBan = new PhongBan { Id = tbMaPhongBan.Text.ToUpper(), TenPhongBan = tbTenPhongBan.Text }; if (PhongBanDal.ThemPhongBan(phongBan)>0) { MessageBox.Show(Resources.TaoDoiTuong +Resources.thanhCong, Resources.MThanhCong); CapNhatGvPhongBan(); } else { MessageBox.Show(Resources.TaoDoiTuong +Resources.thatBai, Resources.MThatBai); } } }