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

📄 sharpqueryschemaclass.cs

📁 c#源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
// created on 04/11/2003 at 18:15

using System;
using System.Windows.Forms;
using System.Collections;
using System.Data;
using System.Data.OleDb;

using SharpQuery.Collections;
using System.Reflection;
using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Services;

using SharpQuery.Connection;

namespace SharpQuery.SchemaClass
{	
	
//
// Childs
//
			
	///<summary>
	/// Column class
	///</summary>	
	public class SharpQueryColumn : AbstractSharpQuerySchemaClass
	{			
		public override string NormalizedName 
		{
			get {
				string normalizedName = "";
								
				if ( (this.OwnerName != "") && (this.OwnerName != null) ){
					normalizedName +=  this.OwnerName +  ".";
				} 				
				
				normalizedName +=  this.Name;
				
				return normalizedName;
			}
		}
		
		protected override void CreateEntitiesList()
		{		
		}
		
		public SharpQueryColumn( IConnection connection, string catalogName, string schemaName, string ownerName, string name  ) : base(connection, catalogName, schemaName, ownerName, name )
		{			
		}
		
		protected override void OnRefresh()		
		{
			//nothing !
		}		

		///<summary>
		/// For a Table or a View extract data.
		/// For a stocked procedure, execute it :o).
		/// <param name="rows">Number of row to extract. if "0", extract all rows.</param>
		/// <returns><see cref="System.Data.DataTable">DataTable</see> 
		/// or a <see cref="System.Data.DataSet">DataSet</see> </returns>
		/// </summary>
		public override object Execute( int rows, SharpQuerySchemaClassCollection parameters )
		{
			//nothing
			return null;
		}	
		
		///<summary> return a <see cref="System.Windows.Forms.DataObject">DataObject</see> 
		///</summary>		
		public override DataObject DragObject
		{
			get
			{
				DataObject returnValue = new DataObject();			
				string extract = this.NormalizedName;
				returnValue.SetData(typeof(string) , extract );
				return returnValue;
			}
		}			
	}
	
	///<summary>
	/// Procedurre's parameters class
	///</summary>	
	public class SharpQueryParameter : AbstractSharpQuerySchemaClass
	{				
		private DbType _dataType;
		private object _value = null;
		private ParameterDirection _type;
		
		///<summary>
		/// Data Type of the parameter
		/// ( used only while extracting data or executing procedure )
		///</summary>
		public DbType DataType
		{
			get
			{
				return this._dataType;
			}
			set
			{
				this._dataType = value;
				switch( value )
				{
					//string type
					case DbType.AnsiString				: 
					case DbType.AnsiStringFixedLength	: 
					case DbType.String					: 
					case DbType.StringFixedLength		: this._value = new string( (char[])null ); break;
					//array type
					case DbType.Binary					: this._value = new byte[8000]; break;
					//bool type
					case DbType.Boolean					: this._value = new bool(); break;
					//interger type
					case DbType.SByte					: this._value = new sbyte(); break;
					case DbType.Byte					: this._value = new byte(); break;					 
					case DbType.Int16					: this._value = new short(); break;
					case DbType.Int32					: this._value = new int(); break;
					case DbType.Int64					: this._value = new long(); break;
					case DbType.UInt16					: this._value = new ushort(); break;
					case DbType.UInt32					: this._value = new uint(); break;
					case DbType.UInt64					: this._value = new long(); break;					
					//Date type
					case DbType.Date					: 
					case DbType.DateTime				:
					case DbType.Time					: this._value = new DateTime(); break;
					//float type
					case DbType.Decimal					: this._value = new decimal(); break;
					case DbType.Currency				: 
					case DbType.VarNumeric				: 
					case DbType.Double					: this._value = new double(); break;
					case DbType.Single					: this._value = new float(); break;
					//user defined
					case DbType.Object					: this._value = new object(); break;
					//Guid
					case DbType.Guid					: this._value = new Guid(); break;															
					default								: throw new ArgumentOutOfRangeException("value");
				}
			}
		}
		
