示例#1
0
			/// <summary>
			/// Raises the EntityDataSource.Deleted event.
			/// </summary>
			/// <param name="args">An instance of EntityDataSourceMethodEventArgs containing the event data.</param>
			internal void OnDeleted(EntityDataSourceMethodEventArgs args)
			{
				if ( _owner.Deleted != null )
				{
					_owner.Deleted(_owner, args);
				}
			}
示例#2
0
			/// <summary>
			/// Raises the EntityDataSource.Updating event.
			/// </summary>
			/// <param name="args">An instance of EntityDataSourceMethodEventArgs containing the event data.</param>
			internal void OnUpdating(EntityDataSourceMethodEventArgs args)
			{
				if ( _owner.Updating != null )
				{
					_owner.Updating(_owner, args);
				}
			}
示例#3
0
			/// <summary>
			/// Performs a delete operation on the list of data
			/// that the EntityDataSourceView object represents.
			/// </summary>
			/// <param name="keys">A System.Collections.IDictionary of object or
			/// row keys to be deleted by the ExecuteDelete operation.</param>
			/// <param name="oldValues">An System.Collections.IDictionary of name/value
			/// pairs that represent data elements and their original values.</param>
			/// <returns>The number of items that were deleted from the underlying data storage.</returns>
			protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues)
			{
				IEnumerable entityList = GetEntityList();
				ValidateEntity(entityList);

				// set the EntityIndex based on keys
				SetEntityIndex(entityList, keys);

				EntityDataSourceMethodEventArgs eventArgs = new EntityDataSourceMethodEventArgs(entityList, EntityIndex, oldValues);
				OnDeleting(eventArgs);

				if ( eventArgs.Cancel )
				{
					return 0;
				}

				// get the current item in the collection
				Object entity = GetCurrentEntity();

				// perform delete
				Object[] args = GetArgs(entity);
				int count = 0;

				try
				{
					Object result = EntityUtil.InvokeMethod(Provider, DeleteMethod, args);

					if ( result == null || Convert.ToBoolean(result) )
					{
						count = 1;
						OnDeleted(new EntityDataSourceMethodEventArgs(entityList, EntityIndex, oldValues, count));
						RaiseChangedEvent();
					}
				}
				catch ( Exception ex )
				{
					EntityDataSourceMethodEventArgs e = new EntityDataSourceMethodEventArgs(entityList, EntityIndex, oldValues, count, ex);
					OnDeleted(e);

					if ( !e.ExceptionHandled )
					{
						throw;
					}
				}

				return count;
			}
示例#4
0
			/// <summary>
			/// Performs an update operation on the list of data
			/// that the EntityDataSourceView object represents.
			/// </summary>
			/// <param name="keys">An System.Collections.IDictionary of object or
			/// row keys to be updated by the update operation.</param>
			/// <param name="values">An System.Collections.IDictionary of name/value
			/// pairs that represent data elements and their original values.</param>
			/// <param name="oldValues">An System.Collections.IDictionary of name/value
			/// pairs that represent data elements and their new 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)
			{
				IEnumerable entityList = GetEntityList();
				ValidateEntity(entityList);

				// set the EntityIndex based on keys
				SetEntityIndex(entityList, keys);

				EntityDataSourceMethodEventArgs eventArgs = new EntityDataSourceMethodEventArgs(entityList, EntityIndex, values);
				OnUpdating(eventArgs);

				if ( eventArgs.Cancel )
				{
					return 0;
				}

				// get the current item in the collection
				Object entity = GetCurrentEntity();

				// raise linked event
				OnAfterUpdating(new LinkedDataSourceEventArgs(entity, values, EntityIndex));

				// set date/time values
				String[] names = GetUpdateDateTimeNames();
				EntityUtil.InitEntityDateTimeValues(entity, names);
				EntityUtil.SetEntityValues(entity, values);

				// perform update
				Object[] args = GetArgs(entity);
				int count = 0;

				try
				{
					Object result = EntityUtil.InvokeMethod(Provider, UpdateMethod, args);

					if ( result == null || Convert.ToBoolean(result) )
					{
						count = 1;
						UpdateEntityId(entityList);
						OnUpdated(new EntityDataSourceMethodEventArgs(entityList, EntityIndex, values, count));
						OnAfterUpdated(new LinkedDataSourceEventArgs(entity, values, EntityIndex));
						RaiseChangedEvent();
					}
				}
				catch ( Exception ex )
				{
					EntityDataSourceMethodEventArgs e = new EntityDataSourceMethodEventArgs(entityList, EntityIndex, values, count, ex);
					OnUpdated(e);

					if ( !e.ExceptionHandled )
					{
						throw;
					}
				}

				return count;
			}
