public bool Update(NhanVienBan nhanVien) { try { var nv = context.NhanVienBans.Find(nhanVien.ID); nv.Name = nhanVien.Name; nv.CMND = nhanVien.CMND; nv.DOB = nhanVien.DOB; nv.GioiTinh = nhanVien.GioiTinh; nv.HinhAnh = nhanVien.HinhAnh; nv.NoiCap = nhanVien.NoiCap; nv.NgayCap = nhanVien.NgayCap; nv.TTLamViec = nhanVien.TTLamViec; nv.SDT = nhanVien.SDT; nv.HonNhan = nhanVien.HonNhan; nv.DiaChi = nhanVien.DiaChi; if (context.SaveChanges() <= 0) { return(false); } return(true); } catch { return(false); } }
private void TaskControl1_SaveEvent(object sender, EventArgs e) { isFind = false; if (!inputIsCorrect()) { return; } taskControl1.isSuccessFul = true; var nhanVien = new NhanVienBan() { Name = txtEmployeeName.Text, DOB = dtBirthDay.Value, NgayCap = dtDate.Value, CMND = txtCMND.Text, NoiCap = txtPlaceMade.Text, GioiTinh = (string)cbSex.SelectedItem, HonNhan = cbMarried.SelectedItem != null?cbMarried.SelectedItem.ToString() == "Có" ? true : false : false, HinhAnh = picAvatar.Tag != null ? (string)picAvatar.Tag : "", SDT = txtPhoneNumber.Text, TTLamViec = (string)cbState.SelectedItem != null ? (string)cbState.SelectedItem : "", DiaChi = txtAddress.Text, DaXoa = false }; if (isAdd) { var rs = nhanVienBanBus.Add(nhanVien); if (rs == true) { MessageBox.Show("Thêm nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadAll(); } else { MessageBox.Show("Thêm nhân viên không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { nhanVien.ID = int.Parse(txtEmloyeeId.Text); var rs = nhanVienBanBus.Update(nhanVien); if (rs == false) { MessageBox.Show("Sửa nhân viên không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadAll(); } } panelContent.Enabled = false; }
public bool Add(NhanVienBan nhanVien) { try { context.NhanVienBans.Add(nhanVien); if (context.SaveChanges() <= 0) { return(false); } return(true); } catch { return(false); } }
public bool Delete(NhanVienBan nv) { try { var nhanVien = context.NhanVienBans.Find(nv.ID); nhanVien.DaXoa = true; if (context.SaveChanges() <= 0) { return(false); } return(true); } catch { return(false); } }
private void TaskControl1_DeleteEvent(object sender, EventArgs e) { NhanVienBan nv = new NhanVienBan() { ID = int.Parse(txtEmloyeeId.Text) }; var rs = nhanVienBanBus.Delete(nv); if (rs == true) { MessageBox.Show("Xóa nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadAll(); } else { MessageBox.Show("Xóa nhân viên không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }