void cleanUp()
 {
     //m_pWSF = null;
     m_pWS            = null;
     m_pSDT           = null;
     m_pSDS           = null;
     m_pSB            = null;
     m_pB             = null;
     m_SelectedObject = null;
     templateInfo     = null;
     m_pSDI           = null;
     formNames        = null;
     formReduce       = null;
     m_sfn            = "";
     blnCancel        = false;
     strLayers        = "";
     strNodeLayers    = "";
 }
		void cleanUp()
		{
			//m_pWSF = null;
			m_pWS = null;
			m_pSDT = null;
			m_pSDS = null;
			m_pSB = null;
			m_pB = null;
			m_SelectedObject = null;
			templateInfo = null;
			m_pSDI = null;
			formNames = null;
			formReduce = null;
			m_sfn = "";
			blnCancel = false;
			strLayers = "";
			strNodeLayers = "";
		}
		private string CreateSchLayers(IEnumLayer pLayers)
		{
			if (pLayers == null) return "";
			ILayer pLayer = pLayers.Next();
			IFeatureLayer featureLayer;
			IFeatureClass featureClass;
			string pStrLayerNames = "";
			IDataset pDataset;
			System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
			System.Windows.Forms.Cursor.Show();

			m_pSDS.DesignMode = true;
			m_pSDI = (ESRI.ArcGIS.Schematic.ISchematicDatasetImport)m_pSDS;

			Dictionary<string, IFeatureClass> myDictionary = new Dictionary<string, IFeatureClass>();
			IGeometricNetwork gn = null;
			do
			{
				featureLayer = (IFeatureLayer)pLayer;
				featureClass = featureLayer.FeatureClass;
				pDataset = (IDataset)featureClass;

				if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTSimpleEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
				{

					//The FeatureType property of feature classes that implement this interface will be esriFTSimpleJunction, esriDTSimpleEdge, esriFTComplexJunction, or esriFTComplexEdge.
					INetworkClass networkClass = (INetworkClass)featureLayer.FeatureClass;

					if (networkClass.GeometricNetwork != null)
					{
						//we have a network class
						if ((gn == null) || (gn != networkClass.GeometricNetwork))
						{
							//need to process all the classes
							Dictionary<string, IFeatureClass> localDictionary = new Dictionary<string, IFeatureClass>();
							gn = networkClass.GeometricNetwork;
							IEnumFeatureClass fcComplexEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
							IEnumFeatureClass fcComplexNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction);
							IEnumFeatureClass fcSimpleEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
							IEnumFeatureClass fcSimpleNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
							localDictionary = ProcessFCs(fcComplexEdge, fcComplexNode, fcSimpleEdge, fcSimpleNode);
							if (myDictionary.Count == 0)  //just copy it
							{
								myDictionary = localDictionary;
							}
							else //merge
							{
								Dictionary<string, IFeatureClass>.KeyCollection keyColl = localDictionary.Keys;

								foreach (string s in keyColl)
								{
									IFeatureClass fc;
									bool bln = localDictionary.TryGetValue(s, out fc);
									myDictionary.Add(s, fc);
								}
							}
						}
						//Build up the string that will go to the select items to reduce form
						pStrLayerNames += pDataset.Name.ToString();
						pStrLayerNames += ";";

						//Build up the string for just the node feature classes
						if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
						{
							strNodeLayers += pDataset.Name.ToString();
							strNodeLayers += ";";
						}

						//create the fields collections to be used by the frmAdvanced form
						IFields pFields = featureClass.Fields;
						if (pFields.FieldCount > 0)
						{
							for (int i = 0; i < pFields.FieldCount; i++)
							{
								//don't mess with objectid or shape or GlobalID
								if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != featureClass.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != featureClass.ShapeFieldName.ToString()))
								{
									m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString());
								}
							}
						}

						//remove the layer from the list of dictionary classes
						if (myDictionary.ContainsKey(featureClass.AliasName))
						{
							myDictionary.Remove(featureClass.AliasName);
						}

						m_pSDI.ImportFeatureLayer(featureLayer, m_pSDT, true, true, true);
					}
				}
				pLayer = pLayers.Next();
			} while (pLayer != null);

			//handle any feature classes that were not in the map
			if (myDictionary.Count > 0)
			{
				Dictionary<string, IFeatureClass>.KeyCollection keyColl = myDictionary.Keys;
				foreach (string s in keyColl)
				{
					IFeatureClass fc;
					bool bln = myDictionary.TryGetValue(s, out fc);
					IObjectClass o = (IObjectClass)fc;
					pDataset = (IDataset)fc;

					pStrLayerNames += pDataset.Name.ToString();
					pStrLayerNames += ";";

					//Build up the string for just the node feature classes
					if (fc.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
					{
						strNodeLayers += pDataset.Name.ToString();
						strNodeLayers += ";";
					}

					//create the fields collections to be used by the frmAdvanced form
					IFields pFields = fc.Fields;
					if (pFields.FieldCount > 0)
					{
						for (int i = 0; i < pFields.FieldCount; i++)
						{
							//don't mess with objectid or shape or GlobalID
							if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != fc.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != fc.ShapeFieldName.ToString()))
							{
								m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString());
							}
						}
					}
					if ((fc.FeatureType == esriFeatureType.esriFTComplexJunction) || (fc.FeatureType == esriFeatureType.esriFTSimpleJunction))
					{
						//node
						m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicNodeType);
					}
					else
					{
						//link
						m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicLinkType);
					}
				}
			}

			m_pSDS.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, true);
			m_pSDS.DesignMode = false;
			return pStrLayerNames;
		}
        private string CreateSchLayers(IEnumLayer pLayers)
        {
            if (pLayers == null)
            {
                return("");
            }
            ILayer        pLayer = pLayers.Next();
            IFeatureLayer featureLayer;
            IFeatureClass featureClass;
            string        pStrLayerNames = "";
            IDataset      pDataset;

            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
            System.Windows.Forms.Cursor.Show();

            m_pSDS.DesignMode = true;
            m_pSDI            = (ESRI.ArcGIS.Schematic.ISchematicDatasetImport)m_pSDS;

            Dictionary <string, IFeatureClass> myDictionary = new Dictionary <string, IFeatureClass>();
            IGeometricNetwork gn = null;

            do
            {
                featureLayer = (IFeatureLayer)pLayer;
                featureClass = featureLayer.FeatureClass;
                pDataset     = (IDataset)featureClass;

                if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTSimpleEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
                {
                    //The FeatureType property of feature classes that implement this interface will be esriFTSimpleJunction, esriDTSimpleEdge, esriFTComplexJunction, or esriFTComplexEdge.
                    INetworkClass networkClass = (INetworkClass)featureLayer.FeatureClass;

                    if (networkClass.GeometricNetwork != null)
                    {
                        //we have a network class
                        if ((gn == null) || (gn != networkClass.GeometricNetwork))
                        {
                            //need to process all the classes
                            Dictionary <string, IFeatureClass> localDictionary = new Dictionary <string, IFeatureClass>();
                            gn = networkClass.GeometricNetwork;
                            IEnumFeatureClass fcComplexEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
                            IEnumFeatureClass fcComplexNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction);
                            IEnumFeatureClass fcSimpleEdge  = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
                            IEnumFeatureClass fcSimpleNode  = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
                            localDictionary = ProcessFCs(fcComplexEdge, fcComplexNode, fcSimpleEdge, fcSimpleNode);
                            if (myDictionary.Count == 0)                              //just copy it
                            {
                                myDictionary = localDictionary;
                            }
                            else                             //merge
                            {
                                Dictionary <string, IFeatureClass> .KeyCollection keyColl = localDictionary.Keys;

                                foreach (string s in keyColl)
                                {
                                    IFeatureClass fc;
                                    bool          bln = localDictionary.TryGetValue(s, out fc);
                                    myDictionary.Add(s, fc);
                                }
                            }
                        }
                        //Build up the string that will go to the select items to reduce form
                        pStrLayerNames += pDataset.Name.ToString();
                        pStrLayerNames += ";";

                        //Build up the string for just the node feature classes
                        if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
                        {
                            strNodeLayers += pDataset.Name.ToString();
                            strNodeLayers += ";";
                        }

                        //create the fields collections to be used by the frmAdvanced form
                        IFields pFields = featureClass.Fields;
                        if (pFields.FieldCount > 0)
                        {
                            for (int i = 0; i < pFields.FieldCount; i++)
                            {
                                //don't mess with objectid or shape or GlobalID
                                if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != featureClass.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != featureClass.ShapeFieldName.ToString()))
                                {
                                    m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString());
                                }
                            }
                        }

                        //remove the layer from the list of dictionary classes
                        if (myDictionary.ContainsKey(featureClass.AliasName))
                        {
                            myDictionary.Remove(featureClass.AliasName);
                        }

                        m_pSDI.ImportFeatureLayer(featureLayer, m_pSDT, true, true, true);
                    }
                }
                pLayer = pLayers.Next();
            } while (pLayer != null);

            //handle any feature classes that were not in the map
            if (myDictionary.Count > 0)
            {
                Dictionary <string, IFeatureClass> .KeyCollection keyColl = myDictionary.Keys;
                foreach (string s in keyColl)
                {
                    IFeatureClass fc;
                    bool          bln = myDictionary.TryGetValue(s, out fc);
                    IObjectClass  o   = (IObjectClass)fc;
                    pDataset = (IDataset)fc;

                    pStrLayerNames += pDataset.Name.ToString();
                    pStrLayerNames += ";";

                    //Build up the string for just the node feature classes
                    if (fc.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
                    {
                        strNodeLayers += pDataset.Name.ToString();
                        strNodeLayers += ";";
                    }

                    //create the fields collections to be used by the frmAdvanced form
                    IFields pFields = fc.Fields;
                    if (pFields.FieldCount > 0)
                    {
                        for (int i = 0; i < pFields.FieldCount; i++)
                        {
                            //don't mess with objectid or shape or GlobalID
                            if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != fc.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != fc.ShapeFieldName.ToString()))
                            {
                                m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString());
                            }
                        }
                    }
                    if ((fc.FeatureType == esriFeatureType.esriFTComplexJunction) || (fc.FeatureType == esriFeatureType.esriFTSimpleJunction))
                    {
                        //node
                        m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicNodeType);
                    }
                    else
                    {
                        //link
                        m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicLinkType);
                    }
                }
            }

            m_pSDS.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, true);
            m_pSDS.DesignMode = false;
            return(pStrLayerNames);
        }