NAEngine.frmLoadLocations.ShowModal C# (CSharp) Method

ShowModal() public method

public ShowModal ( IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv ) : bool
mapControl IMapControl3
naEnv IEngineNetworkAnalystEnvironment
return bool
		public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
		{
			// Initialize variables
			m_okClicked = false;
			m_listDisplayTable = new System.Collections.ArrayList();

			var activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2;
			if (activeCategory == null)
				return false;

			IDataLayer dataLayer = activeCategory.DataLayer;
			if (dataLayer == null)
				return false;

			// Set up the title of this dialog
			String dataLayerName = GetDataLayerName(dataLayer);
			if (dataLayerName.Length == 0)
				return false;

			this.Text = "Load Items into " + dataLayerName;

			// Make sure the combo box lists only the appropriate possible input data layers
			PopulateInputDataComboBox(mapControl, dataLayer);

			//Select the first display table from the list
			if (cboInputData.Items.Count > 0)
				cboInputData.SelectedIndex = 0;

			// Show the window
			this.ShowDialog();

			// If we selected a layer and clicked OK, load the locations
			if (m_okClicked && (cboInputData.SelectedIndex >= 0))
			{
				try
				{
					// Get a cursor on the source display table (either though the selection set or table)
					// Use IDisplayTable because it accounts for joins, querydefs, etc.
					// IDisplayTable is implemented by FeatureLayers and StandaloneTables.
					//
					IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable;
					ICursor cursor;
					if (chkUseSelection.Checked)
					{
						ISelectionSet selSet;
						selSet = displayTable.DisplaySelectionSet;
						selSet.Search(null, false, out cursor);
					}
					else
						cursor = displayTable.SearchDisplayTable(null, false);

					// Get the NAContext from the active analysis layer
					INAContext naContext = naEnv.NAWindow.ActiveAnalysis.Context;

					// Get the dataset for the active NAClass  
					IDataset naDataset = activeCategory.NAClass as IDataset;

					// Setup NAClassLoader and Load Locations
					INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
					naClassLoader.Initialize(naContext, naDataset.Name, cursor);

					// Avoid loading network locations onto non-traversable portions of elements
					INALocator3 locator = naContext.Locator as INALocator3;
					locator.ExcludeRestrictedElements = true;
					locator.CacheRestrictedElements(naContext);

					int rowsIn = 0;
					int rowsLocated = 0;
					naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

					// Let the user know if some of the rows failed to locate
					if (rowsIn != rowsLocated)
						MessageBox.Show("Out of " + rowsIn + " + rows, " + rowsLocated + " rows were located", 
										"Loading locations", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
				catch (Exception e)
				{
					MessageBox.Show(e.Message, "Loading locations failure", MessageBoxButtons.OK, MessageBoxIcon.Error );					
				}

				return true;
			}

			return false;
		}

Usage Example

示例#1
0
        public override void OnClick()
        {
            // Get the NALayer and corresponding NAContext of the layer that
            // was right-clicked on in the table of contents
            // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown
            INALayer naLayer = (INALayer)m_mapControl.CustomProperty;

            // Set the Active Analysis layer to be the layer right-clicked on
            m_naEnv.NAWindow.ActiveAnalysis = naLayer;

            if (!Enabled)
            {
                return;
            }

            // Show the Property Page form for Network Analyst
            frmLoadLocations loadLocations = new frmLoadLocations();

            if (loadLocations.ShowModal(m_mapControl, m_naEnv))
            {
                // If loaded locations, refresh the NAWindow and the Screen
                m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent);
                m_naEnv.NAWindow.UpdateContent(m_naEnv.NAWindow.ActiveCategory);
            }
        }
All Usage Examples Of NAEngine.frmLoadLocations::ShowModal