/// <summary> /// Returns whether the <see cref="IFieldObject"/> in the <see cref="IRowObject"/> is required by FieldNumber. /// </summary> /// <param name="rowObject"></param> /// <param name="fieldNumber"></param> /// <returns></returns> public static bool IsFieldRequired(IRowObject rowObject, string fieldNumber) { if (rowObject == null) { throw new ArgumentNullException(nameof(rowObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (rowObject.Fields == null) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("rowObjectMissingFields", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(fieldNumber)) { throw new ArgumentNullException(nameof(fieldNumber), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } foreach (FieldObject field in rowObject.Fields) { if (field.FieldNumber == fieldNumber) { return(IsFieldRequired(field)); } } throw new System.ArgumentException(ScriptLinkHelpers.GetLocalizedString("noFieldObjectsFoundByFieldNumber", CultureInfo.CurrentCulture) + fieldNumber, nameof(fieldNumber)); }
/// <summary> /// Returns whether the <see cref="IRowObject"/> in an <see cref="IOptionObject"/> is marked for deletion by RowId. /// </summary> /// <param name="optionObject"></param> /// <param name="rowId"></param> /// <returns></returns> public static bool IsRowMarkedForDeletion(IOptionObject optionObject, string rowId) { if (optionObject == null) { throw new ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (optionObject.Forms == null) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("optionObjectMissingForms", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(rowId)) { throw new ArgumentNullException(nameof(rowId), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } foreach (FormObject formObject in optionObject.Forms) { if (IsRowMarkedForDeletion(formObject, rowId)) { return(true); } } return(false); }
/// <summary> /// Returns the ParentRowId of a <see cref="IFormObject"/> in the <see cref="IOptionObject"/> by FormId. /// </summary> /// <param name="optionObject"></param> /// <param name="formId"></param> /// <returns></returns> public static string GetParentRowId(IOptionObject optionObject, string formId) { if (optionObject == null) { throw new ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(formId)) { throw new ArgumentNullException(nameof(formId), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (optionObject.Forms == null) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("optionObjectMissingForms", CultureInfo.CurrentCulture)); } foreach (var formObject in optionObject.Forms) { if (formObject.FormId == formId) { return(GetParentRowId(formObject)); } } throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); }
/// <summary> /// Returns whether the <see cref="IFieldObject"/> in the <see cref="IOptionObject"/> is required by FieldNumber. /// </summary> /// <param name="optionObject"></param> /// <param name="fieldNumber"></param> /// <returns></returns> public static bool IsFieldRequired(IOptionObject optionObject, string fieldNumber) { if (optionObject == null) { throw new System.ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (optionObject.Forms == null) { throw new System.NullReferenceException(ScriptLinkHelpers.GetLocalizedString("optionObjectMissingForms", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(fieldNumber)) { throw new System.ArgumentNullException(nameof(fieldNumber), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } foreach (var form in optionObject.Forms) { if (IsFieldPresent(form, fieldNumber)) { return(IsFieldRequired(form, fieldNumber)); } } throw new ArgumentException("The OptionObject does not contain the FieldObject " + fieldNumber + "."); }
/// <summary> /// Returns a list of FieldValues of a specified <see cref="IFieldObject"/> in the <see cref="IOptionObject"/> by FieldNumber. /// </summary> /// <param name="optionObject"></param> /// <param name="fieldNumber"></param> /// <returns></returns> public static List <string> GetFieldValues(IOptionObject optionObject, string fieldNumber) { if (optionObject == null) { throw new ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (optionObject.Forms == null || optionObject.Forms.Count == 0) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("optionObjectMissingForms", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(fieldNumber)) { throw new ArgumentNullException(nameof(fieldNumber), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } foreach (var form in optionObject.Forms) { if (IsFieldPresent(form, fieldNumber)) { return(GetFieldValues(form, fieldNumber)); } } return(new List <string>()); }
/// <summary> /// Sets the FieldValue of a <see cref="FieldObject"/> in a <see cref="IFormObject"/> by RowId and FieldNumber. /// </summary> /// <param name="formObject"></param> /// <param name="rowId"></param> /// <param name="fieldNumber"></param> /// <param name="fieldValue"></param> /// <returns></returns> public static IFormObject SetFieldValue(IFormObject formObject, string rowId, string fieldNumber, string fieldValue) { if (formObject == null) { throw new ArgumentNullException(nameof(formObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (formObject.CurrentRow == null) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("formObjectMissingCurrentRow", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(rowId)) { throw new ArgumentNullException(nameof(rowId), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(fieldNumber)) { throw new ArgumentNullException(nameof(fieldNumber), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (formObject.CurrentRow.RowId == rowId) { formObject.CurrentRow = (RowObject)SetFieldValue(formObject.CurrentRow, fieldNumber, fieldValue); return(formObject); } if (formObject.MultipleIteration) { for (int i = 0; i < formObject.OtherRows.Count; i++) { if (formObject.OtherRows[i].RowId == rowId) { formObject.OtherRows[i] = (RowObject)SetFieldValue(formObject.OtherRows[i], fieldNumber, fieldValue); return(formObject); } } } throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("noFieldObjectsFoundByFieldNumber", CultureInfo.CurrentCulture) + fieldNumber, nameof(formObject)); }
/// <summary> /// Returns whether the <see cref="IRowObject"/> in an <see cref="IFormObject"/> is marked for deletion by RowId. /// </summary> /// <param name="formObject"></param> /// <param name="rowId"></param> /// <returns></returns> public static bool IsRowMarkedForDeletion(IFormObject formObject, string rowId) { if (formObject == null) { throw new ArgumentNullException(nameof(formObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (formObject.CurrentRow == null) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("formObjectMissingCurrentRow", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(rowId)) { throw new ArgumentNullException(nameof(rowId), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (formObject.CurrentRow.RowId == rowId) { return(formObject.CurrentRow.RowAction == RowAction.Delete); } if (formObject.MultipleIteration) { return(formObject.OtherRows.Exists(r => r.RowId == rowId && r.RowAction == RowAction.Delete)); } return(false); }
/// <summary> /// Adds a <see cref="RowObject"/> to a provided <see cref="IFormObject"/>. /// </summary> /// <param name="formObject"></param> /// <param name="rowObject"></param> /// <returns></returns> public static IFormObject AddRowObject(IFormObject formObject, IRowObject rowObject) { if (formObject == null) { throw new ArgumentNullException(nameof(formObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (rowObject == null) { throw new ArgumentNullException(nameof(rowObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (!formObject.MultipleIteration && formObject.CurrentRow != null) { throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("cannotAddAnotherRowObject", CultureInfo.CurrentCulture)); } if ((formObject.CurrentRow != null && formObject.CurrentRow.RowId == rowObject.RowId && !string.IsNullOrEmpty(rowObject.RowId) || (formObject.OtherRows != null && formObject.OtherRows.Exists(r => r.RowId == rowObject.RowId && string.IsNullOrEmpty(rowObject.RowId))))) { throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("rowIdAlreadyExists", CultureInfo.CurrentCulture)); } if (formObject.CurrentRow == null) { rowObject.RowId = GetNextAvailableRowId(formObject); formObject.CurrentRow = (RowObject)rowObject; } else { if (string.IsNullOrEmpty(rowObject.RowId)) { rowObject.RowId = GetNextAvailableRowId(formObject); } formObject.OtherRows.Add((RowObject)rowObject); } return(formObject); }
/// <summary> /// Flags a <see cref="RowObject"/> for deletion in specified <see cref="IOptionObject2015"/> by RowId. /// </summary> /// <param name="optionObject"></param> /// <param name="rowId"></param> /// <returns></returns> public static IOptionObject DeleteRowObject(IOptionObject optionObject, string rowId) { if (optionObject == null) { throw new ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(rowId)) { throw new ArgumentNullException(nameof(rowId), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (optionObject.Forms == null || optionObject.Forms.Count == 0) { throw new NullReferenceException(ScriptLinkHelpers.GetLocalizedString("optionObjectMissingForms", CultureInfo.CurrentCulture)); } for (int i = 0; i < optionObject.Forms.Count; i++) { if (IsRowPresent(optionObject.Forms[i], rowId)) { optionObject.Forms[i] = (FormObject)DeleteRowObject(optionObject.Forms[i], rowId); return(optionObject); } } throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("noRowObjectsFoundByRowId", CultureInfo.CurrentCulture), nameof(rowId)); }
/// <summary> /// Returns a List of the <see cref="IOptionObject2"/> properties and values. /// </summary> /// <param name="optionObject"></param> /// <returns></returns> public static List <string> GetOptionObjectHeaders(IOptionObject2 optionObject) { if (optionObject == null) { throw new ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } List <string> headers = new List <string> { "Entity ID: " + optionObject.EntityID, "Episode Number: " + optionObject.EpisodeNumber, "Error Code: " + optionObject.ErrorCode, "Error Message: " + optionObject.ErrorMesg, "Facility: " + optionObject.Facility, "Namespace Name: " + optionObject.NamespaceName, "Option ID: " + optionObject.OptionId, "Option Staff ID: " + optionObject.OptionStaffId, "Option User ID: " + optionObject.OptionUserId, "Parent Namepace: " + optionObject.ParentNamespace, "Server Name: " + optionObject.ServerName, "System Code: " + optionObject.SystemCode }; return(headers); }
/// <summary> /// Sets <see cref="FieldObject"/> in an <see cref="IRowObject"/> according to specified FieldAction. /// </summary> /// <param name="rowObject"></param> /// <param name="fieldAction"></param> /// <param name="fieldNumbers"></param> /// <returns></returns> public static IRowObject SetFieldObjects(IRowObject rowObject, string fieldAction, List <string> fieldNumbers) { if (rowObject == null) { throw new ArgumentNullException(nameof(rowObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (string.IsNullOrEmpty(fieldAction)) { throw new ArgumentNullException(nameof(fieldAction), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (fieldNumbers == null || fieldNumbers.Count == 0) { throw new ArgumentNullException(nameof(fieldNumbers), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } List <string> fieldsToSet = new List <string>(); foreach (string fieldNumber in fieldNumbers) { if (IsFieldPresent(rowObject, fieldNumber)) { fieldsToSet.Add(fieldNumber); } } if (fieldsToSet.Count == 0) { throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("noFieldObjectsFound", CultureInfo.CurrentCulture)); } foreach (var fieldObject in rowObject.Fields) { if (fieldsToSet.Contains(fieldObject.FieldNumber)) { switch (fieldAction) { case FieldAction.Disable: fieldObject.SetAsDisabled(); rowObject.RowAction = RowAction.Edit; break; case FieldAction.Enable: fieldObject.SetAsEnabled(); rowObject.RowAction = RowAction.Edit; break; case FieldAction.Lock: fieldObject.SetAsLocked(); rowObject.RowAction = RowAction.Edit; break; case FieldAction.Modify: fieldObject.SetAsModified(); rowObject.RowAction = RowAction.Edit; break; case FieldAction.Optional: fieldObject.SetAsOptional(); rowObject.RowAction = RowAction.Edit; break; case FieldAction.Require: fieldObject.SetAsRequired(); rowObject.RowAction = RowAction.Edit; break; case FieldAction.Unlock: fieldObject.SetAsUnlocked(); rowObject.RowAction = RowAction.Edit; break; default: break; } } } return(rowObject); }