コード例 #1
0
        // check a numberic field for decimals
        private void btnDecimalsCheck_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboCheckDecimals.SelectedIndex == -1)
                {
                    MessageBox.Show("You must select a field to check.", "Select Field", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // show the cursor as busy
                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

                // query for layer's specified field looking for decimals
                IQueryFilter arcQFilter = new QueryFilter();
                arcQFilter.WhereClause = ""; // strActiveComboBox + " not like '%.0000%'";

                ITable   arcTable   = (ITable)clsGlobals.arcFeatLayer;
                IDataset arcDataset = (IDataset)clsGlobals.arcFeatLayer;

                if (arcDataset.Workspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriLocalDatabaseWorkspace)
                {
                    // fgdb
                    MessageBox.Show("This function has not been coded to work on a file geodatabase... yet.  Talk to Greg Bunce.", "Not on FGDB", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                else if (arcDataset.Workspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                {
                    //sde
                    arcQFilter.WhereClause = cboCheckDecimals.Text.ToString() + " not like '%.0000%'";
                }
                else
                {
                    // shapefile
                    MessageBox.Show("This function has not been coded to work on a shapefile... yet.  Talk to Greg Bunce.", "Not on Shapefile", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // select the records that have decimals
                ISelectionSet arcSelSet = arcTable.Select(arcQFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, arcDataset.Workspace);

                ISelectFeaturesOperation arcSeleFeatOperation;
                arcSeleFeatOperation              = new SelectFeaturesOperationClass();
                arcSeleFeatOperation.ActiveView   = clsGlobals.pActiveView;
                arcSeleFeatOperation.Layer        = clsGlobals.arcFeatLayer;
                arcSeleFeatOperation.SelectionSet = arcSelSet;

                //perform the operation
                clsGlobals.pMxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                IOperationStack arcOperationStack = clsGlobals.pMxDocument.OperationStack;
                arcOperationStack.Do((IOperation)arcSeleFeatOperation);

                clsGlobals.pMxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "Push Utrans Roads to SGID!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #2
0
        // select all the records from the specified field that have null or blank values
        private void btnSelectBlankNulls_Click(object sender, EventArgs e)
        {
            try
            {
                // clear the progress bar, in case it has been used before
                pBar.Value = 1;

                if (cboChooseFields.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select a field from the dropdown list", "Must Select Field", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                //show the cursor as busy
                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

                // cast the layer to itable interface b/c it makes use of the layer's definition query or join, if any.. and does the select based on that
                ITable arcTable = (ITable)clsGlobals.arcFeatLayer;

                IDataset     arcDataset     = (IDataset)clsGlobals.arcFeatLayer;
                IQueryFilter arcQueryFilter = new QueryFilter();
                arcQueryFilter.WhereClause = null;

                // check what type of layer this is, to determine the query syntax
                //shapefile//
                if (arcDataset.Workspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriFileSystemWorkspace)
                {
                    //check the field type, look for either text or double/integer to determine what type of query to set up
                    if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeString)
                    {
                        if (chkNullOnly.Checked == true)
                        {
                            arcQueryFilter.WhereClause = "\"" + cboChooseFields.Text.ToString().Trim() + "\" is null";
                        }
                        else
                        {
                            arcQueryFilter.WhereClause = "\"" + cboChooseFields.Text.ToString().Trim() + "\" is null or \"" + cboChooseFields.Text.ToString().Trim() + "\" = ''";
                        }
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeDouble)
                    {
                        arcQueryFilter.WhereClause = "\"" + cboChooseFields.Text.ToString().Trim() + "\" is null";
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeInteger)
                    {
                        arcQueryFilter.WhereClause = "\"" + cboChooseFields.Text.ToString().Trim() + "\" is null";
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeSmallInteger)
                    {
                        arcQueryFilter.WhereClause = "\"" + cboChooseFields.Text.ToString().Trim() + "\" is null";
                    }
                    else
                    {
                        MessageBox.Show("You're asking to do a query on a field type that is not supported by this code.  If you need this field type to be supported talk to Greg Bunce.  He will make it happen.", "Not Supported Field Type", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                //fgdb//
                if (arcDataset.Workspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriLocalDatabaseWorkspace)
                {
                    //check the field type, look for either text or double/integer to determine what type of query to set up
                    if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeString)
                    {
                        if (chkNullOnly.Checked == true)
                        {
                            arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                        }
                        else
                        {
                            arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null or " + cboChooseFields.Text.ToString().Trim() + " = ''";
                        }
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeDouble)
                    {
                        arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeInteger)
                    {
                        arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeSmallInteger)
                    {
                        arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                    }
                    else
                    {
                        MessageBox.Show("You're asking to do a query on a field type that is not supported by this code.  If you need this field type to be supported talk to Greg Bunce.  He will make it happen.", "Not Supported Field Type", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                //sde//
                if (arcDataset.Workspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                {
                    //check the field type, look for either text or double/integer to determine what type of query to set up
                    if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeString)
                    {
                        if (chkNullOnly.Checked == true)
                        {
                            arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                        }
                        else
                        {
                            arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null or (" + "LTRIM(RTRIM(" + cboChooseFields.Text.ToString().Trim() + ")) = '')";
                        }
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeDouble)
                    {
                        arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeInteger)
                    {
                        arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                    }
                    else if (clsPushSgidStaticClass.GetArcGisFieldType(cboChooseFields.Text) == esriFieldType.esriFieldTypeSmallInteger)
                    {
                        arcQueryFilter.WhereClause = cboChooseFields.Text.ToString().Trim() + " is null";
                    }
                    else
                    {
                        MessageBox.Show("You're asking to do a query on a field type that is currently not supported by this code.  If you need this field type to be supported talk to Greg Bunce.  He will make it happen.", "Not Supported Field Type", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                // select the records that have nulls or blanks
                ISelectionSet arcSelSet = arcTable.Select(arcQueryFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, arcDataset.Workspace);

                ISelectFeaturesOperation arcSeleFeatOperation;
                arcSeleFeatOperation              = new SelectFeaturesOperationClass();
                arcSeleFeatOperation.ActiveView   = clsGlobals.pActiveView;
                arcSeleFeatOperation.Layer        = clsGlobals.arcFeatLayer;
                arcSeleFeatOperation.SelectionSet = arcSelSet;

                //perform the operation
                clsGlobals.pMxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                IOperationStack arcOperationStack = clsGlobals.pMxDocument.OperationStack;
                arcOperationStack.Do((IOperation)arcSeleFeatOperation);

                clsGlobals.pMxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                ////IFeatureLayer arcFeatLayer = clsGlobals.pGFlayer;
                //IFeatureLayerDefinition arcFeatureLayerDef = (IFeatureLayerDefinition)clsGlobals.pGFlayer;
                //string strExistingDefQuery = arcFeatureLayerDef.DefinitionExpression;

                //// select the records that have nulls or blanks
                //IQueryFilter arcQueryFilter = new QueryFilter();
                //arcQueryFilter.WhereClause = "(" + strExistingDefQuery + ") AND " + cboChooseFields.Text.ToString().Trim() + " is null";

                //IDataset arcDataset = (IDataset)clsGlobals.pGFlayer.FeatureClass;
                //ISelectionSet arcSelSet = clsGlobals.pGFlayer.FeatureClass.Select(arcQueryFilter,esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, arcDataset.Workspace);

                //clsGlobals.pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "Push Utrans Roads to SGID error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }