/// <summary> /// Initializes a new instance of the <see cref="ValidationMessage"/> class using an existing validation message. /// </summary> /// <param name="message"> /// Existing validation message, whose properties should be taken. /// </param> /// <param name="validationMessageKind"> /// The validation message kind which indicates what kind of validation has been performed (property or entity based). /// If no value is provided, <c>message.ValidationMessageKind</c> will be taken. /// </param> public ValidationMessage(ValidationMessage message, ValidationMessageKind? validationMessageKind = null) : this(message.ValidationLevel, message.MessageText, message.ShowMessageOnProperty, message.ShowMessageInSummary, validationMessageKind ?? message.ValidationMessageKind) { }
/// <summary> /// Constructor with initialization. Shallow copy. /// </summary> /// <param name="arrayOfValues">values to copy.</param> /// <exception cref="System.ArgumentNullException">Argument <c>arrayOfValues</c> is a <see langword="null"/> reference.</exception> public ValidationMessageCollection( ValidationMessage[] arrayOfValues) { if (arrayOfValues == null) throw new System.ArgumentNullException(); foreach (ValidationMessage value in arrayOfValues) this.Add(value); }
// Validates a single script. ValidationMessage[] ValidateFile(TextAsset script, Analysis.Context analysisContext, out CheckerResult.State result) { var messageList = new List<ValidationMessage>(); var variableStorage = new Yarn.MemoryVariableStore(); var dialog = new Dialogue(variableStorage); bool failed = false; dialog.LogErrorMessage = delegate (string message) { var msg = new ValidationMessage(); msg.type = MessageType.Error; msg.message = message; messageList.Add(msg); // any errors means this validation failed failed = true; }; dialog.LogDebugMessage = delegate (string message) { var msg = new ValidationMessage(); msg.type = MessageType.Info; msg.message = message; messageList.Add(msg); }; try { dialog.LoadString(script.text,script.name); } catch (System.Exception e) { dialog.LogErrorMessage(e.Message); } dialog.Analyse(analysisContext); if (failed) { result = CheckerResult.State.Failed; } else { result = CheckerResult.State.Passed; } return messageList.ToArray(); }
/// <summary> /// Invokes the ValidationMessage event. /// </summary> /// <param name="e">ValidationMessageEventArgs object.</param> public virtual void OnValidationMessage(ValidationMessageEventArgs e) => ValidationMessage?.Invoke(this, e);
public override Option <ValidationMessage> Execute(ModelEntity e) { return(from element in e.TryCast <ModelEntity.Element>() where !ElementIdsWithDiagrams.Contains(element.Id) select ValidationMessage.Information("Element not used in a Diagram")); }
private void SetRequired() { #region MethodOfEntry required when Offense has a UCR code of 220, 23F, 23G, or 240 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "methodOfEntry"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); ValidationMessage = new ValidationMessage(string.Format("{0} required when Offense has a UCR code of 220, 23F, 23G, or 240", TargetFieldLabel), "methodOfEntry"); TargetField = new ValidationField { FieldPath = "methodOfEntry", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(), new List <string> { "220", "23F", "23G", "240" }) .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); ValidationRule.ValidationId = string.Format("{0} is required when {1} has a UCR Code of 220", TargetFieldLabel, AssociatedField1Label); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region MethodOfEntry can only be entered if Offense is 220, 23F, 23G, or 240 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "methodOfEntry"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); ValidationMessage = new ValidationMessage(String.Format("{0} can only be entered if Offense is 220, 23F, 23G, or 240", TargetFieldLabel), "methodOfEntry"); TargetField = new ValidationField { FieldPath = "methodOfEntry", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(ValidationField.ViolationCodeOffenses(), new List <string> { "220", "23F", "23G", "240" }) .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); ValidationRule.ValidationId = string.Format("{0} must be blank when {1} does NOT have a UCR Code of 220", TargetFieldLabel, AssociatedField1Label); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region SecondLocationType required when LocationType is 18 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "secondLocationType"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "offenseLocationType"); ValidationMessage = new ValidationMessage(string.Format("{0} required when {1} is 18", TargetFieldLabel, AssociatedField1Label), "secondLocationType"); TargetField = new ValidationField { FieldPath = "secondLocationType", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "offenseLocationType", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField).Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "18" }) .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion }
void ShowLogIn() { var tempBottomRect = bottomRect; tempBottomRect.yMin += tempBottomRect.height * .1f; SmallLabel.fontSize = Screen.width / 28;; GUI.Label(topRect, "UserName", SmallLabel); GUI.Label(tempBottomRect, "Password", SmallLabel); loginUserName.transform.position = new Vector3(backgroundRect.x + backgroundRect.width * .5f, Screen.height - topRect.y - topRect.height * .5f, 1); loginPassword.transform.position = new Vector3(backgroundRect.x + backgroundRect.width * .5f, Screen.height - bottomRect.y - bottomRect.height * .6f, 1); //EnableInputBackground(); var username = loginUserName.GetComponent <InputField>().text; var password = loginPassword.GetComponent <InputField>().text; if (singupHasSubmittedAtleastOnce) { HasEmptyLoginFields(username, password); } var button = transform.Find("LoginButton").GetComponent <SubmitButton>(); button.isEnabled = true; //button.position = new Vector3(backgroundRect.x + backgroundRect.width * .18f, backgroundRect.y + backgroundRect.height * .75f); //button.size = new Vector2(backgroundRect.width * .6f, backgroundRect.height * .15f); if (button.WasPressed) { button.WasPressed = false; loginHasSubmittedAtleastOnce = true; currentValidationMessage = loginPassword.GetComponent <ValidationMessage>(); currentValidationMessage.isEnabled = false; if (HasEmptyLoginFields(username, password)) { return; } int index = serverRequestsInUse; serverRequestsInUse++; TryGetProfile(index, username: username, password: password, setUserProfile: true); if (!tryGetProfileServerRequests[index]) { Debug.Log("Cannont find profile with Username = '******' and Password '" + loginPassword.GetComponent <InputField>().text + "'."); loginPassword.GetComponent <InputField>().text = string.Empty; currentValidationMessage = loginPassword.GetComponent <ValidationMessage>(); currentValidationMessage.isEnabled = true; } else { show = false; UserProfile.IsLoggedIn = true; } serverRequestsInUse--; } }
/// <summary> /// Report added messages to the task list. /// </summary> /// <param name="addedMessage"></param> /// <remarks> /// methods are called in this order: /// 1. OnValidationMessagesChanging /// 2. OnValidationMessageRemoved - called once for each message removed. /// 3. OnValidationMessageAdded - called once for each message added. /// 4. OnValidationMessagesChangedSummary /// </remarks> protected override void OnValidationMessageAdded(ValidationMessage addedMessage) { var task = new ProductStoreValidationTask((ProductStoreTaskValidationMessage)addedMessage); this.TaskProvider.Tasks.Add(task); }
private void SetComparisons() { #region Date Received must be on or before the Incident Start Date/Time TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.INCIDENT_EVENT, "dateReceived"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.INCIDENT_EVENT, "startDate"); TargetField = new ValidationField { FieldPath = "dateReceived", SectionName = GenericSectionName.INCIDENT_EVENT, ControlType = ControlType.Date, Mask = Mask.DateTime, CompareToMask = Mask.DateTime }; AssociatedField1 = new ValidationField { FieldPath = "startDate", SectionName = GenericSectionName.INCIDENT_EVENT, ControlType = ControlType.Date, Mask = Mask.DateTime, CompareToMask = Mask.DateTime }; ValidationMessage = new ValidationMessage { Message = string.Format("{0} must be on or before the {1}", TargetFieldLabel, AssociatedField1Label), TargetPath = "dateReceived" }; ValidationRule = new Validation(ValidationMessage, TargetField).Comparison(ValidationOperand.LessThanEqual).ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); ValidationRule = null; #endregion #region Incident Start Date/Time must be on or before the Incident End Date/Time TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.INCIDENT_EVENT, "startDate"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.INCIDENT_EVENT, "endDate"); TargetField = new ValidationField { FieldPath = "startDate", SectionName = GenericSectionName.INCIDENT_EVENT, ControlType = ControlType.Date, Mask = Mask.DateTime, CompareToMask = Mask.DateTime }; AssociatedField1 = new ValidationField { FieldPath = "endDate", SectionName = GenericSectionName.INCIDENT_EVENT, ControlType = ControlType.Date, Mask = Mask.DateTime, CompareToMask = Mask.DateTime }; ValidationMessage = new ValidationMessage { Message = string.Format("{0} must be on or before the {1}", TargetFieldLabel, AssociatedField1Label), TargetPath = "startDate" }; ValidationRule = new Validation(ValidationMessage, TargetField).Comparison(ValidationOperand.LessThanEqual).ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); ValidationRule = null; #endregion }
private void SetRequired() { #region TimeOfDay is required when ViolationCode has a UCR Class of 05 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "timeOfDay"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); ValidationMessage = new ValidationMessage( string.Format("'You Must Enter In {0} If The Offense Is A Burglary", TargetFieldLabel), "timeOfDay"); TargetField = new ValidationField { FieldPath = "timeOfDay", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), new List <string> { "05" }) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region Structure should be left blank when UCR Class is 08 (Arson) and Sub Class is j,h, or i TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "structure"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); ucrClassList = new List <string> { "08" }; ucrSubclassList = new List <string> { "j.", "h.", "i." }; ValidationMessage = new ValidationMessage { Message = string.Format("{0} should be left blank for Arson offenses not involving structures", TargetFieldLabel), TargetPath = "structure" }; TargetField = new ValidationField { FieldPath = "structure", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; ValidationRule = new Validation( ValidationMessage, TargetField) .NotRequired() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .Contains(ValidationField.ViolationCodeOffenses(ucrSubclassProperty), ucrSubclassList) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region Value is required when Status is S (Property, Guns) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "value"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("If {0} is stolen, {1} is required", AssociatedField1Label, TargetFieldLabel), "value"); TargetField = new ValidationField { FieldPath = "value", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Text, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "S" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} is required when {1} is 'S'", TargetFieldLabel, AssociatedField1Label), "value"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "S" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region RecoveredValue can only be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "recoveredValue"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveredValue"); TargetField = new ValidationField { FieldPath = "recoveredValue", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Text, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveredValue"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); // Vehicles TargetField.SectionName = GenericSectionName.VEHICLES; AssociatedField1.SectionName = GenericSectionName.VEHICLES; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveredValue"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); #endregion #region RecoveryDateTime can only be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "recoveryDateTime"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); TargetField = new ValidationField { FieldPath = "recoveryDateTime", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Date, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); // Vehicles TargetField.SectionName = GenericSectionName.VEHICLES; AssociatedField1.SectionName = GenericSectionName.VEHICLES; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); #endregion #region RecoveredDate must be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "recoveryDateTime"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); TargetField = new ValidationField { FieldPath = "recoveryDateTime", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Date, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); // Vehicles TargetField.SectionName = GenericSectionName.VEHICLES; AssociatedField1.SectionName = GenericSectionName.VEHICLES; ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); #endregion #region EstimatedValue must be entered when Status is S or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "estimatedValue"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Stolen' or 'Stolen/Recovered", TargetFieldLabel, AssociatedField1Label), "estimatedValue"); TargetField = new ValidationField { FieldPath = "estimatedValue", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Text, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "S", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region VehicleRecovery must be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "vehicleRecovery"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "vehicleRecovery"); TargetField = new ValidationField { FieldPath = "vehicleRecovery", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region Person Number cannot be blank (Suspect) UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("{0} is required", ResolveFieldLabel(TemplateReference, GenericSectionName.SUSPECTS, "personNumber")), TargetPath = "personNumber" }, new ValidationField { FieldPath = "personNumber", SectionName = GenericSectionName.SUSPECTS, ControlType = ControlType.Text }) .Required().ImplementStateValidationRule()); #endregion #region Person Number cannot be 0 (Victim) // this rule was broken in 2 rules to handle more than one operation TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "personNumber"); ValidationMessage = new ValidationMessage(string.Format("{0} cannot be '0'", TargetFieldLabel), "personNumber"); TargetField = new ValidationField { FieldPath = "personNumber", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Text }; ValidationRule = new Validation(ValidationMessage, TargetField) .Comparison(ValidationOperand.NotEqual, "0") .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); #endregion #region 'If Person Number is Not 0, Age or Sex or Race Must be Known TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "personNumber"); var ageLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "age"); var raceLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "race"); var sexLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "sex"); ValidationMessage = new ValidationMessage(string.Format("If {0} is Not 0, {1} or {2} or {3} Must be Known", TargetFieldLabel, ageLabel, raceLabel, sexLabel), "personNumber"); TargetField = new ValidationField { FieldPath = "personNumber", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Text }; var AgeField = new ValidationField { FieldPath = "age", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Code }; var RaceField = new ValidationField { FieldPath = "race", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Code }; var SexField = new ValidationField { FieldPath = "sex", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .Comparison(ValidationOperand.Equal, "0") .WithConditions() .NotRequired(AgeField) .NotRequired(SexField) .NotRequired(RaceField) .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AgeField, ValidationRule)); UcrValidationRules.Add(Validation.CreateAssociatedRule(RaceField, ValidationRule)); UcrValidationRules.Add(Validation.CreateAssociatedRule(SexField, ValidationRule)); #endregion #region Status must be entered (Property, Guns) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage(string.Format("Must Enter {0}", TargetFieldLabel), "status"); TargetField = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .ThatBroadcasts() .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage(string.Format("Must Enter {0}", TargetFieldLabel), "status"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .RelatedOffenseRequired() .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region Type must be entered (Property, Guns) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "type"); ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "type"); TargetField = new ValidationField { FieldPath = "type", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .RelatedOffenseRequired() .ThatBroadcasts() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "type"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .RelatedOffenseRequired() .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region Must Enter a Weapon if UCR Class is 01a TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); ucrClassList = new List <string>() { "01" }; ucrSubclassList = new List <string>() { "a." }; ValidationMessage = new ValidationMessage( string.Format("If UCR code is 01a, Weapon Must Be Entered", TargetFieldLabel), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .Contains(ValidationField.ViolationCodeOffenses(ucrSubclassProperty), ucrSubclassList) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region Cannot enter a Weapon if UCR Class is 24 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); ucrClassList = new List <string>() { "24" }; ValidationMessage = new ValidationMessage(string.Format("Cannot enter a {0} if UCR Class is '24'", TargetFieldLabel), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region WeaponTypes must be 06 when ViolationCode has a UCR Class of 04 and Subclass of b -- per PM, needs to fire when no weapon is entered as well TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); classList = new List <string> { "06" }; ucrClassList = new List <string> { "04" }; ucrSubclassList = new List <string> { "b." }; ValidationMessage = new ValidationMessage(string.Format("If UCR code is 04b, the weapon must be 'Knife or other cutting or stabbing instrument'"), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .Contains(ValidationField.ViolationCodeOffenses(ucrSubclassProperty), ucrSubclassList) .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.ViolationCodeOffenses()).ThatBroadcasts().ImplementStateValidationRule()); #endregion }
private void SetRequired() { #region Arrest Disposition must be entered when the Juvenile dropdown is set to no TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "arrestDisposition"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "juvenile"); ValidationMessage = new ValidationMessage(string.Format("{0} is required for adult arrests", TargetFieldLabel, AssociatedField1Label), "arrestDisposition"); TargetField = new ValidationField { FieldPath = "arrestDisposition", FieldType = FieldType.Extended, SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "juvenile", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "N" }) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion #region Must enter arresting agency name TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "arrestingAgencyName"); ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "arrestingAgencyName"); TargetField = new ValidationField { FieldPath = "arrestingAgencyName", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); #endregion #region Must enter felony/misdemeanor TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "felonyMisdemeanor"); ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "felonyMisdemeanor"); TargetField = new ValidationField { FieldPath = "felonyMisdemeanor", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); #endregion #region Must enter law enforcement disposition TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "lawEnforcementDisposition"); ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "lawEnforcementDisposition"); TargetField = new ValidationField { FieldPath = "lawEnforcementDisposition", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); #endregion }
private void SetContains() { #region Sex must be M or F TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "sex"); UcrValidationRules.Add(new Validation( new ValidationMessage { Message = string.Format("{0} must be M or F", TargetFieldLabel), TargetPath = "sex" }, new ValidationField { FieldPath = "sex", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code, }).Contains(new List <string> { "M", "F" }).ImplementStateValidationRule()); #endregion #region Arrestee race cannot be U-Unknown TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "race"); UcrValidationRules.Add(new Validation( new ValidationMessage { Message = string.Format("Arrestee {0} cannot be U-Unknown", TargetFieldLabel), TargetPath = "race" }, new ValidationField { FieldPath = "race", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code, }).DoesNotContain(new List <string> { "X" }).ImplementStateValidationRule()); #endregion #region Law Enforcement Disposition cannot be "Felonies" if Fel/Mis is "M TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "lawEnforcementDisposition"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "felonyMisdemeanor"); ValidationMessage = new ValidationMessage(string.Format("{0} cannot be 'Felonies' if {1} is 'Misdemeanor'", TargetFieldLabel, AssociatedField1Label), "lawEnforcementDisposition"); TargetField = new ValidationField { FieldPath = "lawEnforcementDisposition", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "felonyMisdemeanor", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .DoesNotContain(new List <string> { "4" }) //FELONIES .WithConditions() .Contains(AssociatedField1, new List <string> { "2" }) //MISDEMEANOR .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion #region Law Enforcement Disposition cannot be "Misdemeanors" if Fel/Mis is "F TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "lawEnforcementDisposition"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "felonyMisdemeanor"); ValidationMessage = new ValidationMessage(string.Format("{0} cannot be 'Misdemeanors' if {1} is 'Felony'", TargetFieldLabel, AssociatedField1Label), "lawEnforcementDisposition"); TargetField = new ValidationField { FieldPath = "lawEnforcementDisposition", FieldType = FieldType.Extended, SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "felonyMisdemeanor", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .DoesNotContain(new List <string> { "3" }) //MISDEMEANORS .WithConditions() .Contains(AssociatedField1, new List <string> { "3" }) //FELONY .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion #region Law Enforcement Disposition must be 2, 4, 5 for Juveniles TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "lawEnforcementDisposition"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "juvenile"); ValidationMessage = new ValidationMessage(string.Format("{0} for Juveniles can only be Turned Over, Juvenile Court, or Department", TargetFieldLabel), "lawEnforcementDisposition"); TargetField = new ValidationField { FieldPath = "lawEnforcementDisposition", FieldType = FieldType.Extended, SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "juvenile", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Contains(new List <string> { "2", "5", "6" }) //TURNED OVER, JUVENILE COURT, DEPARTMENT .WithConditions() .Contains(AssociatedField1, new List <string> { "Y" }) //JUVENILE .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion }
private void SetRequired() { #region Race is required UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("{0} is required", ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "race")), TargetPath = "race" }, new ValidationField { FieldPath = "race", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code }) .Required().ImplementStateValidationRule()); #endregion #region Sex is required UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("{0} is required", ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "sex")), TargetPath = "sex" }, new ValidationField { FieldPath = "sex", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code }) .Required().ImplementStateValidationRule()); #endregion #region Age is required UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("{0} is required", ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age")), TargetPath = "age" }, new ValidationField { FieldPath = "age", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code }) .Required().ImplementStateValidationRule()); #endregion #region Ethnicity is required UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("{0} is required", ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "ethnicity")), TargetPath = "ethnicity" }, new ValidationField { FieldPath = "ethnicity", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code }) .Required().ImplementStateValidationRule()); #endregion #region Must Enter Arrest Date UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("Must enter {0}", ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "startDate")), TargetPath = "startDate" }, new ValidationField { FieldPath = "startDate", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Date }) .Required().ImplementStateValidationRule()); #endregion #region Juvenile Disposition must be entered when the Juvenile dropdown is set to yes TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "dispositionUnder18"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "juvenile"); ValidationMessage = new ValidationMessage(string.Format("{0} is required for juvenile arrests", TargetFieldLabel, AssociatedField1Label), "dispositionUnder18"); TargetField = new ValidationField { FieldPath = "dispositionUnder18", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "juvenile", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List<string> { "Y" }) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); #endregion #region Offense field is required (Charge) UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("Must enter {0}", ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "violationCodeReference")), TargetPath = "violationCodeReference" }, new ValidationField { FieldPath = "violationCodeReference", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Offense }) .AlwaysShowMessage() .Required() .ImplementStateValidationRule()); #endregion }
private void SetCustoms() { #region Juv Custody Age Must Be Less Than or Equal to (JUVENILE AGE) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age2"); AssociatedField2Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "juvenile"); ValidationMessage = new ValidationMessage(string.Format("Juvenile Custody {0} Must Be Less Than or Equal to maximum juvenile age", TargetFieldLabel), "age"); TargetField = new ValidationField { FieldPath = "age", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "age2", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Text, }; AssociatedField2 = new ValidationField { FieldPath = "juvenile", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("juvenileCustodyAgeMustBeLessThanOrEqualToJuvenileAge") .ThatBroadcasts() .ThatSelfEvaluates() .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); #endregion #region Adult Arrestee Age Must Be Greater Than (JUVENILE AGE) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age2"); AssociatedField2Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "juvenile"); ValidationMessage = new ValidationMessage(string.Format("Adult Arrestee {0} Must Be Greater Than maximum juvenile age", TargetFieldLabel), "age"); TargetField = new ValidationField { FieldPath = "age", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "age2", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Text, }; AssociatedField2 = new ValidationField { FieldPath = "juvenile", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField).CustomValidation( "adultArresteeAgeMustBeGreaterThanJuvenileAge") .ThatSelfEvaluates() .ThatBroadcasts() .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); #endregion }
/// <summary> /// Removes the first occurrence of a specific item from the IList. /// </summary> /// <param name="value">The item to remove from the <see cref="System.Collections.IList"/>.</param> public void Remove(ValidationMessage value) { base.Remove(value); }
/// <summary> /// Determines the index of a specific item in the <see cref="System.Collections.IList"/>. /// </summary> /// <param name="value">The item to locate in the <see cref="System.Collections.IList"/>.</param> /// <returns>The index of <c>value</c> if found in the list; otherwise, -1.</returns> public int IndexOf(ValidationMessage value) { return base.IndexOf(value); }
private void SetCustoms() { #region Must Enter Stolen Property Record when UCR Code is 6d, Attempted/Completed is '02' ('Completed') ValidationMessage = new ValidationMessage { Message = string.Format("Must Enter Stolen Property Record"), TargetPath = "attemptedCompleted" }; TargetField = new ValidationField { FieldPath = "attemptedCompleted", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("stolenPropertyExistsForOffense6d") .ThatSelfEvaluates() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); //broadcast rules UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Must Enter Stolen Vehicle Record when UCR Code is 07a,07b,07c) and Attempted/Completed is 'C' ('Completed') ValidationMessage = new ValidationMessage { Message = string.Format("Must Enter Stolen Vehicle Record"), TargetPath = "attemptedCompleted" }; TargetField = new ValidationField { FieldPath = "attemptedCompleted", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("stolenVehicleExistsForOffense7a7b7c") .ThatSelfEvaluates() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); //broadcast rules UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Must Enter Stolen Property or Vehicle Record when UCR code is 03a,b,c,d and Attempted/Completed is 'C' ('Completed') ValidationMessage = new ValidationMessage { Message = string.Format("Must Enter Stolen Property or Vehicle Record"), TargetPath = "attemptedCompleted" }; TargetField = new ValidationField { FieldPath = "attemptedCompleted", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code }; AssociatedField2 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("stolenPropertyOrVehicleExistsForOffense3a3b3c3d") .ThatSelfEvaluates() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); //broadcast rules UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Must Enter a Weapon if UCR Class is 01, 02, 03, 04, 15, or 17 and Domestic Violence is checked TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.INCIDENT_EVENT, "domesticViolence"); ucrClassList = new List <string>() { "01", "02", "03", "04", "15", "17" }; ValidationMessage = new ValidationMessage( string.Format("{0} Must Be Entered for {1} incidents", TargetFieldLabel, AssociatedField1Label), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; AssociatedField1 = new ValidationField { FieldPath = "domesticViolence", FieldType = FieldType.Extended, SectionName = GenericSectionName.INCIDENT_EVENT, ControlType = ControlType.Checkbox, }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("mustEnterWeaponForDomesticViolenceEvents") .ThatSelfEvaluates() .AlwaysShowMessage() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.ViolationCodeOffenses()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); #endregion }
public void SetComparisons() { #region Age must be 01-99 or 00 for unknown TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age"); ValidationMessage = new ValidationMessage(string.Format("{0} Must Be Numeric if Not from the List", TargetFieldLabel), "age"); TargetField = new ValidationField { FieldPath = "age", SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code }; // Adding "1-6 DAYS OLD", "7-364 DAYS OLD" and "UNDER 24 HOURS" values var contains = new List<string> { "NB", "BB", "NN" }; // Adding "0" to "9" values for (var i = 0; i < 10; i++) contains.Add(Convert.ToString(i)); // Adding "00" to "99" values for (var i = 0; i < 100; i++) contains.Add(i.ToString("00")); UcrValidationRules.Add(new Validation(ValidationMessage, TargetField).Contains(contains).ImplementStateValidationRule()); #endregion #region Age2 must be greater than Age TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age2"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARRESTEE, "age"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} must be greater than {1}", TargetFieldLabel, AssociatedField1Label), TargetPath = "age2" }; TargetField = new ValidationField { FieldPath = "age2", //age SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Text, //Text Mask = Mask.None, CompareToMask = Mask.None }; AssociatedField1 = new ValidationField { FieldPath = "age", //age2 SectionName = GenericSectionName.ARRESTEE, ControlType = ControlType.Code, Mask = Mask.None, CompareToMask = Mask.None }; ValidationRule = new Validation(ValidationMessage, TargetField) .Comparison(ValidationOperand.GreaterThan) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion }
private static string GetError(ValidationMessage validationMessage, string item, string data) { return string.Format(s_validationMessages[validationMessage], item, data); }
// Validates a single script. ValidationMessage[] ValidateFile(TextAsset script, Context analysisContext, out CheckerResult.State result) { // The list of messages we got from the compiler. var messageList = new List <ValidationMessage>(); // A dummy variable storage; it won't be used, but Dialogue // needs it. var variableStorage = new Yarn.MemoryVariableStore(); // The Dialog object is the compiler. var dialog = new Dialogue(variableStorage); // Whether compilation failed or not; this will be // set to true if any error messages are returned. bool failed = false; // Called when we get an error message. Convert this // message into a ValidationMessage and store it; // additionally, mark that this file failed compilation dialog.LogErrorMessage = delegate(string message) { var msg = new ValidationMessage(); msg.type = MessageType.Error; msg.message = message; messageList.Add(msg); // any errors means this validation failed failed = true; }; // Called when we get an error message. Convert this // message into a ValidationMessage and store it dialog.LogDebugMessage = delegate(string message) { var msg = new ValidationMessage(); msg.type = MessageType.Info; msg.message = message; messageList.Add(msg); }; // Attempt to compile this script. Any exceptions will result // in an error message try { dialog.LoadString(script.text, script.name); } catch (System.Exception e) { dialog.LogErrorMessage(e.Message); } // Once compilation has finished, run the analysis on it dialog.Analyse(analysisContext); // Did it succeed or not? if (failed) { result = CheckerResult.State.Failed; } else { result = CheckerResult.State.Passed; } // All done. return(messageList.ToArray()); }
public override void Execute() { WriteLiteral("\r\n"); ViewBag.Title = "Review your cohort"; ViewBag.Section = "apprentices"; ViewBag.PageID = "apprentice-details"; WriteLiteral("\r\n\r\n"); WriteLiteral("<div"); WriteLiteral(" id=\"cohort-details\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-full\""); WriteLiteral(">\r\n\r\n"); if (Model.Data.Errors.Any()) { WriteLiteral(" <div"); WriteLiteral(" class=\"validation-summary-errors error-summary\""); WriteLiteral(">\r\n <h1"); WriteLiteral(" id=\"error-summary\""); WriteLiteral(" class=\"heading-medium error-summary-heading\""); WriteLiteral(">\r\n There are errors on this page that need your attention" + "\r\n </h1>\r\n <ul"); WriteLiteral(" class=\"error-summary-list\""); WriteLiteral(">\r\n"); foreach (var errorMsg in Model.Data.Errors) { WriteLiteral(" <li>\r\n <a"); WriteAttribute("href", Tuple.Create(" href=\"", 1092), Tuple.Create("\"", 1127) , Tuple.Create(Tuple.Create("", 1099), Tuple.Create("#error-message-", 1099), true) , Tuple.Create(Tuple.Create("", 1114), Tuple.Create <System.Object, System.Int32>(errorMsg.Key , 1114), false) ); WriteLiteral(" data-focuses=\"error-message-"); Write(errorMsg.Key); WriteLiteral("\""); WriteLiteral(">\r\n"); WriteLiteral(" "); Write(ValidationMessage.ExtractBannerMessage(errorMsg.Value)); WriteLiteral("\r\n </a>\r\n </li>\r\n"); } WriteLiteral(" </ul>\r\n </div>\r\n"); } else if (Model.Data.Warnings.Any()) { WriteLiteral(" <div"); WriteLiteral(" class=\"validation-summary-max-funding error-summary\""); WriteLiteral(">\r\n <h1"); WriteLiteral(" id=\"warning-summary\""); WriteLiteral(" class=\"heading-medium warning-summary-heading\""); WriteLiteral(">\r\n Warnings for your attention\r\n </h1>" + "\r\n <ul"); WriteLiteral(" class=\"max-funding-summary-list\""); WriteLiteral(">\r\n"); foreach (var warning in Model.Data.Warnings) { WriteLiteral(" <li><a"); WriteAttribute("href", Tuple.Create(" href=\"", 1938), Tuple.Create("\"", 1976) , Tuple.Create(Tuple.Create("", 1945), Tuple.Create("#max-funding-group-", 1945), true) , Tuple.Create(Tuple.Create("", 1964), Tuple.Create <System.Object, System.Int32>(warning.Key , 1964), false) ); WriteLiteral(" data-focuses=\"max-funding-group-"); Write(warning.Key); WriteLiteral("\""); WriteLiteral(">"); Write(warning.Value); WriteLiteral("</a></li>\r\n"); } WriteLiteral(" </ul>\r\n </div>\r\n"); } WriteLiteral("\r\n <h1"); WriteLiteral(" class=\"heading-xlarge\""); WriteLiteral(">"); Write(Model.Data.PageTitle); WriteLiteral("</h1>\r\n </div>\r\n </div>\r\n\r\n <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(" id=\"review-cohorts\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-one-third all-apps\""); WriteLiteral(">\r\n <div>\r\n <h2"); WriteLiteral(" class=\"bold-xlarge\""); WriteLiteral(">"); Write(Model.Data.Apprenticeships.Count); WriteLiteral("</h2>\r\n <p"); WriteLiteral(" class=\"heading-small\""); WriteLiteral(">"); Write(PluraliseApprentice(Model.Data.Apprenticeships.Count)); WriteLiteral("</p>\r\n </div>\r\n </div>\r\n <div"); WriteLiteral(" class=\"column-one-third incomplete-apps\""); WriteLiteral(">\r\n <div>\r\n <h2"); WriteLiteral(" class=\"bold-xlarge\""); WriteLiteral(">"); Write(Model.Data.Apprenticeships.Count(x => !x.CanBeApproved)); WriteLiteral("</h2>\r\n <p"); WriteLiteral(" class=\"heading-small\""); WriteLiteral(">"); Write(PluraliseIncompleteRecords(Model.Data.Apprenticeships.Count(x => !x.CanBeApproved))); WriteLiteral("</p>\r\n </div>\r\n </div>\r\n <div"); WriteLiteral(" class=\"column-one-third total-cost\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"dynamic-cost-display\""); WriteLiteral(">\r\n"); var totalCost = Model.Data.Apprenticeships.Sum(x => x.Cost ?? 0).ToString("N0"); var totalClass = string.Empty; if (totalCost.Length > 3) { totalClass = "short"; } if (totalCost.Length > 6) { totalClass = "long"; } if (totalCost.Length > 9) { totalClass = "longer"; } WriteLiteral("\r\n <h2"); WriteAttribute("class", Tuple.Create(" class=\"", 3654), Tuple.Create("\"", 3685) , Tuple.Create(Tuple.Create("", 3662), Tuple.Create <System.Object, System.Int32>(totalClass , 3662), false) , Tuple.Create(Tuple.Create(" ", 3673), Tuple.Create("bold-xlarge", 3674), true) ); WriteLiteral(">£"); Write(totalCost); WriteLiteral("</h2>\r\n\r\n <p"); WriteLiteral(" class=\"heading-small\""); WriteLiteral(">Total cost</p>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-one-third employer-details\""); WriteLiteral(">\r\n <p><span"); WriteLiteral(" class=\"strong\""); WriteLiteral(">Training provider:</span> "); Write(Model.Data.ProviderName); WriteLiteral("</p>\r\n <p><span"); WriteLiteral(" class=\"strong\""); WriteLiteral(">Status:</span> "); Write(Model.Data.Status.GetDescription()); WriteLiteral("</p>\r\n </div>\r\n\r\n <div"); WriteLiteral(" class=\"column-two-thirds employer-details\""); WriteLiteral(">\r\n <p"); WriteLiteral(" class=\"strong\""); WriteLiteral(">Message:</p>\r\n <p>"); Write(string.IsNullOrWhiteSpace(Model.Data.LatestMessage) ? "No message added" : Model.Data.LatestMessage); WriteLiteral("</p>\r\n </div>\r\n </div>\r\n\r\n <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-full\""); WriteLiteral(">\r\n"); var finishEditingText = Model.Data.ShowApproveOnlyOption ? "Continue to approval" : "Save and continue"; WriteLiteral("\r\n\r\n"); if (!Model.Data.IsReadOnly) { WriteLiteral(" <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-full\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"emptyStateButton\""); WriteLiteral(">\r\n <hr"); WriteLiteral(" class=\"hr-top\""); WriteLiteral(">\r\n <a"); WriteLiteral(" class=\"button finishEditingBtn\""); WriteAttribute("href", Tuple.Create(" href=\"", 4891), Tuple.Create("\"", 4928) , Tuple.Create(Tuple.Create("", 4898), Tuple.Create <System.Object, System.Int32>(Url.Action("FinishedEditing") , 4898), false) ); WriteAttribute("aria-label", Tuple.Create(" aria-label=\"", 4929), Tuple.Create("\"", 4960) , Tuple.Create(Tuple.Create("", 4942), Tuple.Create <System.Object, System.Int32>(finishEditingText , 4942), false) ); WriteLiteral(">"); Write(finishEditingText); WriteLiteral("</a>\r\n <a"); WriteAttribute("href", Tuple.Create(" href=\"", 5016), Tuple.Create("\"", 5063) , Tuple.Create(Tuple.Create("", 5023), Tuple.Create <System.Object, System.Int32>(Url.Action("CreateApprenticeshipEntry") , 5023), false) ); WriteLiteral(" class=\"button button-secondary\""); WriteLiteral(" aria-label=\"Add an apprentice\""); WriteLiteral(">Add an apprentice</a>\r\n </div>\r\n </div" + ">\r\n </div>\r\n"); } WriteLiteral("\r\n <hr"); WriteLiteral(" class=\"hr-bottom\""); WriteLiteral(">\r\n\r\n"); if (!Model.Data.HasApprenticeships) { WriteLiteral(" <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(" id=\"empty-alert-top\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-full\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"panel panel-border-wide alert-default\""); WriteLiteral(">\r\n\r\n"); if (Model.Data.IsReadOnly) { WriteLiteral(" <p>Apprentices will appear here when the training" + " provider adds them to your cohort.</p>\r\n"); } else { WriteLiteral(" <p>You haven’t added any apprentices yet - <a"); WriteAttribute("href", Tuple.Create(" href=\"", 5925), Tuple.Create("\"", 5972) , Tuple.Create(Tuple.Create("", 5932), Tuple.Create <System.Object, System.Int32>(Url.Action("CreateApprenticeshipEntry") , 5932), false) ); WriteLiteral("> add an apprentice </a></p>\r\n"); } WriteLiteral("\r\n </div>\r\n </div>\r\n </d" + "iv>\r\n"); } else { WriteLiteral(" <div"); WriteLiteral(" class=\"grid-row\""); WriteLiteral(">\r\n <div"); WriteLiteral(" class=\"column-full\""); WriteLiteral(">\r\n\r\n"); foreach (var group in Model.Data.ApprenticeshipGroups) { var groupTitle = string.Format($"{@group.Apprenticeships.Count} x {group.GroupName}"); WriteLiteral(" <div"); WriteLiteral(" class=\"group-header\""); WriteLiteral(">\r\n\r\n <p"); WriteLiteral(" class=\"heading-medium\""); WriteLiteral(">"); Write(groupTitle); WriteLiteral("</p>\r\n"); if (group.TrainingProgramme != null) { WriteLiteral(" <p>Training code: "); Write(group.TrainingProgramme.CourseCode); WriteLiteral("</p>\r\n"); } WriteLiteral("\r\n </div>\r\n"); if (group.OverlapErrorCount > 0) { WriteLiteral(" <div"); WriteLiteral(" class=\"overlap-notification\""); WriteAttribute("id", Tuple.Create(" id=\"", 7042), Tuple.Create("\"", 7075) , Tuple.Create(Tuple.Create("", 7047), Tuple.Create("error-message-", 7047), true) , Tuple.Create(Tuple.Create("", 7061), Tuple.Create <System.Object, System.Int32>(group.GroupId , 7061), false) ); WriteLiteral(">\r\n <p"); WriteLiteral(" class=\"heading-small\""); WriteLiteral(">\r\n"); WriteLiteral(" "); Write(_addS("Apprenticeship", group.OverlapErrorCount)); WriteLiteral(@" can't have overlapping training dates </p> <p> Please update training dates to ensure they do not overlap. </p> </div> "); } else if (group.ApprenticeshipsOverFundingLimit > 0 && !Model.Data.Errors.Any()) { WriteLiteral(" <div"); WriteLiteral(" class=\"funding-cap-alert\""); WriteAttribute("id", Tuple.Create(" id=\"", 7772), Tuple.Create("\"", 7809) , Tuple.Create(Tuple.Create("", 7777), Tuple.Create("max-funding-group-", 7777), true) , Tuple.Create(Tuple.Create("", 7795), Tuple.Create <System.Object, System.Int32>(group.GroupId , 7795), false) ); WriteLiteral(">\r\n <p"); WriteLiteral(" class=\"heading-small\""); WriteLiteral(">\r\n"); WriteLiteral(" "); Write($"{group.ApprenticeshipsOverFundingLimit} {_addS("apprenticeship", group.ApprenticeshipsOverFundingLimit).ToLower()} above funding band maximum"); WriteLiteral("\r\n </p>\r\n <" + "p>\r\n The costs are above the"); Write(group.ShowCommonFundingCap ? $" £{group.CommonFundingCap:N0}":""); WriteLiteral(" <a"); WriteLiteral(" target=\"_blank\""); WriteLiteral(" href=\"https://www.gov.uk/government/publications/apprenticeship-funding-and-perf" + "ormance-management-rules-2017-to-2018\""); WriteLiteral(@">maximum value of the funding band</a> for this apprenticeship. You'll need to pay the difference directly to the training provider - this can't be funded from your account. </p> </div> "); } WriteLiteral(" <table"); WriteLiteral(" class=\"tableResponsive viewCommitment\""); WriteLiteral(">\r\n <thead>\r\n <" + "tr>\r\n <th"); WriteLiteral(" scope=\"col\""); WriteLiteral(">Name</th>\r\n <th"); WriteLiteral(" scope=\"col\""); WriteLiteral(">Unique learner number</th>\r\n <th"); WriteLiteral(" scope=\"col\""); WriteLiteral(">Date of birth</th>\r\n <th"); WriteLiteral(" scope=\"col\""); WriteLiteral(">Training dates</th>\r\n <th"); WriteLiteral(" scope=\"col\""); WriteLiteral(" colspan=\"2\""); WriteLiteral(">Cost</th>\r\n </tr>\r\n " + " </thead>\r\n <tbody>\r\n"); foreach (var apprenticeship in group.Apprenticeships.OrderBy(a => a.CanBeApproved)) { WriteLiteral(" <tr>\r\n " + " <td>\r\n"); WriteLiteral(" "); Write(GetValueOrDefault(apprenticeship.ApprenticeName)); WriteLiteral("\r\n </td>\r\n " + " <td"); WriteLiteral(" id=\"apprenticeUln\""); WriteLiteral(">\r\n"); if (!string.IsNullOrEmpty(apprenticeship.ApprenticeUln)) { WriteLiteral(" <span>"); Write(apprenticeship.ApprenticeUln); WriteLiteral("</span>\r\n"); } else { WriteLiteral(" <span"); WriteLiteral(" class=\"missing\""); WriteLiteral(">–</span>\r\n"); } WriteLiteral(" </td>\r\n " + " <td>\r\n"); if (apprenticeship.ApprenticeDateOfBirth.HasValue) { WriteLiteral(" <span>\r\n"); WriteLiteral(" "); Write(apprenticeship.ApprenticeDateOfBirth.Value.ToGdsFormat()); WriteLiteral("\r\n </span>\r\n"); } else { WriteLiteral(" <span"); WriteLiteral(" class=\"missing\""); WriteLiteral(">–</span>\r\n"); } WriteLiteral(" </td>\r\n"); if (apprenticeship.StartDate != null && apprenticeship.EndDate != null) { if (apprenticeship.OverlappingApprenticeships.Any()) { WriteLiteral(" <td"); WriteLiteral(" class=\"overlap-alert\""); WriteLiteral(">\r\n <a"); WriteAttribute("href", Tuple.Create(" href=\"", 11567), Tuple.Create("\"", 11603) , Tuple.Create(Tuple.Create("", 11574), Tuple.Create("#error-message-", 11574), true) , Tuple.Create(Tuple.Create("", 11589), Tuple.Create <System.Object, System.Int32>(group.GroupId , 11589), false) ); WriteLiteral("\r\n aria-label=\"The unique l" + "earner number already exists for these training dates\""); WriteAttribute("aria-describedby", Tuple.Create("\r\n aria-describedby=\"", 11739), Tuple.Create("\"", 11846) , Tuple.Create(Tuple.Create("", 11814), Tuple.Create("max-funding-group-", 11814), true) , Tuple.Create(Tuple.Create("", 11832), Tuple.Create <System.Object, System.Int32>(group.GroupId , 11832), false) ); WriteLiteral("\r\n title=\"The unique learne" + "r number already exists for these training dates\""); WriteLiteral(">\r\n"); WriteLiteral(" "); Write(apprenticeship.StartDate.Value.ToGdsFormatWithoutDay()); WriteLiteral(" to "); Write(apprenticeship.EndDate.Value.ToGdsFormatWithoutDay()); WriteLiteral(" \r\n </a>\r\n " + " </td>\r\n"); } else { WriteLiteral(" <td>\r\n"); WriteLiteral(" "); Write(apprenticeship.StartDate.Value.ToGdsFormatWithoutDay()); WriteLiteral(" to "); Write(apprenticeship.EndDate.Value.ToGdsFormatWithoutDay()); WriteLiteral("\r\n </td>\r\n"); } } else { WriteLiteral(" <td>\r\n " + " <span"); WriteLiteral(" class=\"missing\""); WriteLiteral(">–</span>\r\n </td>\r\n"); } WriteLiteral("\r\n "); WriteLiteral("\r\n"); if (apprenticeship.IsOverFundingLimit(group.TrainingProgramme) && !Model.Data.Errors.Any()) { WriteLiteral(" <td"); WriteLiteral(" class=\"funding-cap-alert-td\""); WriteLiteral(">\r\n <a"); WriteAttribute("href", Tuple.Create(" href=\"", 13641), Tuple.Create("\"", 13681) , Tuple.Create(Tuple.Create("", 13648), Tuple.Create("#max-funding-group-", 13648), true) , Tuple.Create(Tuple.Create("", 13667), Tuple.Create <System.Object, System.Int32>(group.GroupId , 13667), false) ); WriteLiteral(" aria-label=\"Cost is above the maximum funding band\""); WriteAttribute("aria-describedby", Tuple.Create(" aria-describedby=\"", 13734), Tuple.Create("\"", 13785) , Tuple.Create(Tuple.Create("", 13753), Tuple.Create("max-funding-group-", 13753), true) , Tuple.Create(Tuple.Create("", 13771), Tuple.Create <System.Object, System.Int32>(group.GroupId , 13771), false) ); WriteLiteral(" title=\"Cost is above the maximum funding band\""); WriteLiteral("> "); Write(GetValueOrDefault(FormatCost(apprenticeship.Cost))); WriteLiteral("</a>\r\n </td>\r\n"); } else { WriteLiteral(" <td>\r\n"); WriteLiteral(" "); Write(GetValueOrDefault(FormatCost(apprenticeship.Cost))); WriteLiteral("\r\n </td>\r\n"); } WriteLiteral("\r\n <td>\r\n"); if (!Model.Data.IsReadOnly) { WriteLiteral(" <a"); WriteAttribute("href", Tuple.Create(" href=\"", 14539), Tuple.Create("\"", 14649) , Tuple.Create(Tuple.Create("", 14546), Tuple.Create <System.Object, System.Int32>(Url.Action("EditApprenticeship", new { hashedApprenticeshipId = apprenticeship.HashedApprenticeshipId }) , 14546), false) ); WriteAttribute("aria-label", Tuple.Create(" aria-label=\"", 14650), Tuple.Create("\"", 14698) , Tuple.Create(Tuple.Create("", 14663), Tuple.Create("Edit", 14663), true) , Tuple.Create(Tuple.Create(" ", 14667), Tuple.Create <System.Object, System.Int32>(apprenticeship.ApprenticeName , 14668), false) ); WriteLiteral(">Edit</a>\r\n"); } else { WriteLiteral(" <a"); WriteAttribute("href", Tuple.Create(" href=\"", 14904), Tuple.Create("\"", 15014) , Tuple.Create(Tuple.Create("", 14911), Tuple.Create <System.Object, System.Int32>(Url.Action("ViewApprenticeship", new { hashedApprenticeshipId = apprenticeship.HashedApprenticeshipId }) , 14911), false) ); WriteAttribute("aria-label", Tuple.Create(" aria-label=\"", 15015), Tuple.Create("\"", 15063) , Tuple.Create(Tuple.Create("", 15028), Tuple.Create("View", 15028), true) , Tuple.Create(Tuple.Create(" ", 15032), Tuple.Create <System.Object, System.Int32>(apprenticeship.ApprenticeName , 15033), false) ); WriteLiteral(">View</a>\r\n"); } WriteLiteral(" </td>\r\n " + " </tr>\r\n"); } WriteLiteral(" </tbody>\r\n </table>\r\n"); } WriteLiteral(" </div>\r\n </div>\r\n"); } WriteLiteral(" </div>\r\n </div>\r\n</div>\r\n\r\n"); if (!Model.Data.IsReadOnly && !Model.Data.HideDeleteButton) { WriteLiteral(" <a"); WriteLiteral(" class=\"button delete-button\""); WriteAttribute("href", Tuple.Create(" href=\"", 15563), Tuple.Create("\"", 15597) , Tuple.Create(Tuple.Create("", 15570), Tuple.Create <System.Object, System.Int32>(Url.Action("DeleteCohort") , 15570), false) ); WriteLiteral(" aria-label=\"Delete cohort\""); WriteLiteral(">Delete cohort</a>\r\n"); } WriteLiteral("\r\n"); WriteLiteral("\r\n"); WriteLiteral("\r\n\r\n"); DefineSection("breadcrumb", () => { WriteLiteral("\r\n <div"); WriteLiteral(" class=\"breadcrumbs\""); WriteLiteral(">\r\n <a"); WriteAttribute("href", Tuple.Create(" href=\"", 16464), Tuple.Create("\"", 16494) , Tuple.Create(Tuple.Create("", 16471), Tuple.Create <System.Object, System.Int32>(Model.Data.BackLinkUrl , 16471), false) ); WriteLiteral(" aria-label=\"Back\""); WriteLiteral(" class=\"back-link\""); WriteLiteral(">Back</a>\r\n </div>\r\n"); }); WriteLiteral("\r\n"); DefineSection("gaDataLayer", () => { WriteLiteral("\r\n <script>\r\n sfa.dataLayer.vpv = \'/accounts/apprentices/details/appren" + "tice-detail\';\r\n sfa.dataLayer.cohortRef = \'"); Write(Model.Data.HashedId); WriteLiteral("\';\r\n </script>\r\n"); }); }
private RepositoryItem configureStatusRepository(ValidationMessage validationMessage) { _statusRepository.Items.Clear(); _statusRepository.Items.Add(new ImageComboBoxItem(validationMessage.NotificationType, _presenter.ImageIndexFor(validationMessage))); return(_statusRepository); }
private void SetRequired() { #region Address is required when Latitude or Longitude is blank TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.streetAddress"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.latitude"); AssociatedField2Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.longitude"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} is required when {1} or {2} is blank", TargetFieldLabel, AssociatedField1Label, AssociatedField2Label), TargetPath = "address.streetAddress" }; TargetField = new ValidationField { FieldPath = "address.streetAddress", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; AssociatedField1 = new ValidationField { FieldPath = "address.latitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; AssociatedField2 = new ValidationField { FieldPath = "address.longitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; ValidationRule = new Validation(ValidationMessage, TargetField).Required() .WithOrConditions() .NotRequired(AssociatedField1) .NotRequired(AssociatedField2) .ThatBroadcasts() .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region City is required when Latitude or Longitude is blank TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.city"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.latitude"); AssociatedField2Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.longitude"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} is required when {1} or {2} is blank", TargetFieldLabel, AssociatedField1Label, AssociatedField2Label), TargetPath = "address.city" }; TargetField = new ValidationField { FieldPath = "address.city", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "address.latitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; AssociatedField2 = new ValidationField { FieldPath = "address.longitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; ValidationRule = new Validation(ValidationMessage, TargetField).Required() .WithOrConditions() .NotRequired(AssociatedField1) .NotRequired(AssociatedField2).ThatBroadcasts() .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region State is required when Latitude or Longitude is blank TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.state"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.latitude"); AssociatedField2Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.longitude"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} is required when {1} or {2} is blank", TargetFieldLabel, AssociatedField1Label, AssociatedField2Label), TargetPath = "address.state" }; TargetField = new ValidationField { FieldPath = "address.state", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "address.latitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; AssociatedField2 = new ValidationField { FieldPath = "address.longitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; ValidationRule = new Validation(ValidationMessage, TargetField).Required() .WithOrConditions() .NotRequired(AssociatedField1) .NotRequired(AssociatedField2).ThatBroadcasts() .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Zip is required when Latitude or Longitude is blank TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.zipCode"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.latitude"); AssociatedField2Label = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "address.longitude"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} is required when {1} or {2} is blank", TargetFieldLabel, AssociatedField1Label, AssociatedField2Label), TargetPath = "address.zipCode" }; TargetField = new ValidationField { FieldPath = "address.zipCode", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "address.latitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; AssociatedField2 = new ValidationField { FieldPath = "address.longitude", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Text }; ValidationRule = new Validation(ValidationMessage, TargetField).Required() .WithOrConditions() .NotRequired(AssociatedField1) .NotRequired(AssociatedField2).ThatBroadcasts() .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); NibrsValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region DuiCause is required when ViolationCode has a UCR of 90D TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "duiCause"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "violationCodeReference"); ValidationMessage = new ValidationMessage(string.Format("{0} is required when {1} has a UCR of 90D", TargetFieldLabel, AssociatedField1Label), "duiCause"); TargetField = new ValidationField { FieldPath = "duiCause", SectionName = GenericSectionName.ARREST_CHARGES, ControlType = ControlType.Code, }; AssociatedField1 = new ValidationField { FieldPath = "violationCodeReference", ControlType = ControlType.Offense, SectionName = GenericSectionName.ARREST_CHARGES, }; ValidationRule = new Validation(ValidationMessage, TargetField).Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "90D", }) .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); #endregion }
public void Validate(string fieldName, dynamic fieldValue) { var isInvalid = false; var message = ValidationMessage.Required(fieldName); if (fieldValue is null) { isInvalid = true; } else { switch (fieldValue.GetType()) { case Type x when x == typeof(string): if (string.IsNullOrWhiteSpace(fieldValue)) { isInvalid = true; } break; case Type a when a == typeof(int?): case Type b when b == typeof(uint?): case Type c when c == typeof(long?): case Type d when d == typeof(ulong?): case Type e when e == typeof(short?): case Type f when f == typeof(ushort?): case Type g when g == typeof(double?): case Type h when h == typeof(decimal?): case Type i when i == typeof(byte?): case Type j when j == typeof(sbyte?): case Type k when k == typeof(char?): case Type l when l == typeof(bool?): if (fieldValue == null) { isInvalid = true; } break; case Type x when(x == typeof(Guid) || x == typeof(Guid?)): if (fieldValue == Guid.Empty || fieldValue == null) { isInvalid = true; } break; case Type x when x == typeof(int): isInvalid = (int)fieldValue == default; break; case Type x when x == typeof(uint): isInvalid = (uint)fieldValue == default; break; case Type x when x == typeof(long): isInvalid = (long)fieldValue == default; break; case Type x when x == typeof(ulong): isInvalid = (ulong)fieldValue == default; break; case Type x when x == typeof(short): isInvalid = (short)fieldValue == default; break; case Type x when x == typeof(ushort): isInvalid = (ushort)fieldValue == default; break; case Type x when x == typeof(double): isInvalid = (double)fieldValue == default; break; case Type x when x == typeof(decimal): isInvalid = (decimal)fieldValue == default; break; case Type x when x == typeof(byte): isInvalid = (byte)fieldValue == default; break; case Type x when x == typeof(sbyte): isInvalid = (sbyte)fieldValue == default; break; case Type x when x == typeof(char): isInvalid = (char)fieldValue == default; break; case Type x when x == typeof(bool): isInvalid = (bool)fieldValue == default; break; } } if (isInvalid) { _roleBuilder.AddErrorMessage(fieldName, message); } }
/// <summary> /// Validation message implementation for <see cref="IWindowsInstallerValidatorCallback"/>. /// </summary> public bool ValidationMessage(ValidationMessage message) { this.LogValidationMessage(message); return(true); }
/// <summary> /// Shows the exception. /// </summary> /// <param name="form">The form.</param> /// <param name="title">The title.</param> /// <param name="ex">The ex.</param> public static void ShowException(DependencyObject form, string title, ValidationException ex) { ShowException(form, ex); ValidationMessage.Show(form as Window, title, ex); }
/// <summary> /// Adds a validation message. /// </summary> /// <param name="message">The message.</param> public void AddValidationMessage(string message) { var validationMessage = new ValidationMessage(PropertyName, message); AddValidationMessageAction(validationMessage); }
public bool Equals(ValidationMessage other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.Property, Property) && Equals(other.Message, Message); }
/// <summary> /// Inserts an item to the IList at the specified position. /// </summary> /// <param name="index">The zero-based index at which <c>value</c> should be inserted. </param> /// <param name="value">The item to insert into the <see cref="System.Collections.IList"/>.</param> public void Insert(int index, ValidationMessage value) { base.Insert(index, value); }
public void TestValidationMessageCollection() { var message1 = new ValidationMessage("message1", "Test1 {0}.", new object[] { 5 }, new Example(), "Property1", ValidationLevel.Error, "Validation context 2", 0); var message2 = new ValidationMessage("message2", "Test2 {0}.", new object[] { 5 }, new Example(), "Property2", ValidationLevel.Error, "Validation context 2", 0); var message3 = new ValidationMessage("message3", "Test3 {0}.", new object[] { 5 }, new Example(), "Property3", ValidationLevel.Error, "Validation context 2", 0); var message4 = new ValidationMessage("message4", "Test4 {0}.", new object[] { 5 }, new Example(), "Property4", ValidationLevel.Info, "Validation context 2", 0); var message5 = new ValidationMessage("message5", "Test5 {0}.", new object[] { 5 }, message4.ValidationSource, "Property4", ValidationLevel.Warning, "Validation context 2", 0); var messages = new ValidationMessageCollection(); messages.Add(message1); messages.Add(message2); messages.Add(message3); messages.Insert(messages.Count, message4); Assert.AreEqual(message1, messages[0]); Assert.AreEqual(message2, messages[1]); Assert.AreEqual(message3, messages[2]); Assert.AreEqual(message4, messages[3]); Assert.AreEqual(1, messages[message1.ValidationSource, "Property1", "Validation context 2"].Count); Assert.AreEqual(message1, messages[message1.ValidationSource, "Property1", "Validation context 2"][0]); Assert.AreEqual(1, messages[message3.ValidationSource, message3.PropertyName, "Validation context 2"].Count); Assert.AreEqual(message3, messages[message3.ValidationSource, message3.PropertyName, "Validation context 2"][0]); Assert.AreEqual(0, messages[null as IValidatable].Count); Assert.AreEqual(0, messages[null as IValidatable, null as string].Count); Assert.AreEqual(0, messages[null as IValidatable, "aaa" as string].Count); Assert.AreEqual(0, messages[new Example() as IValidatable, null as string].Count); Assert.IsFalse(messages.Contains(null)); Assert.IsTrue(messages.Contains(message3)); messages.Add(message5); Assert.AreEqual(4, messages.Count); Assert.AreEqual(message5, messages.Last()); messages[3] = message4; Assert.AreEqual(4, messages.Count); Assert.AreEqual(message1, messages[0]); Assert.AreEqual(message2, messages[1]); Assert.AreEqual(message3, messages[2]); Assert.AreEqual(message4, messages[3]); var validationSource = new Example(); var message6 = new ValidationMessage("message1", "Test1 {0}.", new object[] { 7 }, validationSource, "Property1", ValidationLevel.Error, null, 0); var message7 = new ValidationMessage("message2", "Test2 {0}.", new object[] { 8 }, validationSource, "Property1", ValidationLevel.Error, null, 0); var message8 = new ValidationMessage("message3", "Test3 {0}.", new object[] { 9 }, validationSource, "Property2", ValidationLevel.Error, "Validation context 2", 0); messages.Add(message6); messages.Add(message7); messages.Insert(messages.Count, message8); var mergedMessage = messages.Merge(validationSource, "Property1"); Assert.AreEqual("Test1 7.\r\nTest2 8.", mergedMessage.Message); Assert.AreEqual(ValidationLevel.Error, mergedMessage.ValidationLevel); MergedValidationMessage.GetMergedMessages = x => string.Join(" * ", x); var mergedMessage2 = messages.Merge(validationSource, "Property1"); Assert.AreEqual("Test1 7. * Test2 8.", mergedMessage2.Message); Assert.AreEqual(ValidationLevel.Error, mergedMessage2.ValidationLevel); var mergedMessage4 = messages.Merge(validationSource, "Property2"); Assert.AreEqual("Test3 9.", mergedMessage4.Message); Assert.AreEqual(ValidationLevel.Error, mergedMessage4.ValidationLevel); var mergedMessage5 = messages.Merge(validationSource); Assert.AreEqual("Test1 7. * Test2 8. * Test3 9.", mergedMessage5.Message); Assert.AreEqual(ValidationLevel.Error, mergedMessage5.ValidationLevel); MergedValidationMessage.GetMergedMessages = null; }
/// <summary> /// Determines whether the <see cref="System.Collections.IList"/> contains a specific item. /// </summary> /// <param name="value">The item to locate in the <see cref="System.Collections.IList"/>.</param> /// <returns><see langword="true"/> if the item is found in the <see cref="System.Collections.IList"/>; otherwise, <see langword="false"/>.</returns> public bool Contains(ValidationMessage value) { return base.Contains(value); }
private void SetRequired() { #region DrugActivity is required when ViolationCode has a UCR Code of 35A TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "primaryDrugActivity"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "violationCodeReference"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} is required when {1} has a UCR of 35A", TargetFieldLabel, AssociatedField1Label), TargetPath = "primaryDrugActivity" }; TargetField = new ValidationField { FieldPath = "primaryDrugActivity", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .SectionRequired(ValidationField.ViolationCodeArrestCharges(), new List <string> { "35A" }) .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(new Validation(ValidationMessage, ValidationField.ViolationCodeArrestCharges()).ThatBroadcasts() .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); #endregion #region DrugType is required when ViolationCode has a UCR Code of 35A TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.EVENT, "primaryDrugType"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.ARREST_CHARGES, "violationCodeReference"); ValidationMessage = new ValidationMessage { Message = string.Format("{0} is required when {1} has a UCR of 35A", TargetFieldLabel, AssociatedField1Label), TargetPath = "primaryDrugType" }; TargetField = new ValidationField { FieldPath = "primaryDrugType", SectionName = GenericSectionName.EVENT, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .SectionRequired(ValidationField.ViolationCodeArrestCharges(), new List <string> { "35A" }) .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule(); NibrsValidationRules.Add(ValidationRule); NibrsValidationRules.Add(new Validation(ValidationMessage, ValidationField.ViolationCodeArrestCharges()).ThatBroadcasts() .SetRuleImplementation(RuleImplementation) .ImplementStateValidationRule()); #endregion }
/// <summary> /// Adds an item to the <see cref="System.Collections.IList"/>. /// </summary> /// <param name="value">The item to add to the <see cref="System.Collections.IList"/>. </param> /// <returns>The position into which the new element was inserted.</returns> public int Add(ValidationMessage value) { return base.Add(value); }
protected void ClearValidationMessage() { ValidationMessage.Clear(); }
/// <summary> /// Report removed messages to the task list. /// </summary> /// <param name="removedMessage"></param> /// <remarks> /// methods are called in this order: /// 1. OnValidationMessagesChanging /// 2. OnValidationMessageRemoved - called once for each message removed. /// 3. OnValidationMessageAdded - called once for each message added. /// 4. OnValidationMessagesChangedSummary /// </remarks> protected override void OnValidationMessageRemoved(ValidationMessage removedMessage) { if (this.TaskProvider.Tasks.Count != 0) { var task = new ProductStoreValidationTask((ProductStoreTaskValidationMessage)removedMessage); foreach (Task tk in this.TaskProvider.Tasks) { var taskToRemove = tk as ProductStoreValidationTask; if ((taskToRemove != null) && taskToRemove.IsMatch(task)) { this.TaskProvider.Tasks.Remove(taskToRemove); break; } } } }
protected void AddError(string message) { ValidationMessage.Add(message); }