예제 #1
0
        /// <summary>
        ///     Constructs the filter used to query the intermediate table.
        /// </summary>
        /// <param name="relationshipObject">The relationship object.</param>
        /// <returns>
        ///     The <see cref="IQueryFilter" /> that is used to query the relationship.
        /// </returns>
        private IQueryFilter ConstructFilter(IObject relationshipObject)
        {
            IQueryFilter filter = new QueryFilterClass();

            if (relationshipObject.Class.AliasName == this.RelationshipClass.OriginClass.AliasName)
            {
                int originIndex = relationshipObject.Fields.FindField(this.RelationshipClass.OriginPrimaryKey);
                if (originIndex == -1)
                {
                    return(null);
                }

                object originPrimaryKey = relationshipObject.get_Value(originIndex);
                filter.WhereClause = string.Format(CultureInfo.InvariantCulture, "{0} = '{1}'", this.RelationshipClass.OriginForeignKey, originPrimaryKey);
            }
            else
            {
                int destinationIndex = relationshipObject.Fields.FindField(this.RelationshipClass.DestinationPrimaryKey);
                if (destinationIndex == -1)
                {
                    return(null);
                }

                object destinationPrimaryKey = relationshipObject.get_Value(destinationIndex);
                filter.WhereClause = string.Format(CultureInfo.InvariantCulture, "{0} = '{1}'", this.RelationshipClass.DestinationForeignKey, destinationPrimaryKey);
            }

            ITable table = (ITable)this.RelationshipClass;
            IQueryFilterDefinition queryDef = (IQueryFilterDefinition)filter;

            queryDef.PostfixClause = "ORDER BY " + table.OIDFieldName + " ASC";

            return(filter);
        }
예제 #2
0
        private static object HasMany(this IActiveRecord wrapper, FieldAttribute relationshipAttribute)
        {
            if (!(relationshipAttribute is RelationshipAttribute))
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(),
                                                         "O atributo não é do tipo HasMany. Não foi possível retornar os objetos relacionados.");
            }

            HasManyAttribute hasMany = relationshipAttribute as HasManyAttribute;

            object[] customAttributes = hasMany.ClassType.GetCustomAttributes(typeof(RepositoryAttribute), true);
            if (customAttributes.Length != 1)
            {
                throw new ActiveRecordAttributeException(hasMany.ClassType, "Não foi possível encontrar o controlador da classe.");
            }

            RepositoryAttribute controlled = (RepositoryAttribute)customAttributes[0];
            object relatedController       = Activator.CreateInstance(controlled.ControllerType);

            if (relatedController == null)
            {
                throw new ActiveRecordAttributeException(controlled.ControllerType, "Não foi possível instanciar o controller.");
            }

            PrimaryFieldAttribute pkAtt = wrapper.GetPrimaryKeyDefinition();

            if (pkAtt == null)
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "Não foi possível encontrar a chave primária da classe.");
            }

            IQueryFilter filter = new QueryFilterClass();

            filter.WhereClause = String.Format(pkAtt.QuoteValue ? "{0} = '{1}'" : "{0} = {1}", hasMany.FieldName, wrapper.UnderlyingObject.get_Value(pkAtt.Index));

            if (!String.IsNullOrEmpty(hasMany.OrderBy))
            {
                IQueryFilterDefinition definition = filter as IQueryFilterDefinition;
                definition.PostfixClause = hasMany.OrderBy;
            }

            // prepare the method for invoke
            // check if the method is lazy or not
            MethodInfo filterMethod = null;

            filterMethod = controlled.ControllerType.GetMethod(hasMany.Lazy ? "FilterLazy" : "Filter");

            var parameters = new object[1];

            parameters[0] = filter;

            // invoke and return
            return(filterMethod.Invoke(relatedController, parameters));
        }
        /// <summary>
        /// Gets a list of the jobs stored in the current WMX database that match the specified
        /// query filter.
        /// </summary>
        /// <returns>A sorted list of the job IDs</returns>
        private SortedList <int, string> ListJobsInDatabase(string filter)
        {
            SortedList <int, string> jobIds = new SortedList <int, string>();

            // Build up a query that will return the job IDs filtered by the provided query string
            IQueryFilter           query    = new QueryFilterClass();
            IQueryFilterDefinition queryDef = query as IQueryFilterDefinition;

            query.WhereClause      = filter;
            queryDef.PostfixClause = "ORDER BY " + Constants.FIELD_JOBID;

            IFeatureWorkspace featureWorkspace = this.WmxDatabase.JTXWorkspace as IFeatureWorkspace;

            // Declare some of these ComReleaser objects to help ensure that cursors, etc., are
            // immediately released after they go out of scope.
            using (ComReleaser cr1 = new ComReleaser(), cr2 = new ComReleaser())
            {
                // Get the name of the correct table from the jobs workspace, so
                // that the table doesn't have to be owned by the connecting user.
                string tableName = Common.WmauHelperFunctions.GetQualifiedTableName(Constants.JTX_TABLE_JTX_JOBS_TABLE, this.WmxDatabase.JTXWorkspace);

                ITable jobsTable = featureWorkspace.OpenTable(tableName);
                cr1.ManageLifetime(jobsTable);
                ICursor searchCursor = jobsTable.Search(query, true);
                cr2.ManageLifetime(searchCursor);

                // Store the ID and name of each job matching this query
                int  idIndex   = jobsTable.FindField(Constants.FIELD_JOBID);
                int  nameIndex = jobsTable.FindField(Constants.FIELD_JOBNAME);
                IRow row       = null;
                while ((row = searchCursor.NextRow()) != null)
                {
                    string targetIdxStr = row.get_Value(idIndex).ToString();
                    int    targetIdx    = -1;
                    try
                    {
                        // NOTE: Have seen cases where the JTX_JOBS table contained a row with
                        // nothing but null attributes; since this function accesses the table
                        // directly, try to protect against this error.
                        targetIdx = int.Parse(targetIdxStr);
                    }
                    catch (Exception ex)
                    {
                        throw new WmauException(WmauErrorCodes.C_JOB_ID_PARSE_ERROR, ex);
                    }
                    string targetValStr = row.get_Value(nameIndex).ToString();
                    jobIds[targetIdx] = targetValStr;
                }
            }

            return(jobIds);
        }
