Exemplo n.º 1
0
        public AddEditDataSource(IWorkspace theWorkspace, string selectedDataSourceID = null)
        {
            InitializeComponent();

            // Set Class-level variables
            m_theWorkspace = theWorkspace;
            m_dataSourceAccess = new DataSourcesAccess(theWorkspace);

            // Check to see if a Data Source is selected. If not, adjust form for new DataSource creation
            m_selectedDataSourceID = selectedDataSourceID;

            m_boldFont = (Font)tlbtnEditExisting.Font.Clone();
            m_notBoldFont = new Font(m_boldFont, FontStyle.Regular);

            if (m_selectedDataSourceID == null)
            {
                // Set the fonts appropriately in the form. Nothing to populate.
                tlbtnEditExisting.Font = m_notBoldFont;
                tlbtnNewRecord.Font = m_boldFont;
                tlbtnEditExisting.Enabled = false;
                tlbtnNewRecord.Enabled = false;
                btnSave.Enabled = false;

                m_inUpdateMode = false;
            }
            else
            {
                // Fonts default appropriately. Load Source and Notes from the selected record.
                //m_currentDataSource = new DataSourceRecord(m_theWorkspace, m_selectedDataSourceID);
                m_dataSourceAccess.AddDataSources("DataSources_ID = '" + m_selectedDataSourceID + "'");
                DataSourcesAccess.Datasource thisDataSource = m_dataSourceAccess.DataSourceCollection[m_selectedDataSourceID];

                txtSource.Text = thisDataSource.Source;
                txtNotes.Text = thisDataSource.Notes;

                // Enable the save button
                btnSave.Enabled = true;

                m_inUpdateMode = true;
            }
        }
