private void btnXoaBM_Click(object sender, EventArgs e) { if (btnXoaBM.Enabled == true) { DialogResult r = MessageBox.Show(null, "Bạn có chắc xóa bộ môn " + txtTenBM.Text + " không!", "Cân nhắc", MessageBoxButtons.YesNo); if (r == DialogResult.Yes) { XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities(); BoMon bmdel = new BoMon(); bmdel.MaBM = Int32.Parse(txtMaBM.Text); et.Entry(bmdel).State = EntityState.Deleted; et.SaveChanges(); MessageBox.Show("Đã xóa!"); QLBoMon_Load(sender, e); } } }
private void btnReload_Click(object sender, EventArgs e) { if (k == 1) { try { if (t == 1) { XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities(); BoMon b = new BoMon(); b.MaBM = Int32.Parse(txtMaBM.Text); b.TenBM = txtTenBM.Text; et.Entry(b).State = EntityState.Added; et.SaveChanges(); MessageBox.Show("Thêm thành công!"); } else { XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities(); BoMon bnew = new BoMon(); bnew.MaBM = Int32.Parse(txtMaBM.Text); bnew.TenBM = txtTenBM.Text; et.Entry(bnew).State = EntityState.Modified; et.SaveChanges(); MessageBox.Show("Sửa thành công!"); } QLBoMon_Load(sender, e); } catch (Exception ex) { MessageBox.Show("Lỗi " + ex.Message); } } else { QLBoMon_Load(sender, e); } }