using System.Collections.Generic; namespace AyaNova.Biz { //************************************************ // This contains all the fields that are: // Customizable on forms // In grid list templates //In addition it serves as a source for valid form keys in AvailableFormKeys // public static class ObjectFields { public const string WIDGET_KEY = "widget"; public const string USER_KEY = "user"; public static List AvailableObjectKeys { get { List l = new List{ WIDGET_KEY, USER_KEY }; return l; } } public static bool IsValidObjectKey(string key) { return AvailableObjectKeys.Contains(key); } public static List FormFields(string key) { /* ***************************** WARNING: Be careful here, if a standard field is hideable and also it's DB SCHEMA is set to NON NULLABLE then the CLIENT end needs to set a default ***************************** Otherwise the hidden field can't be set and the object can't be saved EVER */ List l = new List(); switch (key) { case WIDGET_KEY: l.Add(new ObjectField("WidgetName", "Name", false, false));//is not shared localized text key and not hideable as it is in the validation rules for widget l.Add(new ObjectField("WidgetSerial", "Serial"));//not in validation rules BUT, is HIDEABLE and is set to NOT NULLABLE in the schema so this field MUST MUST have a default value in client l.Add(new ObjectField("WidgetDollarAmount", "DollarAmount")); l.Add(new ObjectField("WidgetCount", "Count")); l.Add(new ObjectField("WidgetRoles", "Roles"));//not required but must be a valid default l.Add(new ObjectField("WidgetStartDate", "StartDate"));//have rule for date precedence but can both be empty so allowing to hide is ok l.Add(new ObjectField("WidgetEndDate", "EndDate")); l.Add(new ObjectField("WidgetNotes", "Notes")); l.Add(new ObjectField("Active", "Active", true, false));//active is not hideable / required l.Add(new ObjectField("Tags", "Tags", true)); l.Add(new ObjectField("WidgetCustom1", false, true, true)); l.Add(new ObjectField("WidgetCustom2", false, true, true)); l.Add(new ObjectField("WidgetCustom3", false, true, true)); l.Add(new ObjectField("WidgetCustom4", false, true, true)); l.Add(new ObjectField("WidgetCustom5", false, true, true)); l.Add(new ObjectField("WidgetCustom6", false, true, true)); l.Add(new ObjectField("WidgetCustom7", false, true, true)); l.Add(new ObjectField("WidgetCustom8", false, true, true)); l.Add(new ObjectField("WidgetCustom9", false, true, true)); l.Add(new ObjectField("WidgetCustom10", false, true, true)); l.Add(new ObjectField("WidgetCustom11", false, true, true)); l.Add(new ObjectField("WidgetCustom12", false, true, true)); l.Add(new ObjectField("WidgetCustom13", false, true, true)); l.Add(new ObjectField("WidgetCustom14", false, true, true)); l.Add(new ObjectField("WidgetCustom15", false, true, true)); l.Add(new ObjectField("WidgetCustom16", false, true, true)); break; case USER_KEY: l.Add(new ObjectField("Name", true, false));//is not shared localized text key and not hideable as it is in the validation rules for widget l.Add(new ObjectField("EmployeeNumber")); l.Add(new ObjectField("Roles", false, false)); l.Add(new ObjectField("UserNotes", "Notes")); l.Add(new ObjectField("UserType", false, false)); l.Add(new ObjectField("Active", true, false)); l.Add(new ObjectField("Tags", true, false)); l.Add(new ObjectField("UserCustom1", false, true, true)); l.Add(new ObjectField("UserCustom2", false, true, true)); l.Add(new ObjectField("UserCustom3", false, true, true)); l.Add(new ObjectField("UserCustom4", false, true, true)); l.Add(new ObjectField("UserCustom5", false, true, true)); l.Add(new ObjectField("UserCustom6", false, true, true)); l.Add(new ObjectField("UserCustom7", false, true, true)); l.Add(new ObjectField("UserCustom8", false, true, true)); l.Add(new ObjectField("UserCustom9", false, true, true)); l.Add(new ObjectField("UserCustom10", false, true, true)); l.Add(new ObjectField("UserCustom11", false, true, true)); l.Add(new ObjectField("UserCustom12", false, true, true)); l.Add(new ObjectField("UserCustom13", false, true, true)); l.Add(new ObjectField("UserCustom14", false, true, true)); l.Add(new ObjectField("UserCustom15", false, true, true)); l.Add(new ObjectField("UserCustom16", false, true, true)); break; default: throw new System.ArgumentOutOfRangeException($"FormAvailableFields: {key} is not a valid form key"); } return l; } public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName) { var i = System.Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace( lTCustomFieldName, // Our input "[^0-9]", // Select everything that is not in the range of 0-9 "" // Replace that with an empty string. )); return $"c{i}"; } }//eoc FormAvailableFields public class ObjectField { public string Key { get; set; } public string PropertyName { get; set; } //NOTE: Not hideable fields don't require a PropertyName value because they are already required and will be validated public bool Hideable { get; set; } public bool SharedLTKey { get; set; } public bool Custom { get; set; } public bool Filterable { get; set; } public bool Sortable { get; set; } public bool MiniAvailable { get; set; } public string DataType { get; set; } public ObjectField() { } public ObjectField(string key, string propertyName, bool sharedLTKey = false, bool hideable = true, bool custom = false) { Key = key; Hideable = hideable; Custom = custom; SharedLTKey = sharedLTKey; PropertyName = propertyName;//Only if hideable do they require this as non-hideable ones are automatically validated anyway and this is only required for validation } public ObjectField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false) { Key = key; Hideable = hideable; Custom = custom; SharedLTKey = sharedLTKey; PropertyName = null; } } }//ens