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

📄 cdata.cs

📁 简单数据库
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Data;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace QueryTool_V1
{
    public abstract class CDataBase
    {
        #region "Member Variables"

        protected int _tabIndex;  //local member variable which stores the object's UniqueId

        #endregion

        #region "Properties"

        /// <summary>
        /// UniqueId property for every business object
        /// </summary>
        public int TabIndex
        {
            get
            {
                return _tabIndex;
            }
            set
            {
                _tabIndex = value;
            }
        }

        #endregion
    }
    public class CDataCollection<T> : ICollection<T> where T : CDataBase
    {
        #region "Member Variables"

        protected ArrayList _innerArray;  //inner ArrayList object
        protected bool _IsReadOnly;       //flag for setting collection to read-only mode (not used in this example)

        #endregion

        #region "Constructors"

        /// <summary>
        /// Default constructor
        /// </summary>
        public CDataCollection()
        {
            _innerArray = new ArrayList();
        }

        #endregion

        #region "Properties"

        /// <summary>
        /// Default accessor for the collection 
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public virtual T this[int index]
        {
            get
            {
                return (T)_innerArray[index];
            }
            set
            {
                _innerArray[index] = value;
            }
        }

        /// <summary>
        /// Number of elements in the collection
        /// </summary>
        public virtual int Count
        {
            get
            {
                return _innerArray.Count;
            }
        }

        /// <summary>
        /// Flag sets whether or not this collection is read-only
        /// </summary>
        public virtual bool IsReadOnly
        {
            get
            {
                return _IsReadOnly;
            }
        }

        #endregion

        #region "Methods"

        /// <summary>
        /// Add a business object to the collection
        /// </summary>
        /// <param name="BusinessObject"></param>
        public virtual void Add(T CData)
        {
            _innerArray.Add(CData);
        }

        /// <summary>
        /// Remove first instance of a business object from the collection
        /// </summary>
        /// <param name="BusinessObject"></param>
        /// <returns></returns>
        public virtual bool Remove(T CData)
        {
            bool result = false;

            //loop through the inner array's indices
            for (int i = 0; i < _innerArray.Count; i++)
            {
                //store current index being checked
                T obj = (T)_innerArray[i];

                //compare the BusinessObjectBase UniqueId property
                if (obj.TabIndex == CData.TabIndex)
                {
                    //remove item from inner ArrayList at index i
                    _innerArray.RemoveAt(i);
                    result = true;
                    break;
                }
            }

            return result;
        }

        /// <summary>
        /// Returns true/false based on whether or not it finds the requested object in the collection.
        /// </summary>
        /// <param name="BusinessObject"></param>
        /// <returns></returns>
        public bool Contains(T CData)
        {
            //loop through the inner ArrayList
            foreach (T obj in _innerArray)
            {
                //compare the BusinessObjectBase UniqueId property
                if (obj.TabIndex == CData.TabIndex)
                {
                    //if it matches return true
                    return true;
                }
            }

            //no match
            return false;
        }

        /// <summary>
        /// Copy objects from this collection into another array
        /// </summary>
        /// <param name="BusinessObjectArray"></param>
        /// <param name="index"></param>
        public virtual void CopyTo(T[] CDataArray, int index)
        {
            throw new Exception("This Method is not valid for this implementation.");
        }

        /// <summary>
        /// Clear the collection of all it's elements
        /// </summary>
        public virtual void Clear()
        {
            _innerArray.Clear();
        }

        /// <summary>
        /// Returns custom generic enumerator for this BusinessObjectCollection
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerator<T> GetEnumerator()
        {
            //return a custom enumerator object instantiated to use this BusinessObjectCollection 
            return new CDataEnumerator<T>(this);
        }

        /// <summary>
        /// Explicit non-generic interface implementation for IEnumerable extended and required by ICollection (implemented by ICollection<T>)
        /// </summary>
        /// <returns></returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return new CDataEnumerator<T>(this);
        }

        #endregion
    }
    public class CDataEnumerator<T> : IEnumerator<T> where T : CDataBase
    {
        #region "Member Variables"

        protected CDataCollection<T> _collection;  //enumerated collection
        protected int index;                                //current index
        protected T _current;                               //current enumerated object in the collection

        #endregion

        #region "Constructors"

        /// <summary>
        /// Default constructor
        /// </summary>
        public CDataEnumerator()
        {
            //nothing
        }

        /// <summary>
        /// Paramaterized constructor which takes the collection which this enumerator will enumerate
        /// </summary>
        /// <param name="collection"></param>
        public CDataEnumerator(CDataCollection<T> collection)
        {
            _collection = collection;
            index = -1;
            _current = default(T);
        }

        #endregion

        #region "Properties"

        /// <summary>
        /// Current Enumerated object in the inner collection
        /// </summary>
        public virtual T Current
        {
            get
            {
                return _current;
            }
        }

        /// <summary>
        /// Explicit non-generic interface implementation for IEnumerator (extended and required by IEnumerator<T>)
        /// </summary>
        object IEnumerator.Current
        {
            get
            {
                return _current;
            }
        }

        #endregion

        #region "Methods"

        /// <summary>
        /// Dispose method
        /// </summary>
        public virtual void Dispose()
        {
            _collection = null;
            _current = default(T);
            index = -1;
        }

        /// <summary>
        /// Move to next element in the inner collection
        /// </summary>
        /// <returns></returns>
        public virtual bool MoveNext()
        {
            //make sure we are within the bounds of the collection
            if (++index >= _collection.Count)
            {
                //if not return false
                return false;
            }
            else
            {
                //if we are, then set the current element to the next object in the collection
                _current = _collection[index];
            }

            //return true
            return true;
        }

        /// <summary>
        /// Reset the enumerator
        /// </summary>
        public virtual void Reset()
        {
            _current = default(T); //reset current object
            index = -1;
        }

        #endregion
    }
    public class CData : CDataBase
    {
        #region "Member Variables"

        private int _employeeID;
        private string _employeeName;
        private DateTime _dateofJoining;
        private string _workSpace;

        #endregion

        #region "Constructors"

        /// <summary>
        /// Paramaterized constructor for immediate instantiation
        /// </summary>
        /// <param name="first"></param>
        /// <param name="last"></param>
        public CData(int employeeID, string employeeName, DateTime dateofJoining, string workSpace)
        {
            _employeeID = employeeID;
            _employeeName = employeeName;
            _dateofJoining = dateofJoining;
            _workSpace = workSpace;
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        public CData()
        {
            //nothing
        }

        #endregion

        #region "Properties"

        public int EmployeeID
        {
            get
            {
                return _employeeID;
            }
            set
            {
                _employeeID = value;
            }
        }
        public string EmployeeName
        {
            get
            {
                return _employeeName;
            }
            set
            {
                _employeeName = value;
            }
        }
        public DateTime DateofJoining
        {
            get
            {
                return _dateofJoining;
            }
            set
            {
                _dateofJoining = value;
            }
        }
        public string WorkSpace
        {
            get
            {
                return _workSpace;
            }
            set
            {
                _workSpace = value;
            }
        }

        #endregion
    }

    public abstract class CColumnValuesBase
    {
        #region "Member Variables"

⌨️ 快捷键说明

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