示例#5
0
			/// <summary>
			/// Performs an insert operation on the list of data
			/// that the EntityDataSourceView object represents.
			/// </summary>
			/// <param name="values">A System.Collections.IDictionary of
			/// name/value pairs used during an insert operation.</param>
			/// <returns>The number of items that were inserted into the underlying data storage.</returns>
			protected override int ExecuteInsert(IDictionary values)
			{
				Object entity = GetNewEntity();
				IEnumerable entityList = new Object[] { entity };
				Guid entityId = Guid.Empty;

				ValidateEntity(entityList);

				EntityDataSourceMethodEventArgs eventArgs = new EntityDataSourceMethodEventArgs(entityList, 0, values);
				OnInserting(eventArgs);

				if ( eventArgs.Cancel )
				{
					return 0;
				}

				// raise linked event
				OnAfterInserting(new LinkedDataSourceEventArgs(entity, values, 0));

				// set date/time values
				String[] names = GetInsertDateTimeNames();
				EntityUtil.InitEntityDateTimeValues(entity, names);
				EntityUtil.SetEntityValues(entity, values);

				// set primary key value
				if ( !String.IsNullOrEmpty(EntityKeyName) )
				{
					entityId = EntityUtil.SetEntityKeyValue(entity, EntityKeyName);
				}

				// perform insert
				Object[] args = GetArgs(entity);
				int count = 0;

				try
				{
					Object result = EntityUtil.InvokeMethod(Provider, InsertMethod, args);

					if ( result == null || Convert.ToBoolean(result) )
					{
						count = 1;
						UpdateEntityId(entityList);
						OnInserted(new EntityDataSourceMethodEventArgs(entityList, 0, values, count));
						OnAfterInserted(new LinkedDataSourceEventArgs(entity, values, 0));
						RaiseChangedEvent();
					}
				}
				catch ( Exception ex )
				{
					EntityDataSourceMethodEventArgs e = new EntityDataSourceMethodEventArgs(entityList, 0, values, count, ex);
					OnInserted(e);

					if ( !e.ExceptionHandled )
					{
						throw;
					}
				}

				return count;
			}
示例#6
0
			/// <summary>
			/// Gets a list of data from the underlying data storage.
			/// </summary>
			/// <param name="arguments">A System.Web.UI.DataSourceSelectArguments that
			/// is used to request operations on the data beyond basic data retrieval.</param>
			/// <returns>An System.Collections.IEnumerable list of data from the underlying data storage.</returns>
			protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
			{
				arguments.RaiseUnsupportedCapabilitiesError(this);
				IEnumerable entityList = null;

				Hashtable param = new Hashtable();
				Object entityId = GetEntityId();

				if ( entityId != null )
				{
					String key = EntityKeyName ?? EntityDataSource.EntityIdParameterName;
					param.Add(key, entityId);
				}

				EntityDataSourceSelectingEventArgs eventArgs = new EntityDataSourceSelectingEventArgs(param, arguments);
				OnSelecting(eventArgs);

				if ( eventArgs.Cancel )
				{
					return null;
				}

				try
				{
					entityList = GetEntityList(arguments);

					if ( entityList != null )
					{
						IList list = EntityUtil.GetEntityList(entityList);

						// make sure we have a valid TotalRowCount
						if ( arguments.TotalRowCount < 1 )
						{
							arguments.TotalRowCount = list.Count;
						}

						UpdateEntityId(entityList);
						OnSelected(new EntityDataSourceMethodEventArgs(entityList, EntityIndex, param, arguments.TotalRowCount));

						if ( arguments.TotalRowCount > 0 && list.Count > 0 )
						{
							// raise linked event
							OnAfterSelected(new LinkedDataSourceEventArgs(list[EntityIndex], _owner.GetParameterValueMap(), EntityIndex));
						}
					}
				}
				catch ( Exception ex )
				{
					EntityDataSourceMethodEventArgs e = new EntityDataSourceMethodEventArgs(entityList, EntityIndex, param, 0, ex);
					OnSelected(e);

					if ( !e.ExceptionHandled )
					{
						throw;
					}
				}

				return entityList;
			}