private void _updateMemoData(QL_HOIVIEN_KTEntities _context, QL_HOATDONG_DAYNGHE item)
        {
            QL_HOATDONG_DAYNGHE_DOITUONG_KHAC item_chitiet;

            foreach (var person in listDoiTuongKhongKhuyetTat)
            {
                if (person.PARENT_ID == null) //add
                {
                    person.QL_HOATDONG_DAYNGHE = item;
                    _context.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC.Add(person);
                }
                else if (person.PARENT_ID == clsParameter.statusDeleted) //delete
                {
                    item_chitiet = (from p in _context.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC
                                    where p.DTK_ID == person.DTK_ID
                                    select p).FirstOrDefault();
                    if (item_chitiet != null)
                    {
                        _context.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC.Remove(item_chitiet);
                    }
                }
                else //modify
                {
                    var chitiet = _context.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC.Where(p => p.DTK_ID == person.DTK_ID).FirstOrDefault();
                    if (chitiet != null)
                    {
                        _context.Entry(chitiet).CurrentValues.SetValues(person);
                    }
                }
            }
        }
        private void _setMemoText(QL_HOATDONG_DAYNGHE item)
        {
            var query = item.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC.ToList();

            listDoiTuongKhongKhuyetTat = new BindingList <QL_HOATDONG_DAYNGHE_DOITUONG_KHAC>(query);
            memoDoiTuongKhac.Text      = _getMemoText(listDoiTuongKhongKhuyetTat);
        }
        private void _bindingData()
        {
            _clearData();
            QL_HOATDONG_DAYNGHE item = gvGrid.GetFocusedRow() as QL_HOATDONG_DAYNGHE;

            if (item != null)
            {
                _idRowSelected = item.DN_ID;

                deTuNgay.EditValue     = item.DN_THOIGIAN_BATDAU;
                deDenNgay.EditValue    = item.DN_THOIGIAN_KETTHUC;
                seTongSoNgay.EditValue = item.DN_TONGSO_NGAY;

                txtTenChuongTrinh.EditValue = item.DN_TEN;
                txtNgheDay.EditValue        = item.DN_NGHE;
                txtDiaDiem.EditValue        = item.DN_DIADIEM;
                txtDayTuNguon.EditValue     = item.DN_DONVI_THUCHIEN;

                seSoLuongNguoiThamGia.EditValue = item.DN_SOLUONG;
                seSoLuongNu.EditValue           = item.DN_SOLUONG_NU;
                seTongKinhPhi.EditValue         = item.DN_TONGTIEN;

                memoDoiTuongThamGia.EditValue = item.DN_DOITUONG_THAMGIA;
                memoDoiTuongId.EditValue      = item.DN_DOITUONG_THAMGIA_ID;

                _setMemoText(item);
                txtNoiDung.EditValue = item.DN_NOIDUNG;
                txtHoTro.EditValue   = item.DN_NGUOI_HOTRO;
            }
        }
        protected override bool SaveData()
        {
            if (_validateControl())
            {
                using (var _context = new QL_HOIVIEN_KTEntities())
                {
                    QL_HOATDONG_DAYNGHE item = new QL_HOATDONG_DAYNGHE();
                    switch (_formStatus)
                    {
                    case EnumFormStatus.ADD:

                        item = new QL_HOATDONG_DAYNGHE();
                        _setObjectEntities(ref item);
                        _updateMemoData(_context, item);
                        _context.QL_HOATDONG_DAYNGHE.Add(item);

                        break;

                    case EnumFormStatus.MODIFY:
                        Int64 id = Convert.ToInt64(gvGrid.GetFocusedRowCellValue(colID));
                        item = (from p in _context.QL_HOATDONG_DAYNGHE where p.DN_ID == id select p).FirstOrDefault <QL_HOATDONG_DAYNGHE>();
                        if (item != null)
                        {
                            _setObjectEntities(ref item);
                        }
                        var entity = _context.QL_HOATDONG_DAYNGHE.Find(id);
                        if (entity != null)
                        {
                            _context.Entry(entity).CurrentValues.SetValues(item);
                        }

                        _updateMemoData(_context, item);
                        break;

                    default:
                        break;
                    }

                    _context.SaveChanges();

                    _idRowSelected = item.DN_ID;
                }
                FormStatus = EnumFormStatus.VIEW;
            }

            return(base.SaveData());
        }
        private void _setObjectEntities(ref QL_HOATDONG_DAYNGHE item)
        {
            item.DN_THOIGIAN_BATDAU  = deTuNgay.Ex_EditValueToDateTime();
            item.DN_THOIGIAN_KETTHUC = deDenNgay.Ex_EditValueToDateTime();
            item.DN_TONGSO_NGAY      = seTongSoNgay.Ex_EditValueToInt();


            item.DN_TEN            = txtTenChuongTrinh.Text;
            item.DN_NGHE           = txtNgheDay.Text;
            item.DN_DIADIEM        = txtDiaDiem.Text;
            item.DN_DONVI_THUCHIEN = txtDayTuNguon.Text;

            item.DN_SOLUONG    = seSoLuongNguoiThamGia.Ex_EditValueToInt();
            item.DN_SOLUONG_NU = seSoLuongNu.Ex_EditValueToInt();
            item.DN_TONGTIEN   = seTongKinhPhi.Ex_EditValueToInt();

            item.DN_NOIDUNG             = txtNoiDung.Text;
            item.DN_DOITUONG_THAMGIA    = memoDoiTuongThamGia.Text;
            item.DN_DOITUONG_THAMGIA_ID = memoDoiTuongId.Text;
            item.DN_NGUOI_HOTRO         = txtHoTro.Text;
        }
        private void _deleteRow()
        {
            QL_HOATDONG_DAYNGHE item = gvGrid.GetFocusedRow() as QL_HOATDONG_DAYNGHE;

            if (item != null)
            {
                if (clsMessage.MessageYesNo(string.Format("Bạn có chắc muốn xóa: {0}", item.DN_TEN)) == DialogResult.Yes)
                {
                    Int64 id          = Convert.ToInt64(gvGrid.GetFocusedRowCellValue(colID));
                    var   listChiTiet = (from p in context.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC where p.PARENT_ID == id select p);
                    foreach (var item_delete in listChiTiet)
                    {
                        context.QL_HOATDONG_DAYNGHE_DOITUONG_KHAC.Remove(item_delete);
                    }

                    QL_HOATDONG_DAYNGHE entities = (from p in context.QL_HOATDONG_DAYNGHE where p.DN_ID == id select p).FirstOrDefault();
                    context.QL_HOATDONG_DAYNGHE.Remove(entities);
                    context.SaveChanges();
                    FormStatus = EnumFormStatus.VIEW;
                }
            }
        }