Exemple #1
0
        /// <summary>
        /// Fires the <see cref="ObjectContainerDataSourceView.Updating"/> event.
        /// </summary>
        /// <param name="e">The event associated data.</param>
        protected virtual void OnUpdating(ObjectContainerDataSourceUpdatingEventArgs e)
        {
            EventHandler <ObjectContainerDataSourceUpdatingEventArgs> handler =
                base.Events[UpdatingEventKey] as EventHandler <ObjectContainerDataSourceUpdatingEventArgs>;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Performs an update operation on the list of data that the <see cref="DataSourceView"/> object represents.
        /// </summary>
        /// <param name="keys">An <see cref="System.Collections.IDictionary"/> of object or row keys to be updated by the update operation.</param>
        /// <param name="values">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their new values.</param>
        /// <param name="oldValues">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their original values.</param>
        /// <returns>The number of items that were updated in the underlying data storage.</returns>
        protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            Guard.CollectionNotNullNorEmpty(keys, String.Format(CultureInfo.CurrentCulture, Resources.NoKeysSpecified), "keys");
            Guard.ArgumentNotNull(values, "values");

            ObjectContainerDataSourceUpdatingEventArgs updatingEventArgs =
                new ObjectContainerDataSourceUpdatingEventArgs(DictionaryHelper.GetReadOnlyDictionary(keys), values, oldValues);

            OnUpdating(updatingEventArgs);
            if (updatingEventArgs.Cancel)
            {
                return(0);
            }

            object newInstance = CreateInstance();

            TypeDescriptionHelper.BuildInstance(keys, newInstance);
            TypeDescriptionHelper.BuildInstance(values, newInstance);
            int    rowsAffected;
            object oldInstance = FindInstance(keys);

            if (oldInstance != null)
            {
                int index = Data.IndexOf(oldInstance);
                Data[index]  = newInstance;
                rowsAffected = 1;
            }
            else
            {
                rowsAffected = 0;
            }
            OnDataSourceViewChanged(EventArgs.Empty);

            ObjectContainerDataSourceStatusEventArgs updatedEventArgs = new ObjectContainerDataSourceStatusEventArgs(newInstance, rowsAffected);

            OnUpdated(updatedEventArgs);

            return(rowsAffected);
        }