Exemplo n.º 1
0
        /// <summary>
        /// Resets the errors.
        /// Used to clean the IDataErrorInfo when GUI cancels an Insert/Update operation.
        /// </summary>
        private void ResetErrors()
        {
            // current item
            OrderEntity entityToReseterrors = (OrderEntity)_ordersBinder.Current;

            // reset the field errors
            foreach (EntityField field in entityToReseterrors.Fields)
            {
                entityToReseterrors.SetEntityFieldError(field.Name, string.Empty, false);
            }

            // reset entity error
            entityToReseterrors.SetEntityError(string.Empty);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to validate the containing entity right before the save sequence for the entity will start. LLBLGen Pro will call this method right after the
        /// containing entity is selected from the save queue to be saved.
        /// </summary>
        /// <param name="involvedEntity">The involved entity.</param>
        public override void ValidateEntityBeforeSave(IEntityCore involvedEntity)
        {
            // variable to collect errors
            StringBuilder sbExceptionMessage = new StringBuilder();

            // order to validate. Cast depends upon the entity you are validating.
            OrderEntity toValidate = (OrderEntity)involvedEntity;


            #region Check validation rules.
            // ** shippedDate must be >= than the orderDate
            if (toValidate.ShippedDate != null && toValidate.ShippedDate < toValidate.OrderDate)
            {
                // add the error info to the message
                sbExceptionMessage.Append(SHIPPED_DATE_ERROR_MESSAGE + DELIMITER);
            }

            // ** requiredDate must be >= than the orderDate
            if (toValidate.RequiredDate != null && toValidate.RequiredDate < toValidate.OrderDate)
            {
                // add the error info to the message
                sbExceptionMessage.Append(REQUIRED_DATE_ERROR_MESSAGE + DELIMITER);
            }

            /// ** The orders must contain at least 1 item.
            /// Uncomment this if you want to enable this validation
            //if (!(toValidate.OrderDetails.Count > 0))
            //{
            //    sbExceptionMessage.Append(ORDER_DETAILS_ERROR_MESSAGE + DELIMITER);
            //}

            // -- add more validations --
            // ...
            #endregion

            // get the errors collected
            string strExceptionMessage = sbExceptionMessage.ToString();

            // Do exist any break rule in this entity?
            if (strExceptionMessage != string.Empty)
            {
                // set error info so we can access that outside
                toValidate.SetEntityError(strExceptionMessage);

                // throws an exception with all the breaking rules info
                throw new ORMEntityValidationException(strExceptionMessage, toValidate);
            }
        }