Ejemplo n.º 1
0
        private bool SaveRecord(bool prompt)
        {
            try {
                if (_selectedRecord == null)
                {
                    return(true);
                }

                FinalizeBindings();
                bool newRec   = _selectedRecord.IsNew();
                bool modified = newRec || IsModified(_selectedRecord);

                if (modified)
                {
                    if (prompt)
                    {
                        DialogResult result = DisplayHelper.QuestionYesNoCancel(this, "Do you want to save these changes?");
                        if (result == DialogResult.No)
                        {
                            if (newRec)
                            {
                                RemoveRecord();
                            }
                            else
                            {
                                RefreshRecord();
                            }
                            return(true);
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            return(false);
                        }
                    }
                    if (!ValidateAll())
                    {
                        return(false);
                    }

                    if (_selectedRecord.EntityState == EntityState.Detached)
                    {
                        _context.INVT.AddObject(_selectedRecord);
                    }
                    SetUpdateFields(_selectedRecord);
                    _context.SaveChanges();
                    EntityInstantFeedbackSource.Refresh();
                    ShowActionConfirmation("Record Saved");
                }
                return(true);
            }
            catch (Exception ex) {
                DisplayHelper.DisplayError(this, ex);
                RefreshRecord();                        //pull it back from db because that is its current state
                //We must also Load and rebind the related entities from the db because context.Refresh doesn't do that
                SetBindings();
                return(false);
            }
        }
Ejemplo n.º 2
0
        private bool DeleteRecord()
        {
            if (_selectedRecord == null)
            {
                return(false);
            }

            try {
                if (DisplayHelper.QuestionYesNo(this, "Are you sure you want to delete this record?") == DialogResult.Yes)
                {
                    //ignoreLeaveRow and ignorePositionChange are set because when removing a record, the bindingsource_currentchanged
                    //and gridview_beforeleaverow events will fire as the current record is removed out from under them.
                    //We do not want these events to perform their usual code of checking whether there are changes in the active
                    //record that should be saved before proceeding, because we know we have just deleted the active record.
                    _ignoreLeaveRow       = true;
                    _ignorePositionChange = true;
                    RemoveRecord();
                    if (!_selectedRecord.IsNew())
                    {
                        //Apparently a record which has just been added is not flagged for deletion by BindingSource.RemoveCurrent,
                        //(the EntityState remains unchanged).  It seems like it is not tracked by the context even though it is, because
                        //the EntityState changes for modification. So if this is a deletion and the entity is not flagged for deletion,
                        //delete it manually.
                        if (_selectedRecord != null && (_selectedRecord.EntityState & EntityState.Deleted) != EntityState.Deleted)
                        {
                            _context.REGION.DeleteObject(_selectedRecord);
                        }
                        _context.SaveChanges();
                    }
                    if (GridViewLookup.DataRowCount == 0)
                    {
                        ClearBindings();
                    }
                    _ignoreLeaveRow       = false;
                    _ignorePositionChange = false;
                    EntityInstantFeedbackSource.Refresh();
                    SetBindings();
                    ShowActionConfirmation("Record Deleted");
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex) {
                DisplayHelper.DisplayError(this, ex);
                _ignoreLeaveRow       = false;
                _ignorePositionChange = false;
                RefreshRecord();        //pull it back from db because that is it's current state
                //We must also Load and rebind the related entities from the db because context.Refresh doesn't do that
                SetBindings();
                return(false);
            }
        }
Ejemplo n.º 3
0
        IInstantFeedbackSource <TProjection> IUnitOfWorkFactory <TUnitOfWork> .CreateInstantFeedbackSource <TEntity, TProjection, TPrimaryKey>(
            Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
            Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection)
        {
            var threadSafeProperties = new TypeInfoProxied(TypeDescriptor.GetProperties(typeof(TProjection)), null).UIDescriptors;

            if (projection == null)
            {
                projection = x => x as IQueryable <TProjection>;
            }
            var source = new EntityInstantFeedbackSource((GetQueryableEventArgs e) => e.QueryableSource = projection(getRepositoryFunc(createUnitOfWork())))
            {
                KeyExpression = getRepositoryFunc(createUnitOfWork()).GetPrimaryKeyPropertyName(),
            };

            return(new InstantFeedbackSource <TProjection>(source, threadSafeProperties));
        }
        IInstantFeedbackSource <TProjection> IUnitOfWorkFactory <TUnitOfWork> .CreateInstantFeedbackSource <TEntity, TProjection, TPrimaryKey>(
            Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
            Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection)
        {
            var threadSafeProperties = new TypeInfoProxied(TypeDescriptor.GetProperties(typeof(TProjection)), null).UIDescriptors;

            if (projection == null)
            {
                projection = x => x as IQueryable <TProjection>;
            }
            var keyProperties = ExpressionHelper.GetKeyProperties(getRepositoryFunc(createUnitOfWork()).GetPrimaryKeyExpression);
            var keyExpression = keyProperties.Select(p => p.Name).Aggregate((l, r) => l + ";" + r);
            var source        = new EntityInstantFeedbackSource((DevExpress.Data.Linq.GetQueryableEventArgs e) => e.QueryableSource = projection(getRepositoryFunc(createUnitOfWork())))
            {
                KeyExpression = keyExpression
            };

            return(new InstantFeedbackSource <TProjection>(source, threadSafeProperties));
        }
Ejemplo n.º 5
0
 public InstantFeedbackSource(EntityInstantFeedbackSource source, PropertyDescriptorCollection threadSafeProperties)
 {
     this.source = source;
     this.threadSafeProperties = threadSafeProperties;
 }
Ejemplo n.º 6
0
        private bool SaveRecord(bool prompt)
        {
            try {
                if (_selectedRecord == null)
                {
                    return(true);
                }

                FinalizeBindings();
                bool newRec   = _selectedRecord.IsNew();
                bool modified = newRec || IsModified(_selectedRecord);

                if (modified)
                {
                    if (prompt)
                    {
                        DialogResult result = DisplayHelper.QuestionYesNoCancel(this, "Do you want to save these changes?");
                        if (result == DialogResult.No)
                        {
                            if (newRec)
                            {
                                RemoveRecord();
                            }
                            else
                            {
                                RefreshRecord();
                            }
                            return(true);
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            return(false);
                        }
                    }
                    if (!ValidateAll())
                    {
                        return(false);
                    }

                    if (_selectedRecord.EntityState == EntityState.Detached)
                    {
                        _context.WAYPOINT.AddObject(_selectedRecord);
                    }
                    _context.SaveChanges();
                    EntityInstantFeedbackSource.Refresh();
                    ShowActionConfirmation("Record Saved");
                }
                return(true);
            }
            catch (Exception ex) {
                var objectStateManager = _context.ObjectStateManager;
                var fieldInfo          = objectStateManager.GetType().GetField("_entriesWithConceptualNulls", BindingFlags.Instance | BindingFlags.NonPublic);
                var conceptualNulls    = fieldInfo.GetValue(objectStateManager);

                DisplayHelper.DisplayError(this, ex);
                RefreshRecord();        //pull it back from db because that is its current state
                                        //We must also Load and rebind the related entities from the db because context.Refresh doesn't do that
                SetBindings();
                return(false);
            }
        }