Ejemplo n.º 1
0
 /// <summary>
 /// Called to accept all proposed changes and mark the dirty as Unchanged. See <see cref="RejectChanges"/> as well.
 /// </summary>
 virtual public void AcceptChanges()
 {
     if (rowState == esDataRowState.Deleted)
     {
         currentValues     = originalValues = null;
         m_modifiedColumns = null;
         rowState          = esDataRowState.Invalid;
     }
     else
     {
         originalValues    = new esSmartDictionary(currentValues);
         rowState          = esDataRowState.Unchanged;
         m_modifiedColumns = null;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// RejectChanges does just the opposite of <see cref="AcceptChanges"/>. That is, RejectChanges moves the
 /// original values back into the current values, it's as if nothing was ever changed.
 /// </summary>
 /// <seealso cref="AcceptChanges"/>
 virtual public void RejectChanges()
 {
     if (rowState == esDataRowState.Added)
     {
         currentValues     = new esSmartDictionary(currentValues.Count);
         rowState          = esDataRowState.Unchanged;
         m_modifiedColumns = null;
     }
     else
     {
         currentValues     = new esSmartDictionary(originalValues);
         rowState          = esDataRowState.Unchanged;
         m_modifiedColumns = null;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Called by all of the property setters
        /// </summary>
        /// <param name="columnName">The name of the column to set</param>
        /// <param name="data">the value to set it to</param>
        /// <returns>True if the value has truly changed</returns>
        protected bool SetValue(object data, [CallerMemberName] string propertyName = null)
        {
            bool changed = true;

            if (rowState == esDataRowState.Deleted)
            {
                throw new Exception("Cannot modifiy deleted records");
            }

            try
            {
                if (currentValues == null)
                {
                    currentValues = new esSmartDictionary();
                    CurrentValues_OnFirstAccess(currentValues);
                }

                if (currentValues.Count == 0)
                {
                    if (rowState == esDataRowState.Added && !applyDefaultsCalled)
                    {
                        applyDefaultsCalled = true;
                        ApplyDefaults();
                    }
                }

                string columnName = Getters[propertyName];
                if (!currentValues.ContainsKey(columnName))
                {
                    currentValues[columnName] = data;
                    changed = true;

                    if (rowState == esDataRowState.Unchanged)
                    {
                        rowState = esDataRowState.Modified;
                    }
                }
                else
                {
                    object o      = currentValues[columnName];
                    bool   isNull = (o == DBNull.Value || o == null);

                    // Note that we grab this before we make the change
                    esDataRowState state = rowState;

                    if (data == null && isNull)
                    {
                        // Nothing to do here
                        changed = false;
                    }
                    else
                    {
                        if (isNull && data != null)
                        {
                            currentValues[columnName] = data;
                        }
                        else if (data == null && !isNull)
                        {
                            currentValues[columnName] = DBNull.Value;
                        }
                        else if (!o.Equals(data))
                        {
                            this.currentValues[columnName] = data;

                            // Special logic to see if we have changed it back to it's original value, if
                            // so we mark this column as no longer dirty, which if the only one could return
                            // the rowstate back to "Unchanged"
                            if (originalValues != null && originalValues.ContainsKey(columnName))
                            {
                                if (data == originalValues[columnName])
                                {
                                    MarkFieldAsUnchanged(columnName);
                                    return(true); // it still changed but we don't want to mark it as dirty
                                }
                            }
                        }
                        else
                        {
                            changed = false;
                        }
                    }
                }

                if (changed)
                {
                    MarkFieldAsModified(columnName);
                }
            }
            finally
            {
            }

            return(changed);
        }
Ejemplo n.º 4
0
 private void CurrentValues_OnFirstAccess(esSmartDictionary smartDictionary)
 {
     smartDictionary.Allocate(1);
 }