private void _setNhaTaiTro(QL_HOATDONG_ASXH item)
        {
            var queryNhaTaiTro = item.QL_HOATDONG_NHATAITRO.ToList();

            listNhaTaiTro        = new BindingList <QL_HOATDONG_NHATAITRO>(queryNhaTaiTro);
            memoDonViTaiTro.Text = _getNhaTaiTro(listNhaTaiTro);
        }
        private void _updateDoiTuongKhac(QL_HOIVIEN_KTEntities _context, QL_HOATDONG_ASXH item)
        {
            QL_HOATDONG_ASXH_DOITUONG_KHAC item_chitiet;

            foreach (var person in listDoiTuongKhongKhuyetTat)
            {
                if (person.PARENT_ID == null) //add
                {
                    person.QL_HOATDONG_ASXH = item;
                    _context.QL_HOATDONG_ASXH_DOITUONG_KHAC.Add(person);
                }
                else if (person.PARENT_ID == clsParameter.statusDeleted) //delete
                {
                    item_chitiet = (from p in _context.QL_HOATDONG_ASXH_DOITUONG_KHAC
                                    where p.DTK_ID == person.DTK_ID
                                    select p).FirstOrDefault();
                    if (item_chitiet != null)
                    {
                        _context.QL_HOATDONG_ASXH_DOITUONG_KHAC.Remove(item_chitiet);
                    }
                }
                else //modify
                {
                    var chitiet = _context.QL_HOATDONG_ASXH_DOITUONG_KHAC.Where(p => p.DTK_ID == person.DTK_ID).FirstOrDefault();
                    if (chitiet != null)
                    {
                        _context.Entry(chitiet).CurrentValues.SetValues(person);
                    }
                }
            }
        }
        private void _updateNhaTaiTro(QL_HOIVIEN_KTEntities _context, QL_HOATDONG_ASXH item)
        {
            QL_HOATDONG_NHATAITRO item_chitiet;

            foreach (var person in listNhaTaiTro)
            {
                if (person.ASXH_ID == null) //add
                {
                    person.QL_HOATDONG_ASXH = item;
                    _context.QL_HOATDONG_NHATAITRO.Add(person);
                }
                else if (person.ASXH_ID == clsParameter.statusDeleted) //delete
                {
                    item_chitiet = (from p in _context.QL_HOATDONG_NHATAITRO
                                    where p.NTT_ID == person.NTT_ID
                                    select p).FirstOrDefault();
                    if (item_chitiet != null)
                    {
                        _context.QL_HOATDONG_NHATAITRO.Remove(item_chitiet);
                    }
                }
                else //modify
                {
                    var chitiet = _context.QL_HOATDONG_NHATAITRO.Where(p => p.NTT_ID == person.NTT_ID).FirstOrDefault();
                    if (chitiet != null)
                    {
                        _context.Entry(chitiet).CurrentValues.SetValues(person);
                    }
                }
            }
        }
        private void _bindingData()
        {
            _clearData();
            QL_HOATDONG_ASXH item = gvGrid.GetFocusedRow() as QL_HOATDONG_ASXH;

            if (item != null)
            {
                _idRowSelected              = item.ASXH_ID;
                deTuNgay.EditValue          = item.ASXH_THOIGIAN_BATDAU;
                deDenNgay.EditValue         = item.ASXH_THOIGIAN_KETTHUC;
                seTongSoNgay.EditValue      = item.ASXH_TONGSO_NGAY;
                txtTenChuongTrinh.EditValue = item.ASXH_TEN;
                txtDiaDiem.EditValue        = item.ASXH_DIADIEM;
                memoDonViTaiTro.EditValue   = item.ASXH_DONVI_THUCHIEN;

                seSoLuongNguoiThamGia.EditValue = item.ASXH_SOLUONG;
                seTongSoTien.EditValue          = item.ASXH_TONGSO_TIEN;

                memoDoiTuong.EditValue   = item.ASXH_DOITUONG_TEN;
                memoDoiTuongId.EditValue = item.ASXH_DOITUONG_ID;
                _setMemoData(item);

                txtNoiDung.EditValue = item.ASXH_NOIDUNG;
            }
        }
        private void _setDoiTuongKhac(QL_HOATDONG_ASXH item)
        {
            var query = item.QL_HOATDONG_ASXH_DOITUONG_KHAC.ToList();

            listDoiTuongKhongKhuyetTat = new BindingList <QL_HOATDONG_ASXH_DOITUONG_KHAC>(query);
            memoDoiTuongKhac.Text      = _getDoiTuongKhac(listDoiTuongKhongKhuyetTat);
        }
        protected override bool SaveData()
        {
            try
            {
                if (_validateControl())
                {
                    using (var _context = new QL_HOIVIEN_KTEntities())
                    {
                        QL_HOATDONG_ASXH item = new QL_HOATDONG_ASXH();
                        switch (_formStatus)
                        {
                        case EnumFormStatus.ADD:

                            #region Add

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

                            #endregion

                            break;

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

                        default:
                            break;
                        }
                        _context.SaveChanges();
                        _idRowSelected = item.ASXH_ID;
                    }
                    FormStatus = EnumFormStatus.VIEW;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(base.SaveData());
        }
        private void _setObjectEntities(ref QL_HOATDONG_ASXH item)
        {
            item.ASXH_LOAI_ID          = _id_loai;
            item.ASXH_THOIGIAN_BATDAU  = deTuNgay.Ex_EditValueToDateTime();
            item.ASXH_THOIGIAN_KETTHUC = deDenNgay.Ex_EditValueToDateTime();
            item.ASXH_TONGSO_NGAY      = seTongSoNgay.Ex_EditValueToInt();
            item.ASXH_TONGSO_TIEN      = seTongSoTien.Ex_EditValueToInt();

            item.ASXH_TEN            = txtTenChuongTrinh.Text;
            item.ASXH_DIADIEM        = txtDiaDiem.Text;
            item.ASXH_DONVI_THUCHIEN = memoDonViTaiTro.Text;
            item.ASXH_SOLUONG        = seSoLuongNguoiThamGia.Ex_EditValueToInt();
            item.ASXH_DOITUONG_TEN   = memoDoiTuong.Text;
            item.ASXH_DOITUONG_ID    = memoDoiTuongId.Text;
            item.ASXH_DOITUONG_KHAC  = memoDoiTuongKhac.Text;

            item.ASXH_NOIDUNG = txtNoiDung.Text;
        }
        private void _deleteRow()
        {
            QL_HOATDONG_ASXH item = gvGrid.GetFocusedRow() as QL_HOATDONG_ASXH;

            if (item != null)
            {
                if (clsMessage.MessageYesNo(string.Format("Bạn có chắc muốn xóa: {0}", item.ASXH_TEN)) == DialogResult.Yes)
                {
                    Int64 id = Convert.ToInt64(gvGrid.GetFocusedRowCellValue(colID));
                    _deleteMemoData(context, id);

                    QL_HOATDONG_ASXH entities = (from p in context.QL_HOATDONG_ASXH where p.ASXH_ID == id select p).FirstOrDefault();
                    context.QL_HOATDONG_ASXH.Remove(entities);
                    context.SaveChanges();
                    FormStatus = EnumFormStatus.VIEW;
                }
            }
        }
 private void _setMemoData(QL_HOATDONG_ASXH item)
 {
     _setNhaTaiTro(item);
     _setDoiTuongKhac(item);
 }
 private void _updateMemoData(QL_HOIVIEN_KTEntities _context, QL_HOATDONG_ASXH item)
 {
     _updateNhaTaiTro(_context, item);
     _updateDoiTuongKhac(_context, item);
 }