Exemplo n.º 1
0
        public override bool Validate(ValidateCallback callback, StateHolder state)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (sourceLocationId <= 0)
            {
                if (!callback(Translator.GetString("Source location cannot be empty!"), ErrorSeverity.Error, (int)ErrorCodes.SourceLocationEmpty, state))
                {
                    return(false);
                }
            }

            if (BusinessDomain.LoggedUser.LockedLocationId > 0 && BusinessDomain.LoggedUser.LockedLocationId != sourceLocationId)
            {
                if (!callback(Translator.GetString("The source location cannot be used!"), ErrorSeverity.Error, (int)ErrorCodes.SourceLocationCannotBeUsed, state))
                {
                    return(false);
                }
            }

            string error;
            string warning;

            if (!BusinessDomain.CanUseLocationInOperation(OperationType, sourceLocationId, out error, out warning))
            {
                if (error != null && !callback(error, ErrorSeverity.Error, (int)ErrorCodes.SourceLocationCannotBeUsed, state))
                {
                    return(false);
                }

                if (warning != null && !callback(error, ErrorSeverity.Warning, (int)ErrorCodes.SourceLocationCannotBeUsed, state))
                {
                    return(false);
                }
            }

            if (targetLocationId <= 0)
            {
                if (!callback(Translator.GetString("Target location cannot be empty!"), ErrorSeverity.Error, (int)ErrorCodes.TargetLocationEmpty, state))
                {
                    return(false);
                }
            }

            if (details.Any(d => d.Quantity.IsZero()))
            {
                if (!callback(Translator.GetString("Details contain zero quantities!"), ErrorSeverity.Error, (int)ErrorCodes.TargetLocationEmpty, state))
                {
                    return(false);
                }
            }

            return(true);
        }