private void btnSuaCongViec_Click(object sender, EventArgs e) { if (this.txtTenCongViec.Text.Trim().Length <= 0 || this.txtMaCongViec.Text.Trim().Length <= 0 || this.dateTimeDuKienHoanThanh.Value > DateTime.Now || this.dateTimeBatDauCongViec.Value > DateTime.Now || this.dateTimeDuKienHoanThanh.Value > DateTime.Now) { if (this.txtMaCongViec.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtMaCongViec, "Ma cong viec khong duoc trong"); return; } else if (CongViecControllers.getMaCongViecfromDB(this.txtMaCongViec.Text.Trim()) != "") { this.errorProvider1.SetError(this.txtMaCongViec, "Ma cong viec da ton tai"); return; } else { this.errorProvider1.Clear(); } if (this.txtTenCongViec.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtTenCongViec, "nhap ten cong viec"); return; } else { this.errorProvider1.Clear(); } if (this.dateTimeBatDauCongViec.Value <= DateTime.Now) { this.errorProvider1.SetError(this.dateTimeBatDauCongViec, "nhap ngay bat dau"); return; } else { this.errorProvider1.Clear(); } if (this.dateTimeDuKienHoanThanh.Value <= DateTime.Now) { this.errorProvider1.SetError(this.dateTimeDuKienHoanThanh, "nhap ngay du kien hoan thanh"); return; } else { this.errorProvider1.Clear(); } } var lcv = CongViecControllers.getListCongViecfromDB(); CongViec cv = new CongViec(); cv.MaCongViec = txtMaCongViec.Text.Trim(); cv.TenCongViec = txtTenCongViec.Text.Trim(); cv.NoiDungCongViec = rtxtNoiDungCongViec.Text.Trim(); //cv.ListNhomPhuTrach = cbbNhom.SelectedItem.ToString(); cv.NgayBatDau = DateTime.Parse(dateTimeBatDauCongViec.Value.ToString()); cv.DuKienHoanThanh = DateTime.Parse(dateTimeDuKienHoanThanh.Value.ToString()); cv.NgayHoanThanh = lcv[dataGridViewCongViec.CurrentRow.Index].NgayHoanThanh; cv.TienDo = lcv[dataGridViewCongViec.CurrentRow.Index].TienDo; cv.ChiPhi = lcv[dataGridViewCongViec.CurrentRow.Index].ChiPhi; CongViecControllers.updateCongViec(cv); BindingSource source = new BindingSource(); source.DataSource = CongViecControllers.getListCongViecfromDB(); this.dataGridViewCongViec.DataSource = source; }
private void btnThemCongViec_Click(object sender, EventArgs e) { if (this.txtTenCongViec.Text.Trim().Length <= 0 || this.txtMaCongViec.Text.Trim().Length <= 0 || this.dateTimeDuKienHoanThanh.Value > DateTime.Now || this.dateTimeBatDauCongViec.Value > DateTime.Now || this.dateTimeDuKienHoanThanh.Value > DateTime.Now) { if (this.txtMaCongViec.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtMaCongViec, "Ma cong viec khong duoc trong"); return; } else if (CongViecControllers.getMaCongViecfromDB(this.txtMaCongViec.Text.Trim()) != "") { this.errorProvider1.SetError(this.txtMaCongViec, "Ma cong viec da ton tai"); return; } else { this.errorProvider1.Clear(); } if (this.txtTenCongViec.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtTenCongViec, "nhap ten cong viec"); return; } else { this.errorProvider1.Clear(); } if (this.dateTimeBatDauCongViec.Value <= DateTime.Now) { this.errorProvider1.SetError(this.dateTimeBatDauCongViec, "nhap ngay bat dau"); return; } else { this.errorProvider1.Clear(); } if (this.dateTimeDuKienHoanThanh.Value <= DateTime.Now) { this.errorProvider1.SetError(this.dateTimeDuKienHoanThanh, "nhap ngay du kien hoan thanh"); return; } else { this.errorProvider1.Clear(); } } CongViec cv = new CongViec(); cv.MaCongViec = txtMaCongViec.Text.Trim(); cv.TenCongViec = txtTenCongViec.Text.Trim(); cv.NoiDungCongViec = rtxtNoiDungCongViec.Text.Trim(); //cv.ListNhomPhuTrach = cbbNhom.SelectedItem.ToString(); cv.NgayBatDau = DateTime.Parse(dateTimeBatDauCongViec.Value.ToString()); cv.DuKienHoanThanh = DateTime.Parse(dateTimeDuKienHoanThanh.Value.ToString()); cv.NgayHoanThanh = DateTime.Parse("01/01/2000 12:00:00 AM"); cv.TienDo = 0; cv.ChiPhi = 0; DuAn da = DuAnControllers.getDuAnfromDB(lda[(cbxListDuAn.SelectedIndex)].MaDuAn.Trim()); if (da.CongViecDuAn == null) { da.CongViecDuAn = txtMaCongViec.Text.Trim(); } else { da.CongViecDuAn = da.CongViecDuAn.Trim() + "," + txtMaCongViec.Text.Trim(); } DuAnControllers.updateDA(da); CongViecControllers.AddCongViec(cv); BindingSource source = new BindingSource(); source.DataSource = CongViecControllers.getListCongViecfromDB(); this.dataGridViewCongViec.DataSource = source; }