Exemple #1
0
        /// <summary>
        /// Cancels the current edit process.
        /// </summary>
        /// <remarks>Calls OnCancelEdit to allow the implementing class a way
        /// to restore its original values using the FieldCache.  This
        /// is probably possible using reflection - need to look into it.
        /// </remarks>
        public void CancelEdit()
        {
            if (_editstore == null)
            {
                _editstore = new FieldCache();
            }
            OnCancelEdit(_editstore);
            UndoChanges();

            // Potential problem here - cancelling might not leave a clean item if item was new!
            MarkClean();
            _isEditing = false;
        }
Exemple #2
0
        /// <summary>
        /// Commits the current edit process and saves the changes to
        /// the database.
        /// </summary>
        public void ApplyEdit()
        {
            if (_editstore == null)
            {
                _editstore = new FieldCache();
            }
            OnApplyEdit(_editstore);

            // Note: Also invokes OnDataXXX methods to persist...
            AcceptChanges();

            _canAbandon = false;
            _isEditing  = false;
        }
Exemple #3
0
 /// <summary>
 /// Starts editing this object.
 /// </summary>
 public void BeginEdit()
 {
     // Save some key state variables
     if (!_isEditing)
     {
         _wasDeleted     = _isDeleted;
         _preBrokenRules = BrokenRules.Clone(_brokenrules);
     }
     _isEditing = true;
     if (_editstore == null)
     {
         _editstore = new FieldCache();
     }
     OnBeginEdit(_editstore);
 }
Exemple #4
0
 protected void OnPropertyChanging(string propertyName, object currentValue)
 {
     //Debug.Print(string.Format("OnPropertyChanging, property={0}, currentvalue={1}", propertyName, currentValue));
     if (PropertyChanging != null)
     {
         PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
     }
     if (!_enableChangeTracking)
     {
         return;
     }
     if (_editstore == null)
     {
         _editstore = new FieldCache();
     }
     _editstore.FieldChanging(propertyName, currentValue);
 }
Exemple #5
0
 private void OnPropertyChanged(string propertyName, object newValue)
 {
     _isDirty = true;
     if (_enableChangeTracking)
     {
         if (_editstore == null)
         {
             _editstore = new FieldCache();
         }
         _editstore.FieldChanged(propertyName, newValue);
     }
     //Debug.Print(string.Format("OnPropertyChanged, property={0}, newvalue={1}", propertyName, newValue));
     if (PropertyChanged != null)
     {
         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     }
     //OnPropertyChanged(propertyName);
 }
Exemple #6
0
        /// <summary>
        /// Reverses any changes made since the last BeginEdit call.
        /// </summary>
        /// <remarks>This method uses reflection to restore the original values from
        /// the edit store.  After cancelling the object is marked clean and the brokenrules
        /// collection is cleared.</remarks>
        public void UndoChanges()
        {
            if (_editstore == null)
            {
                _editstore = new FieldCache();
            }

            // Restore changed values from edit store.  Use reflection to write directly
            // to local fields in implementing class.
            DisableChangeTracking();

            foreach (KeyValuePair <string, FieldInfo> item in _editstore)
            {
                // Lookup schema object associated with changed data
                ColumnAttribute col;
                if (!Schema.Cols.TryGetValue(item.Key, out col))
                {
                    throw new Exception(string.Format("Unable to restore object state - missing column attribute for field {0}", item.Key));
                }

                // use reflection to access field
                System.Reflection.FieldInfo field = typeof(T).GetField(col.Storage, BindingFlags.NonPublic | BindingFlags.Instance);
                if (field == null)
                {
                    throw new Exception(string.Format("Unable to restore object state - storage field not found for field {0}", item.Key));
                }

                // Restore value
                field.SetValue(this, item.Value.OriginalValue);
            }

            // Restore some key state vars.
            _brokenrules = _preBrokenRules;
            _isDeleted   = _wasDeleted;

            EnableChangeTracking();
            OnUnknownPropertyChanged();
        }
Exemple #7
0
 /// <summary>
 /// Called when editing is applied on this object, either from data binding or
 /// by directly calling ApplyEdit.
 /// </summary>
 /// <param name="store">The collection of changed field values.</param>
 /// <remarks>This method is not intended for persistance.  Only use this method to
 /// make any necessary changes to the current state of the object.</remarks>
 protected virtual void OnApplyEdit(FieldCache store)
 {
 }
Exemple #8
0
 /// <summary>
 /// Called when editing is cancelled on this object, either from data binding or
 /// by directly calling CancelEdit.
 /// </summary>
 /// <param name="store">The collection of changed field values.</param>
 /// <remarks>This method is not intended for persistance.  Only use this method to
 /// make any necessary changes to the current state of the object.</remarks>
 protected virtual void OnCancelEdit(FieldCache store)
 {
 }
Exemple #9
0
 /// <summary>
 /// Called when editing begins on this object, either from data binding or by
 /// directly calling BeginEdit.
 /// </summary>
 /// <param name="store">The collection of changed field values.</param>
 /// <remarks>This method is not intended for persistance.  Only use this method to
 /// make any necessary changes to the current state of the object.</remarks>
 protected virtual void OnBeginEdit(FieldCache store)
 {
 }