예제 #4
0
        internal static List <object[]> Search(string searchText, TableDropdownDataContext item, string field)
        {
            LogLog.Instance.Logger[LogLogEnum.Debug]("Search");
            LogLog.Instance.Logger[LogLogEnum.Debug]($"{searchText},{field}");

            // get the fields back from the dataset item and check the type

            try {
                List <object[]> results     = new List <object[]>();
                IQueryFilter    queryFilter = new QueryFilterClass();
                // handle ints etc where they will need a =
                esriFieldType aType = Utility.ReturnFieldType(item.Value, field);
                queryFilter.WhereClause = QueryMap[aType](field, searchText);
                LogLog.Instance.Logger[LogLogEnum.Debug](queryFilter.WhereClause);
                // Use the PostfixClause to alphabetically order the set by name.
                IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;
                queryFilterDef.PostfixClause = $"ORDER BY {field}";
                // Output the returned names and addresses.
                if (item.Value.Type == esriDatasetType.esriDTTable)
                {
                    ITable table = item.Value as ITable;
                    if (table != null)
                    {
                        using (ComReleaser comReleaser = new ComReleaser()) {
                            ICursor cursor = table.Search(queryFilter, true);
                            comReleaser.ManageLifetime(cursor);
                            IRow row = null;
                            while ((row = cursor.NextRow()) != null)
                            {
                                var oa = new object[item.Fields.Count];
                                foreach (string fdName in item.Fields)
                                {
                                    int    fdIndex = table.FindField(fdName);
                                    String fdValue = Convert.ToString(row.get_Value(fdIndex));
                                    Debug.WriteLine(fdValue);
                                    oa[fdIndex] = fdValue;
                                }
                                results.Add(oa);
                            }
                        }
                    }
                }
                return(results);
            } catch (Exception e) {
                LogLog.Instance.Logger[LogLogEnum.Error](e.Message);
                throw;
            }
        }
예제 #5
0
 /// <summary>
 /// 空间特征查询排序
 /// </summary>
 /// <params name="pfeatureclass">操作的 pfeatureclass</params>
 /// <params name="strSQL">查询条件sql 语句的where 后面的</params>
 /// <params name="PostfixClause">order by  xxxx</params>
 ///<returns>查询结果集的游标</returns>
 public static IFeatureCursor FeatureSorting(IFeatureClass pfeatureclass, string strSQL, string PostfixClause)
 {
     try
     {
         IQueryFilter pQ = new QueryFilterClass();
         pQ.WhereClause = strSQL;
         IQueryFilterDefinition pQueryDef = (IQueryFilterDefinition)pQ;
         pQueryDef.PostfixClause = PostfixClause;
         IFeatureCursor Res = pfeatureclass.Search(pQ, false);
         return(Res);
     }
     catch
     {
         return(null);
     }
 }