Exemplo n.º 2
0
        private Dictionary<string, object> BuildDataAccessFromSelection()
        {
            // Will be building SQL Where Clauses for each possible selected thing
            string MapUnitPolysSearch = "MapUnitPolys_ID = '";
            string OverlayPolysSearch = "OverlayPolys_ID = '";
            string ContactsAndFaultsSearch = "ContactsAndFaults_ID = '";
            string OtherLinesSearch = "OtherLines_ID = '";
            string StationPointsSearch = "StationPoints_ID = '";
            string SamplePointsSearch = "SamplePoints_ID = '";
            string OrientationDataPointsSearch = "OrientationDataPoints_ID = '";
            string GlossarySearch = "Glossary_ID = '";
            string NotesSearch = "Notes_ID = '";
            string RelatedDocumentsSearch = "RelatedDocuments_ID = '";
            string DataSourcesSearch = "DataSources_ID = '";
            string DescriptionOfMapUnitsSearch = "DescriptionOfMapUnits_ID = '";

            // This object will be populated and returned
            Dictionary<string, object> dataAccessClasses = new Dictionary<string, object>();

            #region Selected FEATURES
            // Get an enumeration of the selected features
            IEnumFeature selectionEnum = ArcMap.Document.FocusMap.FeatureSelection as IEnumFeature;

            // Loop through the features to build queries to find the features
            IRow thisFeature = selectionEnum.Next() as IRow;

            while (thisFeature != null)
            {
                // Get the Table Name
                string tableName = (thisFeature.Table as IDataset).Name;

                // Parse the table name in order to strip out unneccessary bits of SDE tables
                ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace;
                string parsedDbName, parsedOwnerName, parsedTableName;
                nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName);

                // Build the SQL Where Clause depending on the table...
                switch (parsedTableName)
                {
                    case "MapUnitPolys":
                        MapUnitPolysSearch += thisFeature.get_Value(thisFeature.Table.FindField("MapUnitPolys_ID")) + "' OR MapUnitPolys_ID = '";
                        break;
                    case "OverlayPolys":
                        OverlayPolysSearch += thisFeature.get_Value(thisFeature.Table.FindField("OverlayPolys_ID")) + "' OR OverlayPolys_ID = '";
                        break;
                    case "ContactsAndFaults":
                        ContactsAndFaultsSearch += thisFeature.get_Value(thisFeature.Table.FindField("ContactsAndFaults_ID")) + "' OR ContactsAndFaults_ID = '";
                        break;
                    case "OtherLines":
                        OtherLinesSearch += thisFeature.get_Value(thisFeature.Table.FindField("OtherLines_ID")) + "' OR OtherLines_ID = '";
                        break;
                    case "StationPoints":
                        StationPointsSearch += thisFeature.get_Value(thisFeature.Table.FindField("StationPoints_ID")) + "' OR StationPoints_ID = '";
                        break;
                    case "SamplePoints":
                        SamplePointsSearch += thisFeature.get_Value(thisFeature.Table.FindField("SamplePoints_ID")) + "' OR SamplePoints_ID = '";
                        break;
                    case "OrientationDataPoints":
                        OrientationDataPointsSearch += thisFeature.get_Value(thisFeature.Table.FindField("OrientationDataPoints_ID")) + "' OR OrientationDataPoints_ID = '";
                        break;
                }

                // Iterate the enumeration
                thisFeature = selectionEnum.Next();
            }

            #region "Build Dictionary"
            // Clean up the Where Clauses, create the data access classes, and then add it to the dictionary

            // MapUnitPolys
            if (MapUnitPolysSearch != "MapUnitPolys_ID = '")
            {
                MapUnitPolysSearch = MapUnitPolysSearch.Remove(MapUnitPolysSearch.Length - 23);
                MapUnitPolysAccess MapUnitPolysRecords = new MapUnitPolysAccess(m_theWorkspace);
                MapUnitPolysRecords.AddMapUnitPolys(MapUnitPolysSearch);
                dataAccessClasses.Add("MapUnitPolys", MapUnitPolysRecords);
            }

            // OverlayPolys
            if (OverlayPolysSearch != "OverlayPolys_ID = '")
            {
                OverlayPolysSearch = OverlayPolysSearch.Remove(OverlayPolysSearch.Length - 23);
                OverlayPolysAccess OverlayPolysRecords = new OverlayPolysAccess(m_theWorkspace);
                OverlayPolysRecords.AddOverlayPolys(OverlayPolysSearch);
                dataAccessClasses.Add("OverlayPolys", OverlayPolysRecords);
            }

            // ContactsAndFaults
            if (ContactsAndFaultsSearch != "ContactsAndFaults_ID = '")
            {
                ContactsAndFaultsSearch = ContactsAndFaultsSearch.Remove(ContactsAndFaultsSearch.Length - 28);
                ContactsAndFaultsAccess ContactsAndFaultsRecords = new ContactsAndFaultsAccess(m_theWorkspace);
                ContactsAndFaultsRecords.AddContactsAndFaults(ContactsAndFaultsSearch);
                dataAccessClasses.Add("ContactsAndFaults", ContactsAndFaultsRecords);
            }

            // OtherLines
            if (OtherLinesSearch != "OtherLines_ID = '")
            {
                OtherLinesSearch = OtherLinesSearch.Remove(OtherLinesSearch.Length - 21);
                OtherLinesAccess OtherLinesRecords = new OtherLinesAccess(m_theWorkspace);
                OtherLinesRecords.AddOtherLines(OtherLinesSearch);
                dataAccessClasses.Add("OtherLines", OtherLinesRecords);
            }

            // StationPoints
            if (StationPointsSearch != "StationPoints_ID = '")
            {
                StationPointsSearch = StationPointsSearch.Remove(StationPointsSearch.Length - 24);
                StationPointsAccess StationPointsRecords = new StationPointsAccess(m_theWorkspace);
                StationPointsRecords.AddStationPoints(StationPointsSearch);
                dataAccessClasses.Add("StationPoints", StationPointsRecords);
            }

            // SamplePoints
            if (SamplePointsSearch != "SamplePoints_ID = '")
            {
                SamplePointsSearch = SamplePointsSearch.Remove(SamplePointsSearch.Length - 23);
                SamplePointsAccess SamplePointsRecords = new SamplePointsAccess(m_theWorkspace);
                SamplePointsRecords.AddSamplePoints(SamplePointsSearch);
                dataAccessClasses.Add("SamplePoints", SamplePointsRecords);
            }

            // OrientationDataPoints
            if (OrientationDataPointsSearch != "OrientationDataPoints_ID = '")
            {
                OrientationDataPointsSearch = OrientationDataPointsSearch.Remove(OrientationDataPointsSearch.Length - 32);
                OrientationDataPointsAccess OrientationDataPointsRecords = new OrientationDataPointsAccess(m_theWorkspace);
                OrientationDataPointsRecords.AddOrientationDataPoints(OrientationDataPointsSearch);
                dataAccessClasses.Add("OrientationDataPoints", OrientationDataPointsRecords);
            }

            #endregion

            #endregion

            #region Selected TABLE ROWS
            // Loop through the tables in the map
            IStandaloneTableCollection tableCollection = ArcMap.Document.FocusMap as IStandaloneTableCollection;
            for (int i = 0; i <= tableCollection.StandaloneTableCount - 1; i++)
            {
                // Get one of the tables
                IStandaloneTable thisTable = tableCollection.StandaloneTable[i];
                string tableName = (thisTable.Table as IDataset).Name;

                // Parse the table name in order to strip out unneccessary bits of SDE tables
                ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace;
                string parsedDbName, parsedOwnerName, parsedTableName;
                nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName);

                // Find the selection
                ITableSelection selectedRows = thisTable as ITableSelection;
                ISelectionSet theSelection = selectedRows.SelectionSet;

                // Iterate if there are no selected rows
                if (theSelection.Count == 0) { continue; }

                // Loop through selected rows, build the where clauses up.
                ICursor theCursor;
                theSelection.Search(null, false, out theCursor);

                IRow theRow = theCursor.NextRow();
                while (theRow != null)
                {
                    switch (parsedTableName)
                    {
                        case "Glossary":
                            GlossarySearch += theRow.get_Value(thisTable.Table.FindField("Glossary_ID")) + "' OR Glossary_ID = '";
                            break;
                        case "Notes":
                            NotesSearch += theRow.get_Value(thisTable.Table.FindField("Notes_ID")) + "' OR Notes_ID = '";
                            break;
                        case "RelatedDocuments":
                            RelatedDocumentsSearch += theRow.get_Value(thisTable.Table.FindField("RelatedDocuments_ID")) + "' OR RelatedDocuments_ID = '";
                            break;
                        case "DataSources":
                            DataSourcesSearch += theRow.get_Value(thisTable.Table.FindField("DataSources_ID")) + "' OR DataSources_ID = '";
                            break;
                        case "DescriptionOfMapUnits":
                            DescriptionOfMapUnitsSearch += theRow.get_Value(thisTable.Table.FindField("DescriptionOfMapUnits_ID")) + "' OR DescriptionOfMapUnits_ID = '";
                            break;
                    }

                    // Iterate
                    theRow = theCursor.NextRow();
                }
            }

            #region Build Dictionary
            // Clean up the Where Clauses, create the data access classes, and then add it to the dictionary

            // Glossary
            if (GlossarySearch != "Glossary_ID = '")
            {
                GlossarySearch = GlossarySearch.Remove(GlossarySearch.Length - 19);
                GlossaryAccess GlossaryRecords = new GlossaryAccess(m_theWorkspace);
                GlossaryRecords.AddGlossary(GlossarySearch);
                dataAccessClasses.Add("Glossary", GlossaryRecords);
            }

            // Notes
            if (NotesSearch != "Notes_ID = '")
            {
                NotesSearch = NotesSearch.Remove(NotesSearch.Length - 16);
                NotesAccess NotesRecords = new NotesAccess(m_theWorkspace);
                NotesRecords.AddNotes(NotesSearch);
                dataAccessClasses.Add("Notes", NotesRecords);
            }

            // RelatedDocuments
            if (RelatedDocumentsSearch != "RelatedDocuments_ID = '")
            {
                RelatedDocumentsSearch = RelatedDocumentsSearch.Remove(RelatedDocumentsSearch.Length - 27);
                RelatedDocumentsAccess RelatedDocumentsRecords = new RelatedDocumentsAccess(m_theWorkspace);
                RelatedDocumentsRecords.AddRelatedDocuments(RelatedDocumentsSearch);
                dataAccessClasses.Add("RelatedDocuments", RelatedDocumentsRecords);
            }

            // DataSources
            if (DataSourcesSearch != "DataSources_ID = '")
            {
                DataSourcesSearch = DataSourcesSearch.Remove(DataSourcesSearch.Length - 22);
                DataSourcesAccess DataSourcesRecords = new DataSourcesAccess(m_theWorkspace);
                DataSourcesRecords.AddDataSources(DataSourcesSearch);
                dataAccessClasses.Add("DataSources", DataSourcesRecords);
            }

            // DescriptionOfMapUnits
            if (DescriptionOfMapUnitsSearch != "DescriptionOfMapUnits_ID = '")
            {
                DescriptionOfMapUnitsSearch = DescriptionOfMapUnitsSearch.Remove(DescriptionOfMapUnitsSearch.Length - 32);
                DescriptionOfMapUnitsAccess DescriptionOfMapUnitsRecords = new DescriptionOfMapUnitsAccess(m_theWorkspace);
                DescriptionOfMapUnitsRecords.AddDescriptionOfMapUnits(DescriptionOfMapUnitsSearch);
                dataAccessClasses.Add("DescriptionOfMapUnits", DescriptionOfMapUnitsRecords);
            }

            #endregion

            #endregion

            // Okay! Return the dictionary that has been built
            return dataAccessClasses;
        }