Example #1
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            try
            {
                StandaloneTable standaloneTable = await QueuedTask.Run(() =>
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);

                    var map        = MapView.Active.Map;
                    var linesLayer = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault((m => m.Name == "Sewer Lines"));

                    // Get the currently selected features in the map
                    var selectedFeatures = map.GetSelection();
                    var selectCount      = linesLayer.SelectionCount;

                    if (selectCount == 0)
                    {
                        MessageBox.Show("No Sewer Line was selected.\n\nTry selection again.");
                    }

                    else if (selectCount > 1)
                    {
                        MessageBox.Show("More than one sewer line was selected.\n" +
                                        "Try selecting sewer line again.\nZooming in may help.");
                    }

                    else
                    {
                        pipeID = SysModule.GetPipeID();
                        if (!string.IsNullOrEmpty(pipeID))
                        {
                            Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                            // Set up Geodatabase Object)
                            using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                            {
                                string queryString = $"PIPE_ID = '{pipeID}'";
                                QueryDef queryDef  = new QueryDef()
                                {
                                    Tables      = "SDE.sewerman.tblEAM_PM",
                                    WhereClause = queryString,
                                    SubFields   = "PIPE_ID, TASK, PREVDATE, NEXTDATE, INTERVAL, UNIT, OBJECTID",
                                };

                                QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                                {
                                    MakeCopy    = true,
                                    Name        = $"Preventive Maintenance: {pipeID}",
                                    PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblEAM_PM", "PIPE_ID")
                                };

                                Table queryTable = geodatabase.OpenQueryTable(queryTableDescription);

                                int count = queryTable.GetCount();
                                if (count == 0)
                                {
                                    MessageBox.Show("Sewer line selected has no preventive maintenance scheduled.");
                                }

                                else
                                {
                                    // Create a standalone table from the queryTable Table
                                    IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                    StandaloneTable pmTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                    return(pmTable);
                                }
                            }
                        }
                        ;
                    }
                    return(null);
                });

                // Open the standalone table pane
                FrameworkApplication.Panes.OpenTablePane(standaloneTable, TableViewMode.eAllRecords);
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occured";
                string message = "Process failed.\nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
            return(true);
        }
