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 { Key = "Name", PropertyName = "Name", SharedLTKey = true, DataType = AyDataType.Text, Hideable = false }); l.Add(new ObjectField { Key = "UserEmployeeNumber", PropertyName = "EmployeeNumber", DataType = AyDataType.Text }); l.Add(new ObjectField { Key = "AuthorizationRoles", PropertyName = "Roles", Hideable = false, DataType = AyDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); l.Add(new ObjectField { Key = "UserNotes", PropertyName = "Notes", DataType = AyDataType.Text }); l.Add(new ObjectField { Key = "UserUserType", PropertyName = "UserType", Hideable = false, DataType = AyDataType.Enum, EnumType = typeof(UserType).ToString() }); 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 = "UserCustom1", Custom = true }); l.Add(new ObjectField { Key = "UserCustom2", Custom = true }); l.Add(new ObjectField { Key = "UserCustom3", Custom = true }); l.Add(new ObjectField { Key = "UserCustom4", Custom = true }); l.Add(new ObjectField { Key = "UserCustom5", Custom = true }); l.Add(new ObjectField { Key = "UserCustom6", Custom = true }); l.Add(new ObjectField { Key = "UserCustom7", Custom = true }); l.Add(new ObjectField { Key = "UserCustom8", Custom = true }); l.Add(new ObjectField { Key = "UserCustom9", Custom = true }); l.Add(new ObjectField { Key = "UserCustom10", Custom = true }); l.Add(new ObjectField { Key = "UserCustom11", Custom = true }); l.Add(new ObjectField { Key = "UserCustom12", Custom = true }); l.Add(new ObjectField { Key = "UserCustom13", Custom = true }); l.Add(new ObjectField { Key = "UserCustom14", Custom = true }); l.Add(new ObjectField { Key = "UserCustom15", Custom = true }); l.Add(new ObjectField { Key = "UserCustom16", Custom = true }); break; default: throw new System.ArgumentOutOfRangeException($"ObjectFields: {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 ObjectFields 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