示例#1
0
        /// <summary>
        /// Sets a join based on the specified relationship class and join type.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="foreignClass">The join.</param>
        /// <param name="layerKeyField">Name of the layer field.</param>
        /// <param name="foreignKeyField">Name of the join field.</param>
        /// <param name="cardinality">The cardinality.</param>
        /// <param name="joinType">Type of the join.</param>
        /// <returns>
        /// Returns a <see cref="IRelQueryTable" /> represents the table and feature join.
        /// </returns>
        public static IRelQueryTable Add(this IFeatureLayer source, IObjectClass foreignClass, string layerKeyField, string foreignKeyField, esriRelCardinality cardinality, esriJoinType joinType)
        {
            IRelQueryTable     result;
            IRelationshipClass relClass;
            var table = ((IDisplayTable)source).DisplayTable as IRelQueryTable;

            if (table != null)
            {
                result   = source.Add(table, foreignClass, string.Format("{0}.{1}", ((IDataset)source.FeatureClass).Name, layerKeyField), foreignKeyField, cardinality, joinType);
                relClass = result.RelationshipClass;
            }
            else
            {
                var layer = (IFeatureClass)((IDisplayTable)source).DisplayTable;
                relClass = layer.Join(foreignClass, layerKeyField, foreignKeyField, cardinality, null);

                var factory = new RelQueryTableFactoryClass();
                result = factory.Open(relClass, true, null, null, "", true, joinType == esriJoinType.esriLeftInnerJoin);
            }

            IDisplayRelationshipClass display = (IDisplayRelationshipClass)source;

            display.DisplayRelationshipClass(relClass, joinType);

            return(result);
        }
示例#2
0
        /// <summary>
        ///     Sets a join based on the specified relationship class and join type.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="table">The table.</param>
        /// <param name="foreignClass">The join.</param>
        /// <param name="layerKeyField">Name of the layer field.</param>
        /// <param name="foreignKeyField">Name of the join field.</param>
        /// <param name="cardinality">The cardinality.</param>
        /// <param name="joinType">Type of the join.</param>
        /// <returns>
        /// Returns a <see cref="IRelQueryTable" /> represents the table and feature join.
        /// </returns>
        public static IRelQueryTable Add(this IFeatureLayer source, IRelQueryTable table, IObjectClass foreignClass, string layerKeyField, string foreignKeyField, esriRelCardinality cardinality, esriJoinType joinType)
        {
            if (source != null)
            {
                var factory = new RelQueryTableFactoryClass();
                var origin  = factory.Open(table.RelationshipClass, true, null, null, "", true, ((IRelQueryTableInfo)table).JoinType == esriJoinType.esriLeftInnerJoin);

                var join   = ((IObjectClass)origin).Join(foreignClass, string.Format("{0}.{1}", ((IDataset)table.SourceTable).Name, layerKeyField), foreignKeyField, cardinality, null);
                var result = factory.Open(join, true, null, null, "", true, joinType == esriJoinType.esriLeftInnerJoin);

                IDisplayRelationshipClass display = (IDisplayRelationshipClass)source;
                display.DisplayRelationshipClass(result.RelationshipClass, joinType);

                return(result);
            }

            return(null);
        }