コード例 #1
0
        /// <summary>
        /// Handles the LLBLGenProDataSource PerformWork Event which is raised when LivePersistence is set to false and an insert/update/delete has to be performed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ProductsDS_PerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
        {
            // indicate whether or not the entity is valid (corresponding to entity validation)
            bool entityToUpdateIsValid = true;

            // Get the entityToDelete from UOW
            // If found, get the entity to be deleted from the UnitOfWork object.
            ProductEntity             entityToDelete = null;
            List <UnitOfWorkElement2> deleteItems    = e.Uow.GetEntityElementsToDelete();

            if (deleteItems.Count > 0)
            {
                entityToDelete = (ProductEntity)deleteItems[0].Entity;
            }

            // Get the entityToUpdate from UOW
            ProductEntity entityToUpdate = null;
            // If found, get the entity to be updated from the UnitOfWork object.
            List <UnitOfWorkElement2> updateItems = e.Uow.GetEntityElementsToUpdate();

            if (updateItems.Count > 0)
            {
                entityToUpdate = (ProductEntity)updateItems[0].Entity;
            }

            // Commit the LLBLGenProDataSource UnitOfWork.
            DataAccessAdapter adapter = new DataAccessAdapter();

            try
            {
                // commit the work
                e.Uow.Commit(adapter, true);

                // everything OK lets hide the error controls
                HideEntityErrorControls();
            }
            catch (ORMEntityValidationException ex)
            {
                // oops, something is invalid, lets show the info to the user
                ShowEntityErrors(ex.Message);
                entityToUpdateIsValid = false;
            }

            // After save/update acknowledges
            // Show a message to acknowledge a Delete.
            if (entityToDelete != null && entityToUpdateIsValid)
            {
                // check if the entity was deleted, by checking the entity.Fields.State field.
                if (entityToDelete.Fields.State == EntityState.Deleted)
                {
                    Message.Text = "The record was successfully deleted.";
                }
                else
                {
                    Message.Text = "Product with ID = " + entityToDelete.ProductId + " could not be deleted.";
                }
            }

            // Show a message to acknowledge an update.
            if (entityToUpdate != null && entityToUpdateIsValid)
            {
                Message.Text = "Product with ID = " + entityToUpdate.ProductId + " was successfully updated.";
            }
        }
コード例 #2
0
 /// <summary>
 /// Handles the LLBLGenProDataSource PerformWork Event which is raised when LivePersistence is set to false and an insert/update/delete has to be performed.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void EmployeesListDS_PerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
 {
     //nothing is done to be persisted. The GridView is used only for Viewing.
     // INSERT, Update and Delete are done with the FormView.
 }