예제 #6
0
 //Returns rows from defaults table which match this object's table name or wildcard
 private void getDefaultRows(IObject inObject, out ICursor outCursor)
 {
     if (m_dynDefaults != null)
     {
         IDataset               dataset    = inObject.Class as IDataset;
         IQueryFilter           qFilter    = new QueryFilterClass();
         IQueryFilterDefinition qFilterDef = qFilter as IQueryFilterDefinition;
         //qFilterDef.PostfixClause = "ORDERBY TABLENAME";
         string[] items = dataset.Name.Split('.');
         string   name  = items[items.GetLength(0) - 1];
         qFilter.WhereClause = "TABLENAME = '" + name + "' or TABLENAME = '" + name.ToUpper() + "' or TABLENAME = '*'";
         outCursor           = m_dynDefaults.Search(qFilter, true) as ICursor;
     }
     else
     {
         outCursor = null;
     }
     return;
 }
예제 #7
0
        private static void PerformTableQuery(IWorkspace pWorkspace)
        {
            //Open table
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            ITable            pTableOwner       = pFeatureWorkspace.OpenTable("BoringLocations");


            // Create the query filter.
            IQueryFilter queryFilter = new QueryFilterClass();

            // Select the fields to be returned—the name and address of the businesses.
            queryFilter.SubFields = "OBJECTID, LOCATION, POINT_X, POINT_Y";

            // Set the filter to return only restaurants.
            queryFilter.WhereClause = "OBJECTID>5 ";

            // Use the PostfixClause to alphabetically order the set by name.
            IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;

            queryFilterDef.PostfixClause = "ORDER BY OBJECTID";

            // Output the returned names and addresses.
            int ObjectIndex   = pTableOwner.FindField("OBJECTID");
            int LocationIndex = pTableOwner.FindField("LOCATION");

            using (ComReleaser comReleaser = new ComReleaser())
            {
                ICursor cursor = pTableOwner.Search(queryFilter, true);

                comReleaser.ManageLifetime(cursor);
                IRow row = null;
                while ((row = cursor.NextRow()) != null)
                {
                    String Object   = Convert.ToString(row.get_Value(ObjectIndex));
                    String Location = Convert.ToString(row.get_Value(LocationIndex));
                    Console.WriteLine("{0} - {1}", Object, Location);
                    System.Diagnostics.Debug.WriteLine("{0} - {1}", Object, Location);
                    Console.Read();
                }
            }
        }
예제 #8
0
        //-----------------------------------------------------------------------------------------------
        // This function creates the cross reference between the ArcMAP feature ID (ObjectID) and
        // our CompWorks ID;
        //-----------------------------------------------------------------------------------------------
        public bool UpdateCrossReference(string layerName)
        {
            string layername = layerName;

            if (layername.Length == 0)
            {
                return(false);
            }
            //Open table
            IFeatureWorkspace pFeatureWorkspace = _workspace as IFeatureWorkspace;
            //IFeature pBLID;
            ITable pTableOwner = pFeatureWorkspace.OpenTable(layername);
            // Create the query filter.
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.SubFields = _layers.AttributeIndexName(layername) + ", " + pTableOwner.OIDFieldName;

            IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;
            int  CWFieldIndex      = pTableOwner.FindField(_layers.AttributeIndexName(layername));
            int  FeatureFieldIndex = pTableOwner.FindField(pTableOwner.OIDFieldName);
            bool done = false;

            using (ComReleaser comReleaser = new ComReleaser())
                try
                {
                    ICursor cursor = pTableOwner.Search(queryFilter, true);
                    comReleaser.ManageLifetime(cursor);
                    IRow row = null;
                    while ((row = cursor.NextRow()) != null)
                    {
                        int cwid = Convert.ToInt32(row.get_Value(CWFieldIndex).ToString());
                        int fid  = Convert.ToInt32(row.get_Value(FeatureFieldIndex).ToString());
                        done = _cwdata.linesectionSetRecordCrossReference(cwid, fid);
                    }
                }
                catch (Exception err)
                {
                    string M = err.Message;
                }
            return(false);
        }
