// hàm xóa public void delete(NhomNV nhom) { NhomNV ph = db.NhomNVs.Find(nhom.NhomNVId); // ph.Phones.ToList().ForEach(phone => db.Phones.Remove(phone)); db.NhomNVs.Remove(ph); db.SaveChanges(); }
//ham sửa public void Update(NhomNV nhom) { NhomNV ph = db.NhomNVs.SingleOrDefault(x => x.NhomNVId == nhom.NhomNVId); ph.TenNhom = nhom.TenNhom; ph.CongViecId = nhom.CongViecId; ph.TrNhomId = nhom.TrNhomId; db.SaveChanges(); }
//hàm thêm public void insert(NhomNV nhom) { NhomNV ph = new NhomNV(); ph.TenNhom = nhom.TenNhom; ph.CongViecId = nhom.CongViecId; ph.TrNhomId = nhom.TrNhomId; db.NhomNVs.Add(ph); db.SaveChanges(); }
private void btnDelete_Click(object sender, EventArgs e) { // Delete DialogResult dr = MessageBox.Show("Bạn có chắc muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { //khởi tạo đối tượng nhân viên NhomNV nv = new NhomNV(); //lấy mã nhân viên từ gridView1 của devexpress, lưu ý các bạn nhớ viết name của trường cần lấy phải đúng như //trong csdl nhé nv.NhomNVId = int.Parse(txtNhomNVId.Text); //thực hienj hàm xóa new NhomNVModel().delete(nv); MessageBox.Show("Thành Công"); //grcNhomNV.RefreshDataSource(); NhomNVForm_Load(sender, e); } }
private void btnSave_Click(object sender, EventArgs e) { NhomNV nv = new NhomNV(); nv.TenNhom = txtTenNhom.Text; if (cmbTrNhomId.SelectedValue != null) { nv.TrNhomId = int.Parse(cmbTrNhomId.SelectedValue.ToString()); } if (cmbCVId.SelectedValue != null) { nv.CongViecId = int.Parse(cmbCVId.SelectedValue.ToString()); } new NhomNVModel().insert(nv); MessageBox.Show("Thành Công"); //grcNhomNV.RefreshDataSource(); NhomNVForm_Load(sender, e); }