private static void AddFieldNamesForCategory(string categoryName) { using (var db = new CommenceDatabase()) { fieldNames.Add(categoryName, db.GetFieldNames(categoryName)); } }
public async Task GetMetaDataAsync() { if (string.IsNullOrEmpty(this.CategoryName) || string.IsNullOrEmpty(this.FormName)) { return; } using (ICommenceDatabase db = new CommenceDatabase()) { var connectionList = db.GetConnectionNames(this.CategoryName); if (connectionList != null) { Connections = GetConnections(connectionList).ToList(); } var fields = db.GetFieldNames(this.CategoryName); Fields = GetFields(fields)?.ToList(); } Controls = await Task.Run(() => GetControlList(this.CategoryName, this.FormName)); }
private IEnumerable <object> GetFields(string categoryName) { using (ICommenceDatabase db = new CommenceDatabase()) { var fieldNames = db.GetFieldNames(categoryName); foreach (string fname in fieldNames) { ICommenceFieldDefinition fdef = db.GetFieldDefinition(categoryName, fname); yield return(new { Name = fname, Combobox = fdef.Combobox, DefaultString = fdef.DefaultString, Mandatory = fdef.Mandatory, MaxChars = fdef.MaxChars, Recurring = fdef.Recurring, Shared = fdef.Shared, Type = fdef.Type }); } } }
// TODO: should be async // also, when multiple models are created, we need only one of this dictionary private IList <FieldListItem> PopulateFieldList(string categoryName) { IList <FieldListItem> retval = new List <FieldListItem>(); // TODO wrap in try-catch using (ICommenceDatabase db = new CommenceDatabase()) { foreach (string field in db.GetFieldNames(categoryName)) { retval.Add(new FieldListItem() { FieldName = field, FieldDefinition = db.GetFieldDefinition(categoryName, field), DisplayName = field }); } foreach (ICommenceConnection conn in db.GetConnectionNames(categoryName)) { retval.Add(new FieldListItem() { DisplayName = conn.Name + " " + conn.ToCategory, ConnectionName = conn.Name, ToCategory = conn.ToCategory }); } } // Return only fields with a fielddefinition. // If they do not have a field definiton, // they most likely have a name that DDE commands trip over, // which means that using them in a filter is virtually guaranteed to fail as well. // If we would be really fancy we'd include them with a different color. That is too complex for now. return(retval.Where(w => (w.FieldDefinition != null // exclude fields that cannot be used in a filter && w.FieldDefinition.Type != CommenceFieldType.Image && w.FieldDefinition.Type != CommenceFieldType.Datafile && w.FieldDefinition.Type != CommenceFieldType.ExcelCell) || !string.IsNullOrEmpty(w.ToCategory)) .OrderBy(o => o.FieldName).ToList()); }
private Dictionary <string, Dictionary <char, string> > GetReplacementRulesForCategory(string categoryName) { var retval = new Dictionary <string, Dictionary <char, string> >(); using (var db = new CommenceDatabase()) { var fieldNames = db.GetFieldNames(categoryName); foreach (string f in fieldNames) { var def = db.GetFieldDefinition(categoryName, f); // should we process this field? // we do this by looking if there are any replacement characters // in the dictionary for this fieldtype var dict = GetReplacementCharsForField(def); if (dict.Keys.Any()) { retval.Add(f, dict); } } } return(retval); }