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); }
/// <summary> /// Gets all the field and column information from Commence. /// </summary> protected internal List <ColumnDefinition> ParseColumns() { _columnDefinitions = new List <ColumnDefinition>(); using (ICommenceDatabase db = new CommenceDatabase()) { // can't use using here, because we would close the database prematurely and lose our cursor. Not sure why that happens, it is a new reference?. _connNames = db.GetConnectionNames(_cursor.Category); // retrieve all connections for current category. Used to check columns against. if (_connNames != null) // there are connections { // retrieve name field names from connections if (_connectedNameFields == null) { _connectedNameFields = GetNameFieldsFromConnectedCategories(_connNames); } } // inject extra columndefintion for thid // it should always be the first definition! // this is a little tricky if (((CommenceCursor)_cursor).Flags.HasFlag(CmcOptionFlags.UseThids)) { ColumnDefinition cd = new ColumnDefinition(0, ColumnDefinition.ThidIdentifier) { FieldName = ColumnDefinition.ThidIdentifier, CustomColumnLabel = ColumnDefinition.ThidIdentifier, ColumnLabel = ColumnDefinition.ThidIdentifier, Category = _cursor.Category, CommenceFieldDefinition = new CommenceFieldDefinition() // provide empty definition to prevent DDEException on GetFieldDefinition }; _columnDefinitions.Add(cd); } // process actual columns using (CmcLibNet.Database.ICommenceQueryRowSet qrs = _cursor.GetQueryRowSet(0)) { // create a rowset of 0 items for (int i = 0; i < qrs.ColumnCount; i++) { ColumnDefinition cd = new ColumnDefinition(_columnDefinitions.Count, qrs.GetColumnLabel(i, CmcOptionFlags.Fieldname)); cd.ColumnLabel = qrs.GetColumnLabel(i); if (this._customHeaders != null) { cd.CustomColumnLabel = this._customHeaders[i]; } if (ColumnIsConnection(cd.ColumnName)) // we have a connection { IRelatedColumn rc = GetRelatedColumn(cd.ColumnName); cd.RelatedColumn = rc; if (((CommenceCursor)_cursor).Flags.HasFlag(CmcOptionFlags.UseThids)) { cd.CommenceFieldDefinition = new CommenceFieldDefinition() { MaxChars = CommenceLimits.MaxNameFieldCapacity, Type = CommenceFieldType.Text }; } else { cd.CommenceFieldDefinition = db.GetFieldDefinition(rc.Category, rc.Field); } } else // we have a direct field { cd.Category = _cursor.Category; cd.FieldName = cd.ColumnName; cd.CommenceFieldDefinition = db.GetFieldDefinition(cd.Category, cd.FieldName); } _columnDefinitions.Add(cd); } } } return(_columnDefinitions); }