예제 #9
0
        /// <summary>
        ///     Constructs the filter used to query the intermediate table.
        /// </summary>
        /// <param name="originObject">The origin object.</param>
        /// <param name="destinationObject">The destination object.</param>
        /// <returns>
        ///     The <see cref="IQueryFilter" /> that is used to query the relationship.
        /// </returns>
        private IQueryFilter ConstructFilter(IObject originObject, IObject destinationObject)
        {
            int originIndex      = originObject.Fields.FindField(this.RelationshipClass.OriginPrimaryKey);
            int destinationIndex = destinationObject.Fields.FindField(this.RelationshipClass.DestinationPrimaryKey);

            object originPrimaryKey      = originObject.get_Value(originIndex);
            object destinationPrimaryKey = destinationObject.get_Value(destinationIndex);

            IQueryFilter filter = new QueryFilterClass();

            filter.WhereClause = string.Format(CultureInfo.InvariantCulture, "{0} = '{1}' AND {2} = '{3}'",
                                               this.RelationshipClass.OriginForeignKey, originPrimaryKey,
                                               this.RelationshipClass.DestinationForeignKey, destinationPrimaryKey);

            ITable table = (ITable)this.RelationshipClass;
            IQueryFilterDefinition queryDef = (IQueryFilterDefinition)filter;

            queryDef.PostfixClause = "ORDER BY " + table.OIDFieldName + " ASC";

            return(filter);
        }
예제 #10
0
        private void btnOKNextScale_Click(object sender, EventArgs e)
        {
            if (!CheckRequirements())
            {
                return;
            }

            IFeatureLayer buildingslayer = _utilitiesArcMap.FeatureLayer(this.cboBuildingLayer.Text);

            try
            {
                if (buildingslayer != null)
                {
                    int indexField           = _utilitiesArcMap.FindField(buildingslayer, "rsi_index");
                    int inspectionfieldindex = _utilitiesArcMap.FindField(buildingslayer, "rsi");

                    IFeatureClass     buildingsfeatureclass     = buildingslayer.FeatureClass;
                    IFeatureSelection buildingsfeatureselection = buildingslayer as IFeatureSelection;
                    if (buildingsfeatureselection.SelectionSet.Count > 0)
                    {
                        Update(1, buildingslayer);
                    }

                    IFeatureCursor featurecursor = null;
                    IQueryFilter   queryfilter   = new QueryFilterClass();
                    queryfilter.WhereClause = "\"rsi\" IS NULL";


                    if (indexField > -1)
                    {
                        queryfilter.SubFields = "rsi_index";
                        IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryfilter;
                        queryFilterDef.PostfixClause = "ORDER BY rsi_index";
                    }

                    featurecursor = buildingsfeatureclass.Search(queryfilter, false);

                    IFeature feature = null;

                    while ((feature = featurecursor.NextFeature()) != null)
                    {
                        IPolygon  polygon  = feature.Shape as IPolygon;
                        IPolyline polyline = feature.Shape as IPolyline;

                        if ((polygon != null) || (polyline != null))
                        {
                            buildingsfeatureselection.Clear();
                            buildingsfeatureselection.Add(feature);
                            buildingsfeatureselection.SelectionChanged();
                            IEnumGeometry     enumgeometry     = new EnumFeatureGeometryClass();
                            IEnumGeometryBind enumgeometrybind = enumgeometry as IEnumGeometryBind;
                            enumgeometrybind.BindGeometrySource(null, buildingsfeatureselection.SelectionSet);
                            IGeometryFactory geometryfactory = new GeometryEnvironmentClass();
                            IGeometry        geometry        = geometryfactory.CreateGeometryFromEnumerator(enumgeometry);

                            double    scale    = _map.MapScale;
                            IEnvelope envelope = geometry.Envelope;
                            _activeView.Extent = envelope;
                            _map.MapScale      = scale;
                            _activeView.Refresh();

                            GetStatus();

                            return;
                        }

                        IPoint point = feature.Shape as IPoint;
                        if (point != null)
                        {
                            buildingsfeatureselection.Clear();
                            buildingsfeatureselection.Add(feature);
                            buildingsfeatureselection.SelectionChanged();
                            double    scale    = _map.MapScale;
                            IEnvelope envelope = _activeView.Extent;
                            envelope.CenterAt(point);
                            _activeView.Extent = envelope;
                            _map.MapScale      = scale;
                            _activeView.Refresh();

                            GetStatus();

                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Building Inspector", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                //_restartreport = false;
            }
        }