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

📄 formbrowsedata.cs

📁 请认真阅读您的文件包然后写出其具体功能(至少要20个字)。尽量不要让站长把时间都花费在为您修正说明上。压缩包解压
💻 CS
📖 第 1 页 / 共 2 页
字号:
/*
 Copyright 1995-2005 ESRI

 All rights reserved under the copyright laws of the United States.

 You may freely redistribute and use this sample code, with or without modification.

 Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 
 WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR 
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY 
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY 
 WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 SUCH DAMAGE.

 For additional information contact: Environmental Systems Research Institute, Inc.

 Attn: Contracts Dept.

 380 New York Street

 Redlands, California, U.S.A. 92373 

 Email: contracts@esri.com
*/
// Microsoft Assemblies
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

// ESRI Assemblies
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace BrowseData
{
	/// <summary>
	/// Form to display FeatureDatasets and FeatureClasses within a valid Workspace.
	/// </summary>
	public class FormBrowseData : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.ListBox listBoxFeatureClasses;
		private System.Windows.Forms.Label labelFeatureClasses;
		private System.Windows.Forms.ListBox listBoxFeatureDatasets;
		private System.Windows.Forms.Label labelFeatureDatasets;
		private System.Windows.Forms.Label labelDescription1;
		private System.Windows.Forms.Label labelDescription2;
		private System.Windows.Forms.Label labelFeatureClassShapeType;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.Label labelCurrentWorkspace;
		private System.Windows.Forms.TextBox textBoxCurrentWorkspace;
		private System.Windows.Forms.MenuItem menuItemOpenWorkspace;
		private System.Windows.Forms.MenuItem menuItemPersonalGeodatabase;
		private System.Windows.Forms.MenuItem menuItemArcInfoCoverage;
		private System.Windows.Forms.MenuItem menuItemESRIShapefile;
		private System.Windows.Forms.MenuItem menuItemExit;
		private System.Windows.Forms.MenuItem menuItemSDEGeodatabase;
		private System.Windows.Forms.MenuItem menuItemCAD;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormBrowseData()
		{
			// Required for Windows Form Designer support
			InitializeComponent();

			// Get ESRI License
			this.InitializeArcObjects();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItemOpenWorkspace = new System.Windows.Forms.MenuItem();
			this.menuItemPersonalGeodatabase = new System.Windows.Forms.MenuItem();
			this.menuItemSDEGeodatabase = new System.Windows.Forms.MenuItem();
			this.menuItemArcInfoCoverage = new System.Windows.Forms.MenuItem();
			this.menuItemESRIShapefile = new System.Windows.Forms.MenuItem();
			this.menuItemCAD = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.menuItemExit = new System.Windows.Forms.MenuItem();
			this.labelCurrentWorkspace = new System.Windows.Forms.Label();
			this.textBoxCurrentWorkspace = new System.Windows.Forms.TextBox();
			this.listBoxFeatureDatasets = new System.Windows.Forms.ListBox();
			this.listBoxFeatureClasses = new System.Windows.Forms.ListBox();
			this.labelFeatureDatasets = new System.Windows.Forms.Label();
			this.labelFeatureClasses = new System.Windows.Forms.Label();
			this.labelDescription1 = new System.Windows.Forms.Label();
			this.labelDescription2 = new System.Windows.Forms.Label();
			this.labelFeatureClassShapeType = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItemOpenWorkspace});
			// 
			// menuItemOpenWorkspace
			// 
			this.menuItemOpenWorkspace.Index = 0;
			this.menuItemOpenWorkspace.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																								  this.menuItemPersonalGeodatabase,
																								  this.menuItemSDEGeodatabase,
																								  this.menuItemArcInfoCoverage,
																								  this.menuItemESRIShapefile,
																								  this.menuItemCAD,
																								  this.menuItem6,
																								  this.menuItemExit});
			this.menuItemOpenWorkspace.Text = "Open Workspace";
			// 
			// menuItemPersonalGeodatabase
			// 
			this.menuItemPersonalGeodatabase.Index = 0;
			this.menuItemPersonalGeodatabase.Text = "Presonal Geodatabase";
			this.menuItemPersonalGeodatabase.Click += new System.EventHandler(this.menuItemPersonalGeodatabase_Click);
			// 
			// menuItemSDEGeodatabase
			// 
			this.menuItemSDEGeodatabase.Index = 1;
			this.menuItemSDEGeodatabase.Text = "SDE Geodatabase";
			this.menuItemSDEGeodatabase.Click += new System.EventHandler(this.menuItemSDEGeodatabase_Click);
			// 
			// menuItemArcInfoCoverage
			// 
			this.menuItemArcInfoCoverage.Index = 2;
			this.menuItemArcInfoCoverage.Text = "ArcInfo Coverage";
			this.menuItemArcInfoCoverage.Click += new System.EventHandler(this.menuItemArcInfoCoverage_Click);
			// 
			// menuItemESRIShapefile
			// 
			this.menuItemESRIShapefile.Index = 3;
			this.menuItemESRIShapefile.Text = "ESRI Shapefile";
			this.menuItemESRIShapefile.Click += new System.EventHandler(this.menuItemESRIShapefile_Click);
			// 
			// menuItemCAD
			// 
			this.menuItemCAD.Index = 4;
			this.menuItemCAD.Text = "CAD";
			this.menuItemCAD.Click += new System.EventHandler(this.menuItemCAD_Click);
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 5;
			this.menuItem6.Text = "-";
			// 
			// menuItemExit
			// 
			this.menuItemExit.Index = 6;
			this.menuItemExit.Text = "Exit";
			this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
			// 
			// labelCurrentWorkspace
			// 
			this.labelCurrentWorkspace.Location = new System.Drawing.Point(14, 13);
			this.labelCurrentWorkspace.Name = "labelCurrentWorkspace";
			this.labelCurrentWorkspace.Size = new System.Drawing.Size(212, 17);
			this.labelCurrentWorkspace.TabIndex = 0;
			this.labelCurrentWorkspace.Text = "Current Workspace:";
			// 
			// textBoxCurrentWorkspace
			// 
			this.textBoxCurrentWorkspace.Location = new System.Drawing.Point(14, 30);
			this.textBoxCurrentWorkspace.Name = "textBoxCurrentWorkspace";
			this.textBoxCurrentWorkspace.ReadOnly = true;
			this.textBoxCurrentWorkspace.Size = new System.Drawing.Size(557, 21);
			this.textBoxCurrentWorkspace.TabIndex = 1;
			this.textBoxCurrentWorkspace.Text = "";
			// 
			// listBoxFeatureDatasets
			// 
			this.listBoxFeatureDatasets.ItemHeight = 12;
			this.listBoxFeatureDatasets.Location = new System.Drawing.Point(16, 92);
			this.listBoxFeatureDatasets.Name = "listBoxFeatureDatasets";
			this.listBoxFeatureDatasets.Size = new System.Drawing.Size(274, 232);
			this.listBoxFeatureDatasets.TabIndex = 2;
			this.listBoxFeatureDatasets.SelectedIndexChanged += new System.EventHandler(this.listBoxFeatureDatasets_SelectedIndexChanged);
			// 
			// listBoxFeatureClasses
			// 
			this.listBoxFeatureClasses.ItemHeight = 12;
			this.listBoxFeatureClasses.Location = new System.Drawing.Point(298, 82);
			this.listBoxFeatureClasses.Name = "listBoxFeatureClasses";
			this.listBoxFeatureClasses.Size = new System.Drawing.Size(273, 232);
			this.listBoxFeatureClasses.TabIndex = 3;
			this.listBoxFeatureClasses.SelectedIndexChanged += new System.EventHandler(this.listBoxFeatureClasses_SelectedIndexChanged);
			// 
			// labelFeatureDatasets
			// 
			this.labelFeatureDatasets.Location = new System.Drawing.Point(14, 65);
			this.labelFeatureDatasets.Name = "labelFeatureDatasets";
			this.labelFeatureDatasets.Size = new System.Drawing.Size(212, 17);
			this.labelFeatureDatasets.TabIndex = 4;
			this.labelFeatureDatasets.Text = "FeatureDatasets";
			// 
			// labelFeatureClasses
			// 
			this.labelFeatureClasses.Location = new System.Drawing.Point(298, 65);
			this.labelFeatureClasses.Name = "labelFeatureClasses";
			this.labelFeatureClasses.Size = new System.Drawing.Size(211, 17);
			this.labelFeatureClasses.TabIndex = 5;
			this.labelFeatureClasses.Text = "FeatureClasses";
			// 
			// labelDescription1
			// 
			this.labelDescription1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.labelDescription1.Location = new System.Drawing.Point(19, 332);
			this.labelDescription1.Name = "labelDescription1";
			this.labelDescription1.Size = new System.Drawing.Size(187, 34);
			this.labelDescription1.TabIndex = 6;
			this.labelDescription1.Text = "Select a Dataset to see its FeatureClasses.";
			// 
			// labelDescription2
			// 
			this.labelDescription2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.labelDescription2.Location = new System.Drawing.Point(302, 327);
			this.labelDescription2.Name = "labelDescription2";
			this.labelDescription2.Size = new System.Drawing.Size(183, 35);
			this.labelDescription2.TabIndex = 7;
			this.labelDescription2.Text = "Select a FeatureClass to see its shape type.";
			// 
			// labelFeatureClassShapeType
			// 
			this.labelFeatureClassShapeType.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.labelFeatureClassShapeType.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.labelFeatureClassShapeType.ForeColor = System.Drawing.Color.Red;
			this.labelFeatureClassShapeType.Location = new System.Drawing.Point(302, 366);
			this.labelFeatureClassShapeType.Name = "labelFeatureClassShapeType";
			this.labelFeatureClassShapeType.Size = new System.Drawing.Size(269, 35);
			this.labelFeatureClassShapeType.TabIndex = 8;
			this.labelFeatureClassShapeType.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// FormBrowseData
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(588, 425);
			this.Controls.Add(this.labelFeatureClassShapeType);
			this.Controls.Add(this.labelDescription2);
			this.Controls.Add(this.labelDescription1);
			this.Controls.Add(this.labelFeatureClasses);
			this.Controls.Add(this.labelFeatureDatasets);
			this.Controls.Add(this.listBoxFeatureClasses);
			this.Controls.Add(this.listBoxFeatureDatasets);
			this.Controls.Add(this.textBoxCurrentWorkspace);
			this.Controls.Add(this.labelCurrentWorkspace);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Menu = this.mainMenu1;
			this.Name = "FormBrowseData";
			this.Text = "Browsing Datasets";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new FormBrowseData());
		}
		
		/// <summary>
		/// Intialize ArcObjects
		/// </summary>
		private void InitializeArcObjects()
		{
			try 
			{
				AoInitialize aoInitialize = new AoInitialize();

				if (aoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
				{
					aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
				}
				else if (aoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable)
				{
					aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
				}
				else if (aoInitialize.IsProductCodeAvailable( esriLicenseProductCode.esriLicenseProductCodeArcEditor) == esriLicenseStatus.esriLicenseAvailable)
				{
					aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
				}
				else if ( aoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcInfo) == esriLicenseStatus.esriLicenseAvailable)
				{
					aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
				}
				else
				{
					throw new Exception("Cannot Initialize ArcObjects License");
				}
			} 
			catch (Exception ex) 
			{
				MessageBox.Show(ex.Message);
			}
		}
		/// <summary>
		/// User Clicks: Open Workspace > Personal Geodatabase
		/// </summary>
		private void menuItemPersonalGeodatabase_Click(object sender, System.EventArgs e)
		{
			// Reset the Form
			this.ClearForm();

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

⌨️ 快捷键说明

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