- framework.development.zip
- App
- App.BusinessControler
- App.Controller
- App.DataSets
- App.UnitTest
- App.WebForm
- App.WinForm
- Build
- App.WinForm.vshost.exe
- nunit.framework.dll
- db.mdb
- Documents
- RelationState.xls
- Spec.doc
- Framework.Development.sln
- Framework.Development.suo
- Framework
- Framework.DAL
- Framework.Lib
- Framework.UI.baController
- Framework.UI.baInterfaces
- Framework.UI.baResources
- Framework.UI.baWeb
- Framework.UI.baWin32
- nunit.framework.dll
- SOA.txt
- app.development.zip
|
using System;
using System.Collections.Generic;
using System.Data;
namespace Framework.baInterfaces
{
/// <summary>
/// The Change (Add, Edit, Delete) request being
/// transfred from Controller Insert/Update/Delete
/// to Model layer with field values in the Token
/// </summary>
#region baToken
public class baToken
{
#region FieldAttributeEnum
/// A bit field or flag enumeration of a field attribute.
[Flags]
public enum FieldAttributeEnum
{
isIncluded = 1, /// The field is included in operation
isInPrimaryKeys = 2, /// The field is PrimaryKey in operation
All = isIncluded | isInPrimaryKeys
}
#endregion
/// <summary>
/// This is the field info including
/// whether or not it is a PrimaryKey,
/// AutoInc and Included in operation
/// and the value the field has
/// </summary>
#region baField class type
public class baField
{
private object _val; /// The Value of the field
private DataColumn _Column; /// The DataColumn of the field
private FieldAttributeEnum _fieldAttribute;
private byte _precision;
#region FieldValue
public object FieldValue
{
get
{
return _val;
}
set
{
_val = value;
}
}
#endregion
#region Column
public DataColumn Column
{
get
{
return _Column;
}
}
#endregion
#region Size
public int Size
{
get
{
return _Column.MaxLength;
}
}
#endregion
#region Precision
public byte Precision
{
get
{
return _precision;
}
set
{
_precision = value;
}
}
#endregion
#region IsPrimaryKeys
public bool IsPrimaryKey
{
get
{
return ((_fieldAttribute & FieldAttributeEnum.isInPrimaryKeys) == 0 ? false : true);
}
set
{
_fieldAttribute =
(value ?
_fieldAttribute | FieldAttributeEnum.isInPrimaryKeys : /// isIncluded be true
_fieldAttribute & ~FieldAttributeEnum.isInPrimaryKeys); /// isIncluded be false
}
}
#endregion
#region IsAuto
public bool IsAuto
{
get
{
return _Column.AutoIncrement;
}
set
{
_Column.AutoIncrement = value;
}
}
#endregion
#region IsIncluded
public bool IsIncluded
{
get
{
return ((_fieldAttribute & FieldAttributeEnum.isIncluded) == 0 ? false : true);
}
set
{
_fieldAttribute =
(value ?
_fieldAttribute | FieldAttributeEnum.isIncluded : /// isIncluded be true
_fieldAttribute & ~FieldAttributeEnum.isIncluded); /// isIncluded be false
}
}
#endregion
#region Constructor
public baField(DataColumn column, byte precision, object val, bool isPrimaryKey, bool isIncluded)
{
this._Column = column;
this._precision = precision;
this._val = val;
this.IsIncluded = isIncluded;
this.IsPrimaryKey = isPrimaryKey;
}
public baField(DataColumn column, object val, bool isPrimaryKey, bool isIncluded)
{
this._Column = column;
this._precision = 0;
this._val = val;
this.IsIncluded = isIncluded;
this.IsPrimaryKey = isPrimaryKey;
}
public baField(DataColumn column, bool isPrimaryKey, bool isIncluded)
{
this._Column = column;
this._precision = 0;
this._val = null;
this.IsIncluded = isIncluded;
this.IsPrimaryKey = isPrimaryKey;
}
private baField()
{
}
#endregion
#region bool Equals(baField obj)
/// <summary>
/// June 15, 06
/// Compare this instance of baField with obj.
/// </summary>
/// <param name="obj">baField instance to be compared with this one</param>
/// <returns>true if the instances are equal else false</returns>
public bool Equals(baField obj)
{
if (this._fieldAttribute == obj._fieldAttribute &&
this._val == obj._val)
return true;
else
return false;
}
#endregion
#region bool EqualAttributes(baField obj)
/// <summary>
/// June 15, 06
/// Compare the structure of this instance of baField with obj.
/// </summary>
/// <param name="obj">baField instance to be compared with this one</param>
/// <returns>true if the instances are equal else false</returns>
public bool EqualAttributes(baField obj)
{
if (this._fieldAttribute == obj._fieldAttribute)
return true;
else
return false;
}
#endregion
}
#endregion
#region baField Fields and TableName values
private Dictionary<string, baField> fields = null;
private string tableName = null;
private DataTable table;
#region string TableName
public string TableName
{
get
{
return tableName;
}
}
#endregion
public DataTable Table
{
get { return table; }
}
#region Dictionary<string, baField> Fields
public Dictionary<string, baField> Fields
{
get
{
return fields;
}
}
#endregion
#region baField this[string FieldName]
public baField this[string FieldName]
{
get
{
if (Fields.ContainsKey(FieldName))
return Fields[FieldName];
else
return null;
}
set
{
if (Fields.ContainsKey(FieldName))
Fields[FieldName] = value;
else
Fields.Add(FieldName, value);
}
}
#endregion
#region baField[] PrimaryKeys
public baField[] PrimaryKeys
{
get
{
// Find the Pk field names
string[] isPkCol = new string[this.Count];
int i=0;
foreach (KeyValuePair<string, baField> kvp in fields)
{
if (kvp.Value.IsPrimaryKey)
isPkCol[i++] = kvp.Value.Column.ColumnName;
}
baField[] pkCols = new baField[i];
for (int j = 0; j < i;j++ )
{
pkCols[j] = this[isPkCol[j]];
}
return pkCols;
}
}
#endregion
#region baField AutoField
public baField AutoField
{
get
{
foreach (KeyValuePair<string, baField> kvp in fields)
{
if (kvp.Value.IsAuto)
return kvp.Value;
}
return null;
}
}
#endregion
#region int Count
public int Count
{
get
{
return fields.Count;
}
}
#endregion
#endregion
#region Constructor
public baToken(DataTable _table)
{
this.table = _table;
this.tableName = _table.TableName;
fields = new Dictionary<string, baField>();
}
#endregion
#region bool Equals(baToken obj)
/// <summary>
/// June 15, 06
/// Compare this instance of baToken with obj. It compares the
/// structure of two baTokens (Fields) not the values in Fields
/// </summary>
/// <param name="obj">baToken instance to be compared with this one</param>
/// <returns>true if the instances are equal else false</returns>
public bool Equals(baToken obj)
{
if (this.Count == obj.Count && this.TableName==obj.TableName)
{
return base.Equals(obj);
}
else
return false;
}
#endregion
#region Contains(baToken token)
/// <summary>
/// June 15, 06
/// Check to see if this baToken is holding token fields structure
/// </summary>
/// <param name="token">the token to check their fields existance in this baToken</param>
/// <returns>true if ba token has these fields else false</returns>
public bool Contains(baToken token)
{
if (this.Count >= token.Count && this.TableName == token.TableName)
{
/// Move on the fields of the sent token to see
/// if this token has exactly the sent token fields
foreach (KeyValuePair<string, baField> fld in token.Fields)
{
if (this.Fields.ContainsKey(fld.Key))
{
if (!this.Fields[fld.Key].EqualAttributes(fld.Value))
return false;
}
else
return false;
}
return true;
}
else
return false;
}
#endregion
}
#endregion
/// <summary>
/// This is the interface that is being used in
/// Transportation and Controller layer to
/// communicate with Model layer
/// </summary>
#region IBaseModel
public interface IBaseModel
{
DataSet GetDataSet();
int FetchData(DataSet ds, string tableName);
int FetchData(DataSet ds, string tableName, string filter);
int FetchData(DataTable dataTable);
int FetchData(DataTable dataTable, string filter);
int Insert(baToken theFields);
int Update(baToken theFields);
int Delete(baToken theFields);
int Select(baToken theFields);
}
#endregion
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.