Пример #1
0
        /// <summary>
        ///     Commits the changes to the database when one or more field values have changed.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="predicate">The predicate that indicates if the field should be checked for changes.</param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing <c>true</c> when the store was called on the row; otherwise <c>false</c>
        /// </returns>
        /// <exception cref="System.ArgumentNullException">predicate</exception>
        /// <remarks>
        ///     The changes will not be saved, if there was a call to BlockReentrancy of which the IDisposable return value has not
        ///     yet been disposed of.
        /// </remarks>
        public static bool SaveChanges(this IRow source, Predicate <IField> predicate)
        {
            if (source == null)
            {
                return(false);
            }
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            source.CheckReentrancy();

            bool        saveChanges = false;
            IRowChanges rowChanges  = (IRowChanges)source;

            for (int i = 0; i < source.Fields.FieldCount; i++)
            {
                if (predicate(source.Fields.Field[i]) && rowChanges.ValueChanged[i])
                {
                    saveChanges = true;
                    break;
                }
            }

            if (saveChanges)
            {
                source.Store();
            }

            return(saveChanges);
        }