www.pudn.com > C sharp和MapObjects实现.rar > frmContent.cs


using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
 
namespace MainSystem 
{ 
	///  
	/// Summary description for frmContent. 
	///  
	public class frmContent : System.Windows.Forms.Form 
	{ 
		CEnvironment	_env = null; 
		string			_szName; 
 
		private System.Windows.Forms.ListBox _listBox; 
		///  
		/// Required designer variable. 
		///  
		private System.ComponentModel.Container components = null; 
 
		public frmContent(CEnvironment env) 
		{ 
			_env = env; 
			InitializeComponent(); 
		} 
 
		///  
		/// Clean up any resources being used. 
		///  
		protected override void Dispose( bool disposing ) 
		{ 
			if( disposing ) 
			{ 
				if(components != null) 
				{ 
					components.Dispose(); 
				} 
			} 
			base.Dispose( disposing ); 
		} 
 
		#region Windows Form Designer generated code 
		///  
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor. 
		///  
		private void InitializeComponent() 
		{ 
			this._listBox = new System.Windows.Forms.ListBox(); 
			this.SuspendLayout(); 
			//  
			// _listBox 
			//  
			this._listBox.Dock = System.Windows.Forms.DockStyle.Fill; 
			this._listBox.ItemHeight = 12; 
			this._listBox.Name = "_listBox"; 
			this._listBox.Size = new System.Drawing.Size(216, 208); 
			this._listBox.TabIndex = 1; 
			//  
			// frmContent 
			//  
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 
			this.ClientSize = new System.Drawing.Size(216, 213); 
			this.Controls.AddRange(new System.Windows.Forms.Control[] { 
																		  this._listBox}); 
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 
			this.MaximizeBox = false; 
			this.MinimizeBox = false; 
			this.Name = "frmContent"; 
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 
			this.Text = "详细信息"; 
			this.Load += new System.EventHandler(this.frmContent_Load); 
			this.ResumeLayout(false); 
 
		} 
		#endregion 
 
		private void frmContent_Load(object sender, System.EventArgs e) 
		{ 
			if ("" == _szName) 
				return; 
 
			string szTableName = _env.GetTableName(_szName,"地名索引"); 
			if ("" == szTableName) 
			{ 
				MessageBox.Show("属性库中无此地名!","中国地名指南",MessageBoxButtons.OK,MessageBoxIcon.Error );  
				return; 
			} 
			_listBox.Items.Clear(); 
   
			string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _env.m_szDBName +  
				";Persist Security Info=False";		 
			System.Data.OleDb.OleDbConnection  myConnection = new System.Data.OleDb.OleDbConnection(strConnectionString);    
			myConnection.Open(); 
			System.Data.DataSet dataSet = new System.Data.DataSet("临时库"); 
			System.Data.OleDb.OleDbDataAdapter myDataAdapter; 
 
			string szSQL; 
			string szFieldName;			 
			szFieldName = this._env.GetFieldName(_szName); 
   
			if (szFieldName == "") 
				szFieldName = "单位名称"; 
 
			szSQL = "Select * From [" + szTableName + "] Where "+ szFieldName+" ='"+_szName+"'"; 
 
			myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection); 
				 
			try 
			{ 
				myDataAdapter.Fill(dataSet,"地名"); 
			} 
			finally 
			{ 
			} 
 
			System.Data.DataTable indexTbl = dataSet.Tables["地名"]; 
		 
			System.Data.DataRow[] rowsType = indexTbl.Select(); 
 
			if (0 == rowsType.Length) 
				return ; 
 
			for (int i = 0; i < indexTbl.Columns.Count; i ++) 
			{	 
				string szValue = indexTbl.Columns[i].ColumnName + ":" + rowsType[0][i].ToString();  
				_listBox.Items.Add(szValue);  
			} 
		} 
 
 
		public void SetName(string szName) 
		{ 
			_szName = szName; 
		} 
 
	} 
}