Example #2
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            try
            {
                var standaloneTable = await QueuedTask.Run(() =>
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);

                    var map   = MapView.Active.Map;
                    var mh    = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(m => m.Name == "Manholes");
                    var lines = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines");

                    // Get the number of selections for manholes layer
                    var selectedFeatures = map.GetSelection();
                    var mhSelectCount    = mh.SelectionCount;
                    var linesSelectCount = lines.SelectionCount;
                    Uri path             = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                    // If Manholes layer has selection, remove lines selection and query work history for manhole selected.
                    if (mhSelectCount == 1)
                    {
                        lines.ClearSelection();
                        mhID = SysModule.GetManholeID();
                        //Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                        // Set up Geodatabase Object)
                        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                        {
                            string queryString = $"MH_ID = '{mhID}'";
                            QueryDef queryDef  = new QueryDef()
                            {
                                Tables      = "SDE.sewerman.tblEAM_Manhole_Work",
                                WhereClause = queryString,
                            };

                            QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                            {
                                MakeCopy    = true,
                                Name        = $"Manhole work history: {mhID}",
                                PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblEAM_Manhole_Work", "MH_ID")
                            };

                            var queryTable = geodatabase.OpenQueryTable(queryTableDescription);
                            int count      = queryTable.GetCount();
                            if (count == 0)
                            {
                                MessageBox.Show("Manhole selected has no work history.");
                                return(null);
                            }

                            else
                            {
                                // Create a standalone table from the queryTable Table
                                IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                StandaloneTable whTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                return(whTable);
                            }
                        }
                    }

                    // Query work history forSewer Lines selection
                    else if (linesSelectCount == 1)
                    {
                        pipeID = SysModule.GetPipeID();
                        //Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                        // Set up Geodatabase Object)
                        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                        {
                            string queryString = $"PIPE_ID = '{pipeID}'";
                            QueryDef queryDef  = new QueryDef()
                            {
                                Tables      = "SDE.sewerman.tblEAM_Sewer_Work",
                                WhereClause = queryString,
                            };

                            QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                            {
                                MakeCopy    = true,
                                Name        = $"Sewer line work history: {pipeID}",
                                PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblEAM_Sewer_Work", "PIPE_ID")
                            };

                            var queryTable = geodatabase.OpenQueryTable(queryTableDescription);

                            int count = queryTable.GetCount();
                            if (count == 0)
                            {
                                MessageBox.Show("Sewer line selected has no work history.");
                                return(null);
                            }

                            else
                            {
                                // Create a standalone table from the queryTable Table
                                IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                StandaloneTable whTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                return(whTable);
                            }
                        }
                    }

                    else if (linesSelectCount == 0 && mhSelectCount == 0)
                    {
                        MessageBox.Show("No manhole or sewer line was selected.\n\nTry selection again.");
                    }

                    else if (linesSelectCount > 1 && mhSelectCount == 0)
                    {
                        MessageBox.Show("More than one sewer line was selected. " +
                                        "\nPlease select a single sewer. " +
                                        "\nZooming in may help.");
                    }

                    else if (mhSelectCount > 1 && linesSelectCount == 0)
                    {
                        MessageBox.Show("More than one manhole was selected. " +
                                        "\nPlease select a single manhole. " +
                                        "\nZooming in may help.");
                    }

                    else if (mhSelectCount > 1 && linesSelectCount > 1)
                    {
                        MessageBox.Show("More than one sewer feature was selected. " +
                                        "\nPlease select a single feature. " +
                                        "\nZooming in may help.");
                    }
                    return(null);
                });

                // Open the standalone table pane
                FrameworkApplication.Panes.OpenTablePane(standaloneTable, TableViewMode.eAllRecords);
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occured";
                string message = "Process failed.\nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
            return(true);
            //return base.OnSketchCompleteAsync(geometry);
        }
        /// <summary>
        /// The on comboBox selection change event. This creates a new table that lists the assignments for the specified category.  This table is added to the map, selected in the TOC, and opened.
        /// </summary>
        /// <param name="item">The newly selected combo box item</param>
        protected override async void OnSelectionChange(ComboBoxItem item)
        {
            if (item == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(item.Text))
            {
                return;
            }

            if (myLayer == null)
            {
                return;
            }

            //Construct the name of our table for the category assignment report
            string baseCategoryReportTableName = "CategoryAssignments_" + item.Text;
            string categoryReportTableName     = baseCategoryReportTableName.Replace(" ", "_");

            bool needToCreateTable        = true;
            bool needToAddStandaloneTable = true;

            // Switch to the MCT to access the geodatabase
            await QueuedTask.Run(() =>
            {
                // Check if the table exists

                using (Geodatabase projectWorkspace = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath))))
                {
                    try
                    {
                        using (Table categoryReportTable = projectWorkspace.OpenDataset <Table>(categoryReportTableName))
                        {
                            // Table exists, we do not need to create it...
                            needToCreateTable = false;

                            // .. but we should delete the existing contents
                            categoryReportTable.DeleteRows(new QueryFilter());

                            // Check to see if a Standalone table exists in the map
                            bool standaloneTableFound = false;
                            ReadOnlyObservableCollection <StandaloneTable> initialStandaloneTables = MapView.Active.Map.StandaloneTables;
                            foreach (StandaloneTable standaloneTable in initialStandaloneTables)
                            {
                                if (standaloneTable.Name == categoryReportTableName)
                                {
                                    standaloneTableFound = true;
                                }
                            }

                            // Since there is already a StandaloneTable that references our category table in the map, we don't need to add it
                            needToAddStandaloneTable = !standaloneTableFound;
                        }
                    }
                    catch
                    {
                        //Table doesn't exist.  Not an error, but we will have to create it
                    }
                }
            });

            // Create the category report table

            if (needToCreateTable)
            {
                // Create table
                IReadOnlyList <string> createParams = Geoprocessing.MakeValueArray(new object[] { Project.Current.DefaultGeodatabasePath, categoryReportTableName, null, null });
                IGPResult result = await Geoprocessing.ExecuteToolAsync("management.CreateTable", createParams);

                if (result.IsFailed)
                {
                    MessageBox.Show("Unable to create category assignment table in project workspace", "Category Assignments");
                    return;
                }

                // Add field for feature class alias
                IReadOnlyList <string> addFieldParams = Geoprocessing.MakeValueArray(new object[] { categoryReportTableName, "FeatureClassAlias", "TEXT", null, null, 32, "Feature Class", "NULLABLE", "NON_REQUIRED", null });
                result = await Geoprocessing.ExecuteToolAsync("management.AddField", addFieldParams);

                if (result.IsFailed)
                {
                    MessageBox.Show("Unable to modify schema of category assignment table in project workspace", "Category Assignments");
                    return;
                }

                // Add field for Asset Group name
                addFieldParams = Geoprocessing.MakeValueArray(new object[] { categoryReportTableName, "AssetGroupName", "TEXT", null, null, 256, "Asset Group Name", "NULLABLE", "NON_REQUIRED", null });
                result         = await Geoprocessing.ExecuteToolAsync("management.AddField", addFieldParams);

                if (result.IsFailed)
                {
                    MessageBox.Show("Unable to modify schema of category assignment table in project workspace", "Category Assignments");
                    return;
                }

                // Add field for Asset Type name
                addFieldParams = Geoprocessing.MakeValueArray(new object[] { categoryReportTableName, "AssetTypeName", "TEXT", null, null, 256, "Asset Type Name", "NULLABLE", "NON_REQUIRED", null });
                result         = await Geoprocessing.ExecuteToolAsync("management.AddField", addFieldParams);

                if (result.IsFailed)
                {
                    MessageBox.Show("Unable to modify schema of category assignment table in project workspace", "Category Assignments");
                    return;
                }

                needToAddStandaloneTable = false; //creating a table automatically adds it to the map
            }


            // Populate table
            // Again, we need to switch to the MCT to execute geodatabase and utility network code
            await QueuedTask.Run(() =>
            {
                using (Geodatabase projectWorkspace = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath))))
                    using (Table categoryReportTable = projectWorkspace.OpenDataset <Table>(categoryReportTableName))
                        using (UtilityNetwork utilityNetwork = UtilityNetworkSamples.UtilityNetworkUtils.GetUtilityNetworkFromLayer(myLayer))
                            using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition())
                            {
                                IReadOnlyList <NetworkSource> networkSources = utilityNetworkDefinition.GetNetworkSources();

                                // Step through each NetworkSource
                                foreach (NetworkSource networkSource in networkSources)
                                {
                                    IReadOnlyList <AssetGroup> assetGroups = networkSource.GetAssetGroups();

                                    // Step through each AssetGroup
                                    foreach (AssetGroup assetGroup in assetGroups)
                                    {
                                        IReadOnlyList <AssetType> assetTypes = assetGroup.GetAssetTypes();

                                        // Step through each AssetType
                                        foreach (AssetType assetType in assetTypes)
                                        {
                                            // Check to see if this AssetType is assigned the Category we are looking for
                                            IReadOnlyList <string> assignedCategoryList = assetType.CategoryList;
                                            foreach (string assignedCategory in assignedCategoryList)
                                            {
                                                if (assignedCategory == item.Text)
                                                {
                                                    // Our Category is assigned to this AssetType.  Create a row to store in the category report table
                                                    using (FeatureClass networkSourceFeatureClass = utilityNetwork.GetTable(networkSource) as FeatureClass)
                                                        using (FeatureClassDefinition networkSourceFeatureClassDefinition = networkSourceFeatureClass.GetDefinition())
                                                            using (RowBuffer rowBuffer = categoryReportTable.CreateRowBuffer())
                                                            {
                                                                rowBuffer["FeatureClassAlias"] = networkSourceFeatureClassDefinition.GetAliasName();
                                                                rowBuffer["AssetGroupName"]    = assetGroup.Name;
                                                                rowBuffer["AssetTypeName"]     = assetType.Name;
                                                                categoryReportTable.CreateRow(rowBuffer).Dispose();
                                                            }
                                                }
                                            }
                                        }
                                    }
                                }

                                // If necessary, add our category report table to the map as a standalone table
                                if (needToAddStandaloneTable)
                                {
                                    IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                    tableFactory.CreateStandaloneTable(categoryReportTable, MapView.Active.Map);
                                }
                            }
            });

            // Open category report stand alone table into a window
            ReadOnlyObservableCollection <StandaloneTable> standaloneTables = MapView.Active.Map.StandaloneTables;

            foreach (StandaloneTable standaloneTable in standaloneTables)
            {
                if (standaloneTable.Name == categoryReportTableName)
                {
                    FrameworkApplication.Panes.OpenTablePane(standaloneTable, TableViewMode.eAllRecords);
                }
            }
        }
Example #4
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            try
            {
                var standaloneTable = await QueuedTask.Run(() =>
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);
                    slComp = Module1.GetCompkey();
                    if (!string.IsNullOrEmpty(slComp))
                    {
                        Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                        // Set up Geodatabase Object)
                        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                        {
                            string queryString = $"COMPKEY = {slComp}";
                            QueryDef queryDef  = new QueryDef()
                            {
                                Tables      = "SDE.sewerman.tblV8PMTOOL",
                                WhereClause = queryString,
                            };

                            QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                            {
                                MakeCopy    = true,
                                Name        = $"Preventive Maintenance: {slComp}",
                                PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblV8PMTOOL", "COMPKEY")
                            };

                            var queryTable = geodatabase.OpenQueryTable(queryTableDescription);

                            int count = queryTable.GetCount();
                            if (count == 0)
                            {
                                MessageBox.Show("Sewer line selected has no preventive maintenance scheduled.");
                            }

                            else
                            {
                                // Create a standalone table from the queryTable Table
                                IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                StandaloneTable pmTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                return(pmTable);
                            }
                        }
                    }
                    ;
                    //return base.OnSketchCompleteAsync(geometry);
                    return(null);
                });

                // Open the standalone table pane
                FrameworkApplication.Panes.OpenTablePane(standaloneTable, TableViewMode.eAllRecords);
            }

            catch (Exception)
            {
                string caption = "Error Occured";
                string message = "Process failed! \nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your local GIS nerd.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
            return(true);
        }