		protected void SetValue( string value )
		{
				switch( this.DataType )
				{
					//string type
					case DbType.Object					:					
					case DbType.Binary					: 											
					case DbType.AnsiString				: 
					case DbType.AnsiStringFixedLength	: 
					case DbType.String					: 
					case DbType.StringFixedLength		: this._value = value; break;

					case DbType.Boolean					: this._value = bool.Parse( value ); break;

					case DbType.SByte					: this._value = sbyte.Parse( value ); break;
					case DbType.Byte					: this._value = byte.Parse( value ); break;					 
					case DbType.Int16					: this._value = short.Parse( value ); break;
					case DbType.Int32					: this._value = int.Parse( value ); break;
					case DbType.Int64					: this._value = long.Parse( value ); break;
					case DbType.UInt16					: this._value = ushort.Parse( value ); break;
					case DbType.UInt32					: this._value = uint.Parse( value ); break;
					case DbType.UInt64					: this._value = long.Parse( value ); break;					

					case DbType.Date					: 
					case DbType.DateTime				:
					case DbType.Time					: this._value = DateTime.Parse( value ); break;

					case DbType.Decimal					: this._value = decimal.Parse( value ); break;
					case DbType.Currency				: 
					case DbType.VarNumeric				: 
					case DbType.Double					: this._value = double.Parse( value ); break;
					case DbType.Single					: this._value = float.Parse( value );  break;

					case DbType.Guid					: this._value = new Guid( value ); break;															
					default								: throw new ArgumentOutOfRangeException("value");
				}			
		}
		
		///<summary>
		/// Value of the parameter
		/// ( used only while extracting data or executing procedure )
		///</summary>
		public object Value
		{
			get
			{
				return this._value;
			}
			set
			{
				this.SetValue( value.ToString() );
			}
		}
		
		///<summary>
		/// Value of the parameter
		/// ( used only while extracting data or executing procedure )
		///</summary>
		public ParameterDirection Type
		{
			get
			{
				return this._type;
			}
			set
			{
				this._type = value;
			}
		}
		
		public override string NormalizedName 
		{
			get {
				string normalizedName = "";
								
				if ( (this.OwnerName != "") && (this.OwnerName != null) ){
					normalizedName +=  this.OwnerName +  ".";
				} 				
				
				normalizedName +=  this.Name;
				
				return normalizedName;
			}
		}
		
		protected override void CreateEntitiesList()
		{		
		}
		
		public SharpQueryParameter( IConnection connection, string catalogName, string schemaName, string ownerName, string name  ) : base(connection, catalogName, schemaName, ownerName, name )
		{
			this.pEntities = null;
		}			
		
		protected override void OnRefresh()		
		{
			//nothing !
		}

		///<summary>
		/// For a Table or a View extract data.
		/// For a stocked procedure, execute it :o).
		/// <param name="rows">Number of row to extract. if "0", extract all rows.</param>
		/// <returns><see cref="System.Data.DataTable">DataTable</see></returns>
		/// </summary>
		public override object Execute( int rows, SharpQuerySchemaClassCollection parameters )
		{
			//nothing
			return null;
		}	
		
		///<summary> return a <see cref="System.Windows.Forms.DataObject">DataObject</see> 
		///</summary>		
		public override DataObject DragObject
		{
			get
			{
				DataObject returnValue = new DataObject();			
				string extract = NormalizedName;
				returnValue.SetData(typeof(string) , extract );
				return returnValue;
			}
		}		
	}	
	
	///<summary>
	/// Table class
	///</summary>	
	public class SharpQueryProcedure : AbstractSharpQuerySchemaClass
	{		
		public override string NormalizedName 
		{
			get 
			{
				if ( (this.CatalogName != "") && (this.CatalogName != null) )
				{
					return this.CatalogName + "." + this.Name;
				}
				else
				{
					return CheckWhiteSpace(this.Connection.GetProperty( AbstractSharpQueryConnectionWrapper.SharpQueryPropertyEnum.DataSource ).ToString()) + "." + this.Name;
				}
			}
		}
		
		protected override void CreateEntitiesList()
		{
			base.CreateEntitiesList();
			this.pEntities.Add("PROCEDURE_COLUMNS", new SharpQuerySchemaClassCollection() );
			this.pEntities.Add("PROCEDURE_PARAMETERS", new SharpQuerySchemaClassCollection() );
		}
				
		public SharpQueryProcedure( IConnection connection, string catalogName, string schemaName, string ownerName, string name  ) : base(connection, catalogName, schemaName, ownerName, name )
		{
		}					
		
		public override SharpQuerySchemaClassCollection GetSchemaParameters()
		{
			return this.pDataConnection.GetSchemaProcedureParameters( this );			
		}
		
		public override SharpQuerySchemaClassCollection GetSchemaColumns()
		{
			return this.pDataConnection.GetSchemaProcedureColumns( this );			
		}		
				
		protected override void OnRefresh()
		{
			this.Entities["PROCEDURE_COLUMNS"].AddRange( this.GetSchemaColumns() );
			this.Entities["PROCEDURE_PARAMETERS"].AddRange( this.GetSchemaParameters() );
		}	
		
		///<summary>
		/// For a Table or a View extract data.
		/// For a stocked procedure, execute it :o).
		/// <param name="rows">Number of row to extract. if "0", extract all rows.</param>
		/// <returns><see cref="System.Data.DataTable">DataTable</see> 
		/// or a <see cref="System.Data.DataSet">DataSet</see> </returns>
		/// </summary>
		public override object Execute( int rows, SharpQuerySchemaClassCollection parameters )
		{
			return this.Connection.ExecuteProcedure( this, rows, parameters );			
		}		
		
		///<summary> return a <see cref="System.Windows.Forms.DataObject">DataObject</see> 
		///</summary>		
		public override DataObject DragObject
		{
			get
			{
				DataObject returnValue = new DataObject();			
				string extract = "EXECUTE " + NormalizedName;
				returnValue.SetData(typeof(string) , extract );
				return returnValue;
			}
		}		
	}
	
	///<summary>
	/// Table class
	///</summary>	
	public class SharpQueryTable : AbstractSharpQuerySchemaClass
	{
		public override string NormalizedName 
		{
			get 
			{
				if ( (this.CatalogName != "") && (this.CatalogName != null) )
				{
					return this.CatalogName + "." + this.Name;
				}
				else
				{
					return CheckWhiteSpace(this.Connection.GetProperty( AbstractSharpQueryConnectionWrapper.SharpQueryPropertyEnum.DataSource ).ToString()) + "." + this.Name;
				}
			}
		}
		
		protected override void CreateEntitiesList()
		{
			base.CreateEntitiesList();
			this.pEntities.Add("TABLE_COLUMNS", new SharpQuerySchemaClassCollection() );
		}		
				
		public SharpQueryTable( IConnection connection, string catalogName, string schemaName, string ownerName, string name  ) : base(connection, catalogName, schemaName, ownerName, name )
		{
		}		
		
		public override SharpQuerySchemaClassCollection GetSchemaColumns()
		{	
			return this.pDataConnection.GetSchemaTableColumns( this );
		}	
		
		protected override void OnRefresh()
		{
			this.Entities["TABLE_COLUMNS"].AddRange( this.GetSchemaColumns() );			
		}		

		///<summary>
		/// For a Table or a View extract data.
		/// For a stocked procedure, execute it :o).
		/// <param name="rows">Number of row to extract. if "0", extract all rows.</param>
		/// <returns><see cref="System.Data.DataTable">DataTable</see> 
		/// or a <see cref="System.Data.DataSet">DataSet</see> </returns>
		/// </summary>

⌨️ 快捷键说明

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