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); } }
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"; } } } } }