public static bool AddCongViecNhanVien(CongViecNhanVien cv) { try { using (var _context = new QuanLyDuAnEntities1()) { _context.CongViecNhanViens.Add(cv); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool updateCongViecNhanVien(CongViecNhanVien nv) { try { using (var _context = new QuanLyDuAnEntities1()) { // nv.Luong = getLuongNV(nv.MaNhanVien); _context.CongViecNhanViens.AddOrUpdate(nv); _context.SaveChanges(); return(true); } } catch { return(false); } }
private void btnSuaCongViec_Click(object sender, EventArgs e) { if (this.txtMaCongViecNhanVien.Text.Trim().Length <= 0 || this.txtMaNhanVien.Text.Trim().Length <= 0 || this.dateTimeDuKienHoanThanhCVNV.Value > DateTime.Now || this.dateTimeNgayBatDauCVNV.Value > DateTime.Now || this.dateTimeNgayKetThucCVNV.Value > DateTime.Now) { if (this.txtMaCongViecNhanVien.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtMaCongViecNhanVien, "Ma cong viec khong duoc trong"); return; } else if (this.txtMaNhanVien.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtMaNhanVien, "Ma nhan vien khong duoc de trong"); return; } this.errorProvider1.Clear(); if (this.txtTenCongViecNhanVien.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtTenCongViecNhanVien, "nhap ten cong viec"); return; } else { this.errorProvider1.Clear(); } if (this.txtMoTaCongViecNhanVien.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtMoTaCongViecNhanVien, "nhap mo ta cong viec"); return; } else { this.errorProvider1.Clear(); } if (this.txtLuongCongViec.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtLuongCongViec, "nhap luong cong viec"); return; } else { this.errorProvider1.Clear(); } if (this.dateTimeNgayBatDauCVNV.Value <= DateTime.Now) { this.errorProvider1.SetError(this.dateTimeNgayBatDauCVNV, "nhap ngay bat dau"); return; } else { this.errorProvider1.Clear(); } if (this.dateTimeDuKienHoanThanhCVNV.Value <= DateTime.Now) { this.errorProvider1.SetError(this.dateTimeDuKienHoanThanhCVNV, "nhap ngay du kien hoan thanh"); return; } else { this.errorProvider1.Clear(); } } CongViecNhanVien cv = new CongViecNhanVien(); cv.MaCongViecNhanVien = txtMaCongViecNhanVien.Text.Trim(); cv.TenCongViec = txtTenCongViecNhanVien.Text.Trim(); cv.MaNhanVienPhuTrach = txtMaNhanVien.Text.Trim(); cv.MoTa = txtMoTaCongViecNhanVien.Text.Trim(); cv.LuongCongViec = int.Parse(txtLuongCongViec.Text.Trim()); cv.TaiLieu = txtTaiLieu.Text.Trim(); cv.NgayBatDau = DateTime.Parse(dateTimeNgayBatDauCVNV.Value.ToString()); cv.DuKienHoanThanh = DateTime.Parse(dateTimeDuKienHoanThanhCVNV.Value.ToString()); cv.NgayHoanThanh = DateTime.Parse(dateTimeNgayKetThucCVNV.Value.ToString()); cv.TienDo = bool.Parse(txtTienDoCongViecNhanVien.Text); ChiPhi cp = new ChiPhi(); cp.ChiPhiCongViec = cv.LuongCongViec; cp.MaCongViecChiTieu = cv.MaCongViecNhanVien; cp.CongViecChiTieu = cv.TenCongViec; cp.ThucHien = DateTime.Parse(dateTimeNgayKetThucCVNV.Value.ToString()); ChiPhiControllers.updateChiPhi(cp); CongViecNhanVienControllers.updateCongViecNhanVien(cv); BindingSource source = new BindingSource(); source.DataSource = CongViecNhanVienControllers.getListCongViecNhanVienfromDB(); this.dataGridViewCongViecDangThucHien.DataSource = source; }