public static void SetDefault(SPField field, FieldDefaults allFieldDefaults) { if (allFieldDefaults.Count > 0) { foreach (FieldDefault fd in allFieldDefaults) { if (fd.OnField.SPName == field.InternalName) { if (PrincipalEvaluator.Check(fd.ForSPPrinciples, fd.BySPPrinciplesOperator)) { field.DefaultValue = fd.Value.ToString(); break; } } } } }
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>"); } } } } } }
public static SPControlMode Handle(string spInternalName, SPControlMode formMode, Tabs tabs, FieldPermissions fPerms, SPPrincipal princ, out bool isHidden) { SPControlMode result = SPControlMode.Invalid; isHidden = false; if (tabs != null) { foreach (Tab tab in tabs) { foreach (TabPermission tp in tab.Permissions) { if (ConditionEvaluator.EvaluateFromListItem(tp.Conditions) && PrincipalEvaluator.Check(tp.ForSPPrinciples, tp.BySPPrinciplesOperator)) { if (tab.Fields.Any <Field> (f => f.SPName.Equals(spInternalName, StringComparison.InvariantCultureIgnoreCase))) { if (tp.OnForms.Contains(Enums.SPForms.New) && formMode == SPControlMode.New || tp.OnForms.Contains(Enums.SPForms.View) && formMode == SPControlMode.Display || tp.OnForms.Contains(Enums.SPForms.Edit) && formMode == SPControlMode.Edit) { switch (tp.Level) { case Enums.PermissionLevel.Read: result = SPControlMode.Display; isHidden = false; break; case Enums.PermissionLevel.Write: if (formMode == SPControlMode.Edit) { result = SPControlMode.Edit; } else { result = SPControlMode.New; } isHidden = false; break; case Enums.PermissionLevel.Deny: isHidden = true; result = SPControlMode.Invalid; break; } } } } } } } //FieldPermissionCheck: if (fPerms != null) { foreach (FieldPermission fp in fPerms) { if (ConditionEvaluator.EvaluateFromListItem(fp.Conditions) && PrincipalEvaluator.Check(fp.ForSPPrinciples, fp.BySPPrinciplesOperator)) { if (fp.OnField.SPName.Equals(spInternalName, StringComparison.InvariantCultureIgnoreCase)) { if (fp.OnForms.Contains(Enums.SPForms.New) && formMode == SPControlMode.New || fp.OnForms.Contains(Enums.SPForms.View) && formMode == SPControlMode.Display || fp.OnForms.Contains(Enums.SPForms.Edit) && formMode == SPControlMode.Edit) { switch (fp.Level) { case Enums.PermissionLevel.Read: result = SPControlMode.Display; isHidden = false; goto FinishPermissionCheck; case Enums.PermissionLevel.Write: if (formMode == SPControlMode.Edit) { result = SPControlMode.Edit; } else { result = SPControlMode.New; } isHidden = false; goto FinishPermissionCheck; case Enums.PermissionLevel.Deny: isHidden = true; result = SPControlMode.Invalid; break; } } } } } } FinishPermissionCheck: return(result); }