Exemplo n.º 1
0
        private static bool CheckFromUIValue(string fieldName, Enums.Operator op, string value, SPFormContext formContext, string clientID)
        {
            BaseFieldControl field = ValidationInjector.GetFieldControlByName(fieldName, formContext, clientID);

            // to manage the rich field UI text
            if (field is RichTextField)
            {
                string fieldVaue = ((RichTextField)field).HiddenInput.Value;

                switch (op)
                {
                case Enums.Operator.Equal:
                    return(fieldVaue.Equals(value));

                case Enums.Operator.NotEqual:
                    return(!fieldVaue.Equals(value));

                case Enums.Operator.Contains:
                    return(fieldVaue.Contains(value));

                case Enums.Operator.NotContains:
                    return(!fieldVaue.Contains(value));

                default:
                    return(false);
                }
            }
            else
            {
                if (field is LookupField)
                {
                    LookupField l = field as LookupField;
                    String      v = l.Value.ToString();
                }

                return(MatchItemValueBasedOnOperatorAndValueType(op, value, field.Value, field.Field.FieldValueType));
            }
        }
Exemplo n.º 2
0
        public void Validate()
        {
            FieldValidations allFieldVals = FieldValidations.LoadFieldValidations(GetConfigFile(Constants.ConfigFile.FieldValidationFile));

            if (base.ControlMode != SPControlMode.Display && allFieldVals != null)
            {
                #region Test data
                //allFieldVals.Add(new FieldValidation(new Field("Title"), Enums.ValidationRule.Column, Enums.Operator.Equal, "adil", "error for adil", "", Enums.Operator.None));
                //allFieldVals.Add(new FieldValidation(new Field("Status"), Enums.ValidationRule.Column, Enums.Operator.Contains, "Start", "error for start", "", Enums.Operator.None));
                //allFieldVals.Add(new FieldValidation(new Field("Title"), Enums.ValidationRule.Pattern, Enums.Operator.Equal, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", "not valid email", "pc\\pdadmin", Enums.Operator.Equal));
                //allFieldVals.Add(new FieldValidation(new Field("Predecessors"), Enums.ValidationRule.Column, Enums.Operator.Contains, "adil", "contains adil", "pc\\pdadmin", Enums.Operator.Equal));
                #endregion

                bool isErroredField = false;
                foreach (FieldValidation v in allFieldVals)
                {
                    if (ConditionEvaluator.EvaluateFromUIValue(v.Conditions, _formContext, ClientID) && PrincipalEvaluator.Check(v.ForSPPrinciples, v.BySPPrinciplesOperator))
                    {
                        BaseFieldControl field = ValidationInjector.GetFieldControlByName(v.OnField.SPName, _formContext, ClientID);

                        if (field != null)
                        {
                            switch (v.Rule)
                            {
                            case Enums.ValidationRule.Column:
                                if (ValidationInjector.InvalidColumnValue(field.Value, v.ByRuleOperator, v.Value.ToString(), field.Field.FieldValueType))
                                {
                                    ValidationInjector.SetValidationError(field, v.ErrorMsg); isErroredField = true;
                                }
                                break;

                            case Enums.ValidationRule.length:
                                int length = (field.Value == null ? 0 : field.Value.ToString().Length);
                                if (ValidationInjector.InvalidLengthValue(length, v.ByRuleOperator, v.Value.ToString()))
                                {
                                    ValidationInjector.SetValidationError(field, v.ErrorMsg); isErroredField = true;
                                }
                                break;

                            case Enums.ValidationRule.Pattern:
                                if (ValidationInjector.InvalidPatternValue((field.Value ?? "").ToString(), v.Value.ToString()))
                                {
                                    ValidationInjector.SetValidationError(field, v.ErrorMsg); isErroredField = true;
                                }
                                break;
                            }
                        }

                        if (allTabs != null)
                        {
                            string tabname = allTabs.GetTabNameOfField(v.OnField.SPName);
                            if (isErroredField && !string.IsNullOrEmpty(tabname))
                            {
                                this.Page.ClientScript.RegisterStartupScript(base.GetType(), "SLFE_UpdatePanelHelper", string.Concat(new string[]
                                {
                                    "<script type='text/javascript'>g_SLFEUpdatePanelHelper='",
                                    this.updatePanelIterator.ClientID,
                                    "';\r\ng_RequestResultTabsInfoHidden = '",
                                    this.RequestResultTabsInfoHidden.ClientID,
                                    "';\r\nSys.WebForms.PageRequestManager.getInstance().add_pageLoaded(SLFE_OnClientResponseEnded);\r\n</script>"
                                }));
                                this.Page.ClientScript.RegisterStartupScript(base.GetType(), "SLFE_CallFirstSelectTab", "<script type='text/javascript'>SLFE_SelectTab('" + allTabs.GetTabNameOfField(v.OnField.SPName) + "')</script>");
                            }
                        }
                    }
                }
            }
        }