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;
}