コード例 #1
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();
                }
        }