コード例 #1
0
 private IEnumerable <ICommenceConnection> GetConnections(string categoryName)
 {
     using (ICommenceDatabase db = new CommenceDatabase())
     {
         return(db.GetConnectionNames(categoryName));
     }
 }
コード例 #2
0
 private static void RefreshConnections()
 {
     using (var db = new CommenceDatabase())
     {
         foreach (string c in Categories)
         {
             connections.Add(c, db.GetConnectionNames(c));
         }
     }
 }
コード例 #3
0
        private void SetPropertiesByView(string viewName)
        {
            // if we have just a view, everything changes
            // we need to create the fieldnames and the connected fields from the columns in the view.
            // This is non-trivial, because of the mess Commence makes with representing rlated columns.
            // for some viewtypes it is '%%', for others it is a space.
            IEnumerable <ICommenceConnection> connNames;
            IEnumerable <string>  viewColumns;
            List <string>         directColumns    = new List <string>();
            List <ConnectedField> connectedColumns = new List <ConnectedField>();

            using (var db = new CommenceDatabase())
                using (var cur = db.GetCursor(viewName, CmcCursorType.View, CmcOptionFlags.Default))
                {
                    connNames   = db.GetConnectionNames(cur.Category);
                    viewColumns = db.GetViewColumnNames(viewName);
                    // loop through all columns to determine if they are a direct field or a connection
                    foreach (var vc in viewColumns)
                    {
                        if (vc.Contains(connDelim))
                        {
                            string[] cc = vc.Split(new string[] { connDelim }, StringSplitOptions.None);
                            if (cc.Length == 3)
                            {
                                connectedColumns.Add(new ConnectedField(cc[0], cc[1], cc[2]));
                            }
                        }
                        else if (vc.Contains(' '))
                        {
                            foreach (ICommenceConnection c in connNames)
                            {
                                if (vc.StartsWith(c.Name) && vc.EndsWith(c.ToCategory) &&
                                    vc.Length == c.Name.Length + c.ToCategory.Length + 1)
                                {
                                    connectedColumns.Add(new ConnectedField(c.Name, c.ToCategory, db.GetNameField(c.ToCategory)));
                                    break;
                                }
                            }
                        }
                        else // a direct column
                        {
                            directColumns.Add(vc);
                        }
                    }
                    FieldNames      = directColumns?.ToArray();
                    ConnectedFields = connectedColumns?.ToArray();
                }
        }
コード例 #4
0
 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));
 }
コード例 #5
0
        // 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());
        }
コード例 #6
0
        /// <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);
        }