📄 cdata.cs
字号:
protected string _columnName; //local member variable which stores the object's UniqueId
#endregion
#region "Properties"
/// <summary>
/// UniqueId property for every business object
/// </summary>
public string ColumnName
{
get
{
return _columnName;
}
set
{
_columnName = value;
}
}
#endregion
}
public class CColumnValuesCollection<T> : ICollection<T> where T : CColumnValuesBase
{
#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 CColumnValuesCollection()
{
_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 CColumnValuesBase)
{
_innerArray.Add(CColumnValuesBase);
}
/// <summary>
/// Remove first instance of a business object from the collection
/// </summary>
/// <param name="BusinessObject"></param>
/// <returns></returns>
public virtual bool Remove(T CColumnValuesBase)
{
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.ColumnName == CColumnValuesBase.ColumnName)
{
//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 CColumnValuesBase)
{
//loop through the inner ArrayList
foreach (T obj in _innerArray)
{
//compare the BusinessObjectBase UniqueId property
if (obj.ColumnName == CColumnValuesBase.ColumnName)
{
//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[] CColumnValuesArray, 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 CColumnValuesEnumerator<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 CColumnValuesEnumerator<T>(this);
}
#endregion
}
public class CColumnValuesEnumerator<T> : IEnumerator<T> where T : CColumnValuesBase
{
#region "Member Variables"
protected CColumnValuesCollection<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 CColumnValuesEnumerator()
{
//nothing
}
/// <summary>
/// Paramaterized constructor which takes the collection which this enumerator will enumerate
/// </summary>
/// <param name="collection"></param>
public CColumnValuesEnumerator(CColumnValuesCollection<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 CColumnValues : CColumnValuesBase
{
#region "Member Variables"
public ArrayList _columnValues;
#endregion
#region "Constructors"
/// <summary>
/// Default constructor
/// </summary>
public CColumnValues()
{
//nothing
}
#endregion
#region "Properties"
#endregion
}
public class CDataColumns
{
// Collections
public Dictionary<string, Type> _columnNameType;
private CColumnValues _columnValues;
public CColumnValuesCollection<CColumnValues> column_collection;
private DataTable _dt;
public CDataColumns()
{
CDataBaseOps objDataBase = new CDataBaseOps();
string queryCommand = "Select EmployeeID, EmployeeName, DateofJoining, WorkSpace from EmployeeInfo";
// Populate Data Table
_dt = objDataBase.ExecuteQuery(queryCommand);
if (_dt.Rows.Count > 0)
{
// Get ColumnTypes
_columnNameType = objDataBase.GetColumnNamesTypes(_dt);
// Get ColumnNames
//create a person collection using our generic collection object
column_collection = new CColumnValuesCollection<CColumnValues>();
Dictionary<string, Type>.KeyCollection _columnNames = _columnNameType.Keys;
Dictionary<string, Type>.Enumerator _columnNameEnum = _columnNameType.GetEnumerator();
while(_columnNameEnum.MoveNext())
{
KeyValuePair<string, Type> kvp = _columnNameEnum.Current;
_columnValues = new CColumnValues();
// Get Columns Names <===
_columnValues.ColumnName = kvp.Key;
// Get their Values <==
_columnValues._columnValues = objDataBase.GetValuesforColumn(kvp.Key, _dt);
column_collection.Add(_columnValues);
}
}
}
}
public class DataGVCell
{
public int _rowIndex;
public int _columnIndex;
public bool _isUpdated;
public string _cellValue;
public bool _cellClickedBefore;
public DataGVCell(int rowIndex, int columnIndex, bool isUpdated, string cellValue, bool cellClickedBefore)
{
_rowIndex = rowIndex;
_columnIndex = columnIndex;
_isUpdated = isUpdated;
_cellValue = cellValue;
_cellClickedBefore = cellClickedBefore;
}
}
public class DataGVCellCollection : CollectionBase
{
public void Add(DataGVCell value)
{
List.Add(value);
}
public bool Contains(DataGVCell value)
{
return List.Contains(value);
}
public void Remove(DataGVCell value)
{
List.Remove(value);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -