Exemplo n.º 1
0
        void DataCommandValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            bool IsValid = false;
            DataCommandService dataCommand = DataCommandService.GetInstance();
            PageDB             pageDB      = new PageDB();

            try
            {
                CustomDataCommandValidator        validator  = (CustomDataCommandValidator)source;
                List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(validator.DataCommand, ((CodeTorch.Web.Templates.BasePage) this.Page));

                if (validator.UseValueParameter)
                {
                    ScreenDataCommandParameter valueParameter = parameters.Where(p =>
                                                                                 (
                                                                                     (p.Name.ToLower() == validator.ValueParameter.ToLower())
                                                                                 )
                                                                                 )
                                                                .SingleOrDefault();

                    if (valueParameter != null)
                    {
                        valueParameter.Value = args.Value;
                    }
                }

                DataTable data = dataCommand.GetDataForDataCommand(validator.DataCommand, parameters);

                if (data.Rows.Count == 1)
                {
                    if (validator.UseErrorMessageField)
                    {
                        if (String.IsNullOrEmpty(validator.ErrorMessageField))
                        {
                            throw new ApplicationException(String.Format("ErrorMessageField for validator {0} is not configured", validator.ID));
                        }
                        else
                        {
                            if (data.Columns.Contains(validator.ErrorMessageField))
                            {
                                validator.ErrorMessage = data.Rows[0][validator.ErrorMessageField].ToString();
                            }
                        }
                    }

                    if (data.Columns.Contains(validator.ValidationField))
                    {
                        IsValid = Convert.ToBoolean(data.Rows[0][validator.ValidationField]);
                    }
                }
            }
            catch (Exception ex)
            {
                args.IsValid = false;
                ((System.Web.UI.WebControls.BaseValidator)source).ErrorMessage = "Validator: " + ex.Message;
            }

            args.IsValid = IsValid;
        }
Exemplo n.º 2
0
        private System.Web.UI.WebControls.BaseValidator GetValidator(Widget control, Core.BaseValidator validator)
        {
            System.Web.UI.WebControls.BaseValidator retVal = null;
            //string validationErrorMessage = null;
            //string validationResourceKeyPrefix = String.Format("", this.ResourceKeyPrefix, validator.Name)
            //validationErrorMessage = GetGlobalResourceString("", compareConfig.ErrorMessage);

            switch (validator.GetType().Name.ToLower())
            {
            case "comparevalidator":
                Core.CompareValidator compareConfig = (Core.CompareValidator)validator;
                System.Web.UI.WebControls.CompareValidator compareActual = new System.Web.UI.WebControls.CompareValidator();

                compareActual.ID      = compareConfig.Name;
                compareActual.Display = ValidatorDisplay.None;


                compareActual.ErrorMessage      = compareConfig.ErrorMessage;
                compareActual.Text              = "*";
                compareActual.ControlToValidate = control.Name;

                //validator specific
                compareActual.Type             = compareConfig.Type;
                compareActual.ControlToCompare = compareConfig.ControlToCompare;
                compareActual.Operator         = compareConfig.Operator;
                compareActual.ValueToCompare   = compareConfig.ValueToCompare;

                retVal = (System.Web.UI.WebControls.BaseValidator)compareActual;

                break;

            case "datacommandvalidator":
                Core.DataCommandValidator  dataConfig = (Core.DataCommandValidator)validator;
                CustomDataCommandValidator dataActual = new CustomDataCommandValidator();

                dataActual.ID      = dataConfig.Name;
                dataActual.Display = ValidatorDisplay.None;

                dataActual.ErrorMessage      = dataConfig.ErrorMessage;
                dataActual.Text              = "*";
                dataActual.ControlToValidate = control.Name;

                //validator specific
                dataActual.DataCommand          = dataConfig.DataCommand;
                dataActual.ValidationField      = dataConfig.ValidationField;
                dataActual.UseValueParameter    = dataConfig.UseValueParameter;
                dataActual.ValueParameter       = dataConfig.ValueParameter;
                dataActual.UseErrorMessageField = dataConfig.UseErrorMessageField;
                dataActual.ErrorMessageField    = dataConfig.ErrorMessageField;

                dataActual.ServerValidate += new ServerValidateEventHandler(DataCommandValidator_ServerValidate);

                retVal = (System.Web.UI.WebControls.BaseValidator)dataActual;
                break;

            case "regularexpressionvalidator":
                Core.RegularExpressionValidator regexpConfig = (Core.RegularExpressionValidator)validator;
                System.Web.UI.WebControls.RegularExpressionValidator regexpActual = new System.Web.UI.WebControls.RegularExpressionValidator();

                regexpActual.ID      = regexpConfig.Name;
                regexpActual.Display = ValidatorDisplay.None;

                regexpActual.ErrorMessage      = regexpConfig.ErrorMessage;
                regexpActual.Text              = "*";
                regexpActual.ControlToValidate = control.Name;

                //validator specific
                regexpActual.ValidationExpression = regexpConfig.ValidationExpression;

                retVal = (System.Web.UI.WebControls.BaseValidator)regexpActual;
                break;

            case "rangevalidator":
                Core.RangeValidator rangeConfig = (Core.RangeValidator)validator;
                System.Web.UI.WebControls.RangeValidator rangeActual = new System.Web.UI.WebControls.RangeValidator();

                rangeActual.ID      = rangeConfig.Name;
                rangeActual.Display = ValidatorDisplay.None;

                rangeActual.ErrorMessage      = rangeConfig.ErrorMessage;
                rangeActual.Text              = "*";
                rangeActual.ControlToValidate = control.Name;

                //validator specific
                rangeActual.Type         = rangeConfig.Type;
                rangeActual.MinimumValue = rangeConfig.MinimumValue;
                rangeActual.MaximumValue = rangeConfig.MaximumValue;

                retVal = (System.Web.UI.WebControls.BaseValidator)rangeActual;
                break;
            }

            return(retVal);
        }