Files
raven/server/AyaNova/biz/ObjectFields.cs
2020-01-14 21:57:00 +00:00

164 lines
9.5 KiB
C#

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<string> AvailableObjectKeys
{
get
{
List<string> l = new List<string>{
WIDGET_KEY, USER_KEY
};
return l;
}
}
public static bool IsValidObjectKey(string key)
{
return AvailableObjectKeys.Contains(key);
}
public static List<ObjectField> 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<ObjectField> l = new List<ObjectField>();
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", PropertyName = "WidgetCustom1", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom2", PropertyName = "WidgetCustom2", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom3", PropertyName = "WidgetCustom3", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom4", PropertyName = "WidgetCustom4", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom5", PropertyName = "WidgetCustom5", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom6", PropertyName = "WidgetCustom6", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom7", PropertyName = "WidgetCustom7", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom8", PropertyName = "WidgetCustom8", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom9", PropertyName = "WidgetCustom9", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom10", PropertyName = "WidgetCustom10", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom11", PropertyName = "WidgetCustom11", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom12", PropertyName = "WidgetCustom12", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom13", PropertyName = "WidgetCustom13", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom14", PropertyName = "WidgetCustom14", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom15", PropertyName = "WidgetCustom15", Custom = true });
l.Add(new ObjectField { Key = "WidgetCustom16", PropertyName = "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", PropertyName = "UserCustom1", Custom = true });
l.Add(new ObjectField { Key = "UserCustom2", PropertyName = "UserCustom2", Custom = true });
l.Add(new ObjectField { Key = "UserCustom3", PropertyName = "UserCustom3", Custom = true });
l.Add(new ObjectField { Key = "UserCustom4", PropertyName = "UserCustom4", Custom = true });
l.Add(new ObjectField { Key = "UserCustom5", PropertyName = "UserCustom5", Custom = true });
l.Add(new ObjectField { Key = "UserCustom6", PropertyName = "UserCustom6", Custom = true });
l.Add(new ObjectField { Key = "UserCustom7", PropertyName = "UserCustom7", Custom = true });
l.Add(new ObjectField { Key = "UserCustom8", PropertyName = "UserCustom8", Custom = true });
l.Add(new ObjectField { Key = "UserCustom9", PropertyName = "UserCustom9", Custom = true });
l.Add(new ObjectField { Key = "UserCustom10", PropertyName = "UserCustom10", Custom = true });
l.Add(new ObjectField { Key = "UserCustom11", PropertyName = "UserCustom11", Custom = true });
l.Add(new ObjectField { Key = "UserCustom12", PropertyName = "UserCustom12", Custom = true });
l.Add(new ObjectField { Key = "UserCustom13", PropertyName = "UserCustom13", Custom = true });
l.Add(new ObjectField { Key = "UserCustom14", PropertyName = "UserCustom14", Custom = true });
l.Add(new ObjectField { Key = "UserCustom15", PropertyName = "UserCustom15", Custom = true });
l.Add(new ObjectField { Key = "UserCustom16", PropertyName = "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; }
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;
}
}
}//ens