public List <eCongTrinh> getAllCongTrinh() { List <CongTrinh> list = db.CongTrinhs.Where(p => p.isDelete == false).ToList(); List <eCongTrinh> eList = new List <eCongTrinh>(); foreach (CongTrinh item in list) { string a = item.idCongTrinh; eCongTrinh e = new eCongTrinh(item.idCongTrinh, item.tenCongTrinh, item.diaChi, (DateTime)item.ngayBatDau, (DateTime)item.ngayKetThucDuKien, (DateTime)item.ngayHoanThanh, item.trangThai, (bool)item.isDelete); eList.Add(e); } return(eList); }
private void btnLuu_Click(object sender, EventArgs e) { if (trangThaiLuu == 0) // Thêm { eCongTrinh a = new eCongTrinh(tbTenCongTrinh.Text, tbDiaChi.Text, (DateTime)dateNgayBatDau.Value, (DateTime)dateNgayKetThuc.Value); bool kq = ctBLL.themCongTrinh(a); if (kq) { XtraMessageBox.Show("Thêm công trình thành công"); } else { XtraMessageBox.Show("Thêm công trình thất bại !!!"); } dataGridView1.DataSource = null; dataGridView1.DataSource = ctBLL.getAllCongTrinh(); loadDataCellCongTrinh(); btnCapNhat.Enabled = btnXoa.Enabled = btnThem.Enabled = true; btnLuu.Enabled = false; enableOptions(false); trangThaiLuu = -1; btnThem.Text = "Thêm mới"; } else //Cập nhật { eCongTrinh a = new eCongTrinh(dataGridView1.CurrentRow.Cells[0].Value.ToString(), tbTenCongTrinh.Text, tbDiaChi.Text, (DateTime)dateNgayBatDau.Value, (DateTime)dateNgayKetThuc.Value, (DateTime)dateNgayHoanThanh.Value, comboBoxTrangThai.Text); bool kq = ctBLL.capNhatCongTrinh(a); if (kq) { XtraMessageBox.Show("Cập nhật công trình thành công"); } else { XtraMessageBox.Show("Cập nhật công trình thất bại !!!"); } dataGridView1.DataSource = null; dataGridView1.DataSource = ctBLL.getAllCongTrinh(); loadDataCellCongTrinh(); btnCapNhat.Enabled = btnXoa.Enabled = btnThem.Enabled = true; btnLuu.Enabled = false; enableOptions(false); } }
public bool capNhatCongTrinh(eCongTrinh a) { CongTrinh aa = db.CongTrinhs.Where(p => p.idCongTrinh == a.idCongTrinh).SingleOrDefault(); if (a != null) { aa.tenCongTrinh = a.tenCongTrinh; aa.diaChi = a.diaChi; aa.ngayBatDau = (DateTime)a.ngayBatDau; aa.ngayKetThucDuKien = (DateTime)a.ngayKetThucDuKien; aa.ngayHoanThanh = (DateTime)a.ngayHoanThanh; aa.trangThai = a.trangThai; db.SubmitChanges(); return(true); } else { return(false); } }
public bool themCongTrinh(eCongTrinh a) { CongTrinh aa = new CongTrinh(); aa.idCongTrinh = idTuDongTang(); aa.tenCongTrinh = a.tenCongTrinh; aa.diaChi = a.diaChi; aa.ngayBatDau = (DateTime)a.ngayBatDau; aa.ngayKetThucDuKien = (DateTime)a.ngayKetThucDuKien; aa.ngayHoanThanh = new DateTime(1900, 1, 1); aa.trangThai = "Đang Thực Hiện"; aa.isDelete = false; if (!db.CongTrinhs.Contains(aa)) { db.CongTrinhs.InsertOnSubmit(aa); db.SubmitChanges(); return(true); } return(false); }
private void btnLuu_Click(object sender, EventArgs e) { if (trangThaiLuu == 0) // Thêm { if (tbTenCongTrinh.Text.Trim().Length == 0 || tbDiaChi.Text.Trim().Length == 0) { XtraMessageBox.Show("Vui lòng nhập đầy đủ dữ liệu cho công trình mới!"); } else { if (dateNgayBatDau.Value > dateNgayKetThuc.Value) { XtraMessageBox.Show("Ngày bắt đầu phải nhỏ hơn hoặc bằng ngày kết thúc công trình!"); } else { eCongTrinh a = new eCongTrinh(tbTenCongTrinh.Text, tbDiaChi.Text, (DateTime)dateNgayBatDau.Value, (DateTime)dateNgayKetThuc.Value); bool kq = ctBLL.themCongTrinh(a); if (kq) { XtraMessageBox.Show("Thêm công trình thành công"); } else { XtraMessageBox.Show("Thêm công trình thất bại !!!"); } dataGridView1.DataSource = null; dataGridView1.DataSource = ctBLL.getAllCongTrinh(); loadDataCellCongTrinh(); btnCapNhat.Enabled = btnXoa.Enabled = btnThem.Enabled = true; btnLuu.Enabled = false; enableOptions(false); trangThaiLuu = -1; btnThem.Text = "Thêm Mới"; } } } else //Cập nhật { if (tbTenCongTrinh.Text.Trim().Length == 0 || tbDiaChi.Text.Trim().Length == 0) { XtraMessageBox.Show("Vui lòng nhập đầy đủ dữ liệu cho công trình!"); } else { if (dateNgayBatDau.Value > dateNgayKetThuc.Value) { XtraMessageBox.Show("Ngày bắt đầu phải nhỏ hơn hoặc bằng ngày kết thúc công trình!"); } else { if (comboBoxTrangThai.Text == "Đang Thực Hiện") { XtraMessageBox.Show("Trạng thái chỉ được cập nhật khi Quá Hạn hoặc Hoàn Thành !"); } else { eCongTrinh a = new eCongTrinh(dataGridView1.CurrentRow.Cells[0].Value.ToString(), tbTenCongTrinh.Text, tbDiaChi.Text, (DateTime)dateNgayBatDau.Value, (DateTime)dateNgayKetThuc.Value, (DateTime)dateNgayHoanThanh.Value, comboBoxTrangThai.Text); bool kq = ctBLL.capNhatCongTrinh(a); if (kq) { XtraMessageBox.Show("Cập nhật công trình thành công"); } else { XtraMessageBox.Show("Cập nhật công trình thất bại !!!"); } dataGridView1.DataSource = null; dataGridView1.DataSource = ctBLL.getAllCongTrinh(); loadDataCellCongTrinh(); btnCapNhat.Enabled = btnXoa.Enabled = btnThem.Enabled = true; btnLuu.Enabled = false; enableOptions(false); trangThaiLuu = -1; btnCapNhat.Text = "Cập Nhật"; } } } } }