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 object keys in AvailableObjectKeys // public static class ObjectFields { //DEFINE VALID KEYS HERE //For objects that are both list and edit form it's just the name of the object //For objects that are compound list objects or reporting objects it's whatever uniquely but clearly identifies that 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 ObjectFieldsList(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 Defaults of paramterless constructor: SharedLTKey = false; Hideable = true; Custom = false; Filterable = true; Sortable = true; MiniAvailable = true; */ List l = new List(); switch (key) { case WIDGET_KEY: l.Add(new ObjectField { Key = "WidgetName", PropertyName = "Name", DataType = AyDataType.Text, Hideable = false }); l.Add(new ObjectField { Key = "WidgetSerial", PropertyName = "Serial", DataType = AyDataType.Integer }); l.Add(new ObjectField { Key = "WidgetDollarAmount", PropertyName = "DollarAmount", DataType = AyDataType.Currency }); l.Add(new ObjectField { Key = "WidgetCount", PropertyName = "Count", DataType = AyDataType.Integer }); l.Add(new ObjectField { Key = "WidgetRoles", PropertyName = "Roles", DataType = AyDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); l.Add(new ObjectField { Key = "WidgetStartDate", PropertyName = "StartDate", DataType = AyDataType.DateTime }); l.Add(new ObjectField { Key = "WidgetEndDate", PropertyName = "EndDate", DataType = AyDataType.DateTime }); l.Add(new ObjectField { Key = "WidgetNotes", PropertyName = "Notes", DataType = AyDataType.Text }); l.Add(new ObjectField { Key = "Active", PropertyName = "Active", DataType = AyDataType.Bool, Hideable = false, SharedLTKey = true }); l.Add(new ObjectField { Key = "Tags", PropertyName = "Tags", DataType = AyDataType.Tags, SharedLTKey = true }); l.Add(new ObjectField { Key = "WidgetCustom1", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom2", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom3", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom4", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom5", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom6", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom7", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom8", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom9", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom10", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom11", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom12", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom13", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom14", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom15", Custom = true }); l.Add(new ObjectField { Key = "WidgetCustom16", Custom = 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; } //If it's an enum DataType then this is the specific enum type which sb the name of the class that holds the enum in the server project public string EnumType { get; set; } public ObjectField() { //most common defaults SharedLTKey = false; Hideable = true; Custom = false; Filterable = true; Sortable = true; MiniAvailable = true; } 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