⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formbrowsedata.cs

📁 请认真阅读您的文件包然后写出其具体功能(至少要20个字)。尽量不要让站长把时间都花费在为您修正说明上。压缩包解压
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// Update Form with Workspace Information
			this.AssignWorkspace(workspace);
		}
		
		/// <summary>
		/// User Clicks: Open Workspace > SDE Geodatabase
		/// </summary>
		private void menuItemSDEGeodatabase_Click(object sender, System.EventArgs e)
		{
			// Reset the Form
			this.ClearForm();

			// Browse to Workspace File
			IWorkspace workspace = this.BrowseWorkspaceFile(
				new SdeWorkspaceFactoryClass(),
				"Please Select an ArcSDE Geodatabase", 
				"ArcSDE Connection File (*.sde)|*.sde");
			if (workspace == null)
			{
				MessageBox.Show("Cannot create a ArcSDE Workspace Factory");
				return;
			}

			// Update Form with Workspace Information
			this.AssignWorkspace(workspace);
		}

		/// <summary>
		/// User Clicks: Open Workspace > ArcInfo Coverage
		/// </summary>
		private void menuItemArcInfoCoverage_Click(object sender, System.EventArgs e)
		{
			// Reset the Form
			this.ClearForm();

			// Browse to Workspace Folder
			IWorkspace workspace = this.BrowseWorkspaceFolder(
				new ArcInfoWorkspaceFactoryClass(), 
				"Please Select an ArcInfo Coverage Workspace");
			if (workspace == null)
			{
				MessageBox.Show("Cannot create an ArcInfo Converage Workspace Factory");
				return;
			}

			// Update Form with Workspace Information
			this.AssignWorkspace(workspace);
		}
		
		/// <summary>
		/// User Clicks: Open Workspace > ESRI Shapefile
		/// </summary>
		private void menuItemESRIShapefile_Click(object sender, System.EventArgs e)
		{
			// Reset the Form
			this.ClearForm();

			// Browse to Workspace Folder
			IWorkspace workspace = this.BrowseWorkspaceFolder(
				new ShapefileWorkspaceFactoryClass(),
				"Please Select a ShapeFile Workspace");
			if (workspace == null)
			{
				MessageBox.Show("Cannot create a ShapeFile Workspace Factory");
				return;
			}

			// Update Form with Workspace Information
			this.AssignWorkspace(workspace);
		}
		
		/// <summary>
		/// User Clicks: Open Workspace > CAD
		/// </summary>
		private void menuItemCAD_Click(object sender, System.EventArgs e)
		{
			// Reset the Form
			this.ClearForm();

			// Browse to Workspace Folder
			IWorkspace workspace = this.BrowseWorkspaceFolder(
				new CadWorkspaceFactoryClass(),
				"Please Select a CAD Workspace");
			if (workspace == null)
			{
				MessageBox.Show("Cannot create a CAD Workspace Factory");
				return;
			}

			// Update Form with Workspace Information
			this.AssignWorkspace(workspace);
		}

		private void menuItemExit_Click(object sender, System.EventArgs e)
		{
			// Close the Form.
			this.Close();
		}
		
		private void ClearForm()
		{
			// Clear ListBox Item Collections
			this.listBoxFeatureDatasets.Items.Clear();
			this.listBoxFeatureClasses.Items.Clear();

			// Clear Tag
			this.textBoxCurrentWorkspace.Tag = null;
			this.listBoxFeatureDatasets.Tag  = null;
			this.listBoxFeatureClasses.Tag   = null;

			// Clear Geometry Type Label
			this.labelFeatureClassShapeType.Text = "";
		}
		
		private IWorkspace BrowseWorkspaceFile(IWorkspaceFactory workspaceFactory, string title, string extension)
		{
			// Display .Net dialog for user to select a File.
			OpenFileDialog openFileDialog = new OpenFileDialog();
			
			// Set File Filter
			openFileDialog.Filter = extension;
			
			// Disable multi-select
			openFileDialog.Multiselect = false;

			// Show Help
			openFileDialog.ShowHelp = true;

			// Set Dialog Title
			openFileDialog.Title = title;
			
			// Display Open File Dialog
			if(openFileDialog.ShowDialog() != DialogResult.OK)
			{
				return null;
			}

			// Get Selected Path
			string stringFileName = openFileDialog.FileName;

			// Trap invalid WorkspaceFactories
			try
			{
				return workspaceFactory.OpenFromFile(stringFileName, 0);
			}
			catch
			{
				return null;
			}

		}

		private IWorkspace BrowseWorkspaceFolder(IWorkspaceFactory workspaceFactory, string title)
		{
			// Display .Net dialog for user to select a Folder.
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

			// Set the help text description for the FolderBrowserDialog.
			folderBrowserDialog.Description = title;

			// Do not allow the user to create new files via the FolderBrowserDialog.
			folderBrowserDialog.ShowNewFolderButton = false;

			// Default to the My Documents folder.
			folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
				
			// Show the FolderBrowserDialog.
			if (folderBrowserDialog.ShowDialog() != DialogResult.OK )
			{
				return null;
			}
			
			// Get Selected Path
			string stringFolderName = folderBrowserDialog.SelectedPath;

			// Trap invalid WorkspaceFactories
			try
			{
				return workspaceFactory.OpenFromFile(stringFolderName, 0);
			}
			catch
			{
				return null;
			}
		}
		
		private void AssignWorkspace(IWorkspace workspace)
		{
			// Add Workspace path to the Form.
			this.textBoxCurrentWorkspace.Text = workspace.PathName;

			// Store Workspace against TextBox tag.
			this.textBoxCurrentWorkspace.Tag = (object) workspace;
		
			// Seed FeatureDataset ListBox with a entry for "standalone" FeatureClasses.
			this.listBoxFeatureDatasets.Items.Add("< Standalong FeatureClasses >");
			
			// Get an enumeration of FeatureDatasets
			IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
			if (enumDatasetName == null)
			{
				return;
			}

			// Create an Array of DatasetNames
			IArray array = new ArrayClass();
		
			// Loop through FeatureDatasets
			IDatasetName datasetName = enumDatasetName.Next();
			while (datasetName != null)
			{
				// Add the name of the FeatureDataset to the ListBox
				this.listBoxFeatureDatasets.Items.Add(datasetName.Name);

				// Store a copy of the FeatureDataset in an ESRI Array.
				array.Add(datasetName);
				
				// Get the next FeatureDataset
				datasetName = enumDatasetName.Next();
			}

			// Store DatasetName enumeration against FeatureDataset ListBox
			this.listBoxFeatureDatasets.Tag = (object) array;

			// Select First Entry in FeatureDataset ListBox
			this.listBoxFeatureDatasets.Text = this.listBoxFeatureDatasets.Items[0].ToString();
		}

		private void listBoxFeatureDatasets_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				// Clear FeatureClass ListBox
				this.listBoxFeatureClasses.Items.Clear();

				// Clear FeatureClass Tag
				this.listBoxFeatureClasses.Tag = null;

				// Clear Geometry Type Label
				this.labelFeatureClassShapeType.Text = "";

				// Exit if Nothing Selected in FeatureClass ListBox
				if (this.listBoxFeatureDatasets.SelectedIndex < 0)
				{
					return;
				}

				// Create an array to store the FeatureClassNames
				IArray arrayFC = new ArrayClass();
			
				// List all Standalong FeatureClasses
				if (this.listBoxFeatureDatasets.SelectedIndex == 0)
				{
					// Get Workspace from TextBox Tag.
					IWorkspace workspace = (IWorkspace) this.textBoxCurrentWorkspace.Tag;

					// Get an enumeration of FeatureClasses
					IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
					if (enumDatasetName == null)
					{
						return;
					}

					// Loop Through Datasets
					IDatasetName datasetName = enumDatasetName.Next();
					while (datasetName != null)
					{
						this.listBoxFeatureClasses.Items.Add(datasetName.Name);
						arrayFC.Add(datasetName);
						datasetName = enumDatasetName.Next();
					}					
				}

				// List all FeatureClasses withint the selected FeatureDataset
				if (this.listBoxFeatureDatasets.SelectedIndex > 0)
				{
					// Retrieve array of DatasetNames from the Tag.
					IArray array = (IArray) this.listBoxFeatureDatasets.Tag;

					// Get the selected DatasetName
					IDatasetName datasetName = (IDatasetName) array.get_Element(this.listBoxFeatureDatasets.SelectedIndex - 1);

					// QI to IFeatureDatasetName
					IFeatureDatasetName featureDatasetName = (IFeatureDatasetName) datasetName;

					// Get an enumeration of child FeatureClassNames
					IEnumDatasetName enumDatasetNameFC = featureDatasetName.FeatureClassNames;

					// Loop through each of the child FeatureDatasetNames
					IDatasetName datasetNameFC = enumDatasetNameFC.Next();
					while (datasetNameFC != null)
					{
						// Add the name of the FeatureClassName to the ListBox
						this.listBoxFeatureClasses.Items.Add(datasetNameFC.Name);

						// Store the FeatureClassName in the ESRI array.
						arrayFC.Add(datasetNameFC);

						// Get next FeatureDatasetName
						datasetNameFC = enumDatasetNameFC.Next();
					}
				}

				// Store enumeration of FeatureClasssNames in ListBox Tag
				this.listBoxFeatureClasses.Tag = arrayFC;

				// Select First FeatureClass
				if (this.listBoxFeatureClasses.Items.Count > 0)
				{
					this.listBoxFeatureClasses.Text = this.listBoxFeatureClasses.Items[0].ToString();
				}
			}
			catch (Exception ex) 
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void listBoxFeatureClasses_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				// Exit if nothing selected.
				if (this.listBoxFeatureClasses.SelectedIndex < 0)
				{
					return;
				}
			
				// Retrieve array of FeatureClassNames
				IArray array = (IArray) this.listBoxFeatureClasses.Tag;

				// Get the selected FeatureClassName
				IDatasetName datasetName = (IDatasetName) array.get_Element(this.listBoxFeatureClasses.SelectedIndex);

				// QI from DatasetName to FeatureClassName
				IFeatureClassName featureClassName = (IFeatureClassName) datasetName;

				// Display "shape type" in Form.
				this.labelFeatureClassShapeType.Text = featureClassName.ShapeType.ToString();
			}
			catch (Exception ex) 
			{
				MessageBox.Show(ex.Message);
			}
		}		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -