现在的位置: 首页 > 综合 > 正文

define a DbParam class and DbParamCollection

2013年09月05日 ⁄ 综合 ⁄ 共 3476字 ⁄ 字号 评论关闭

using System;
using System.Collections ;

namespace LiveChain.CSW.DataAccess
{
 /// <summary>
 /// Summary description for DBParams.
 /// </summary>
    /// <summary>
    ///  DB param Type .Use type by self can easy to extend ..
    /// the Cursor
    /// </summary>
    public enum  DbPType
    {
        String = 1 ,
        Decimal = 2 ,
        Int16 = 3 ,
        Int32 = 4 ,
        Int = 4 ,
        Int64 = 5 ,
        DateTime = 6 ,
        Boolean = 7 ,
        Binary = 8 ,
        Double = 9 ,

        Cursor = 20
    }

    public enum DbParamDirection
    {
        Input = 1 ,
        Output = 2 ,
        InputOutput =3
    }
    public class DbParam
    {
        public string Name;
        public object Value;
        public DbPType Type;
        public int Size;
        public DbParamDirection Direction ;
       
        //if the Name changed ,the old name use to find it's name with start .
        //the conllection 's index[string] use this oldName ;
        //but , it also take a problem , when the use change the Name before do procedure .
        //the result value will wrong . ??
        public string OldName
        {
            get { return oldName ;}
        }
        private string oldName ;

        public DbParam(string AName,DbPType pType,int ASize,object AValue ,DbParamDirection pdirection)
        {   
            oldName = AName ;
            Name = AName;    
            Value = AValue;
            Type = pType;
            Size = ASize;
            this.Direction = pdirection  ;
        }
        public DbParam(string AName,DbPType pType,int ASize,DbParamDirection pdirection)
            : this(AName,pType,ASize,null,pdirection)
        {}

        public DbParam(string AName,DbPType pType,int ASize,object AValue)
            : this(AName,pType,ASize,AValue,DbParamDirection.Input)
        {}

        public DbParam(string AName,DbPType pType,object AValue)
            : this(AName,pType,0,AValue)
        {}
    }

    public class DbParamCollection : System.Collections.CollectionBase,System.ComponentModel.IListSource
        {
            //        string fullName = "LiveChain.CSW.CommonData.DbParam";
            public DbParam this[ int index ] 
            {
                get 
                {
                    return( (DbParam) List[index] );
                }
                set 
                {
                    List[index] = value;
                }
            }
            //add the name index ,can  easy to use it .
            public DbParam this[string name]
            {
                get {
                    foreach (DbParam p in List)
                    {
                        if (p.OldName == name)
                            return p ;
                    }
                    return null ;
                }
            }

            public int Add( DbParam value ) 
            {
                return( List.Add( value ) );
            }

            public int IndexOf( DbParam value ) 
            {
                return( List.IndexOf( value ) );
            }

            public void Insert( int index, DbParam value ) 
            {
                List.Insert( index, value );
            }

            public void Remove( DbParam value ) 
            {
                List.Remove( value );
            }

            public bool Contains( DbParam value ) 
            {
                // If value is not of type DbParam, this will return false.
                return( List.Contains( value ) );
            }

            #region IListSource 成员

            public IList GetList()
            {
                // TODO:  添加 ChildLocationDataCollection.GetList 实现
                return this.List;
            }

            public bool ContainsListCollection
            {
                get
                {
                    // TODO:  添加 ChildLocationDataCollection.ContainsListCollection getter 实现
                    return false;
                }
            }

            #endregion
        }

}

【上篇】
【下篇】

抱歉!评论已关闭.