📄 templates.cs
字号:
/// <summary>
/// Gets and Sets the parent ORMBiz.Table.
/// </summary>
[System.ComponentModel.Bindable(false)]
public virtual ORMBiz.Table Table
{
get
{
if (row.GetParentRow(base.DataSet.Relations["FKTableIDColumn"]) != null)
return new ORMBiz.Table( DataContext, row.GetParentRow("FKTableIDColumn"));
else
return null;
}
set
{
if ( value == null )
{
row.SetParentRow(null, base.DataSet.Relations["FKTableIDColumn"] );
}
else
row.SetParentRow( value.row, base.DataSet.Relations["FKTableIDColumn"] );
}
}
}
/// <summary>
/// Wraps a datarow, exposing it's richest features as properties and methods.
/// </summary>
public abstract class DatabaseOrmTemplate : Business
{
/// <summary>
/// Default Constructor
/// </summary>
/// <param name="dataContext">The DataManager this object should perform it's operations with</param>
/// <param name="ROW">The underlying row that this object will wrap</param>
internal DatabaseOrmTemplate( DataManager dataContext, DataRow ROW) : base(dataContext)
{
row = ROW;
}
/// <summary>
/// Gets and sets the property at the underlying row index.
/// </summary>
public object this[int index]
{
get
{
if ( this.row.IsNull(index) )
return null;
else
return this.row[index];
}
set
{
if ( value == null )
this.row[index] = DBNull.Value;
else
this.row[index] = value;
}
}
/// <summary>
/// Gets and sets the property by its name.
/// </summary>
/// <remarks>
/// Do not use the underlying column name if it is different.
/// </remarks>
public object this[string property]
{
get
{
System.Reflection.PropertyInfo pi = this.GetType().GetProperty(property);
if ( pi != null && pi.CanRead )
return pi.GetValue(this, null);
System.Reflection.MethodInfo mi = this.GetType().GetMethod("Get" + property,new Type[]{});
if ( mi != null )
return mi.Invoke(this, null);
return null;
}
set
{
System.Reflection.PropertyInfo pi = this.GetType().GetProperty(property);
if ( pi != null && pi.CanWrite )
{
pi.SetValue(this, value, null);
return;
}
System.Reflection.MethodInfo mi = this.GetType().GetMethod("Set" + property,new Type[]{value.GetType()});
if ( mi != null )
mi.Invoke(this, new object[]{value});
}
}
/// <summary>
/// Returns true if the underlying DataRow.RowState is marked as DataRowState.Deleted
/// </summary>
/// <returns>true if deleted</returns>
public virtual bool IsDeleted()
{
return row.RowState == DataRowState.Deleted;
}
/// <summary>
/// Gets the ID.
/// </summary>
/// <value>
/// The underlying rows ID cell
/// </value>
public virtual System.Int32 ID
{
get
{
if (row.RowState != DataRowState.Deleted)
return (System.Int32) row["ID"];
else
return (System.Int32) row["ID", DataRowVersion.Original];
//System.Int32
}
}
/// <summary>
/// Gets and Sets the DatabaseName.
/// </summary>
/// <value>
/// The underlying rows DatabaseName cell
/// </value>
public virtual System.String DatabaseName
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("DatabaseName") ? null : (System.String) row["DatabaseName"];
else
return row.IsNull(row.Table.Columns["DatabaseName"], DataRowVersion.Original) ? null : (System.String) row["DatabaseName", DataRowVersion.Original];
//System.String
}
set
{
row["DatabaseName"] = value;
}
}
/// <summary>
/// Gets and Sets the DatabaseToken.
/// </summary>
/// <value>
/// The underlying rows DatabaseToken cell
/// </value>
public virtual System.String DatabaseToken
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("DatabaseToken") ? null : (System.String) row["DatabaseToken"];
else
return row.IsNull(row.Table.Columns["DatabaseToken"], DataRowVersion.Original) ? null : (System.String) row["DatabaseToken", DataRowVersion.Original];
//System.String
}
set
{
row["DatabaseToken"] = value;
}
}
private ORMBiz.ProcedureCollection _Procedures = null;
/// <summary>
/// Refreshes the collection of Procedures from the underlying dataset
/// </summary>
internal void refreshProcedures()
{
if (_Procedures == null) _Procedures = new ORMBiz.ProcedureCollection();
((IList)_Procedures).Clear();
DataRow[] cr = row.GetChildRows("FKDatabaseIDProcedure");
foreach( DataRow chld in cr)
{
ORMBiz.Procedure obj = new ORMBiz.Procedure(base.DataContext, chld);
_Procedures.Add( obj );
}
// add after, so that events wont be fired
_Procedures.Parent = this;
}
/// <summary>
/// Exposes the collection of child ORMBiz.Procedures.
/// </summary>
public virtual ORMBiz.ProcedureCollection Procedures
{
get
{
if (_Procedures == null) refreshProcedures();
return _Procedures;
}
}
/// <summary>
/// Adds a ORMBiz.Procedure to the collection.
/// </summary>
public virtual int AddProcedure(ORMBiz.Procedure newProcedure)
{
if ( _Procedures == null ) refreshProcedures();
if ( newProcedure.row.GetParentRow(base.DataSet.Relations["FKDatabaseIDProcedure"]) == row )
return _Procedures.IndexOf( newProcedure );
newProcedure.row.SetParentRow(row,base.DataSet.Relations["FKDatabaseIDProcedure"]);
int index = _Procedures.Add( newProcedure );
return index;
}
/// <summary>
/// Creates a new ORMBiz.Procedure, adding it to the collection.
/// </summary>
/// <remarks>
/// CommitAll() must be called to persist this to the database.
/// </remarks>
/// <returns>A new Procedure object</returns>
public virtual ORMBiz.Procedure NewProcedure()
{
if ( _Procedures == null ) refreshProcedures();
ORMBiz.Procedure newProcedure = new ORMBiz.Procedure(base.DataContext, base.DataSet.Tables["Procedure"].NewRow());
base.DataSet.Tables["Procedure"].Rows.Add(newProcedure.row);
this.AddProcedure(newProcedure);
return newProcedure;
}
private ORMBiz.TableCollection _Tables = null;
/// <summary>
/// Refreshes the collection of Tables from the underlying dataset
/// </summary>
internal void refreshTables()
{
if (_Tables == null) _Tables = new ORMBiz.TableCollection();
((IList)_Tables).Clear();
DataRow[] cr = row.GetChildRows("FKDatabaseIDTable");
foreach( DataRow chld in cr)
{
ORMBiz.Table obj = new ORMBiz.Table(base.DataContext, chld);
_Tables.Add( obj );
}
// add after, so that events wont be fired
_Tables.Parent = this;
}
/// <summary>
/// Exposes the collection of child ORMBiz.Tables.
/// </summary>
public virtual ORMBiz.TableCollection Tables
{
get
{
if (_Tables == null) refreshTables();
return _Tables;
}
}
/// <summary>
/// Adds a ORMBiz.Table to the collection.
/// </summary>
public virtual int AddTable(ORMBiz.Table newTable)
{
if ( _Tables == null ) refreshTables();
if ( newTable.row.GetParentRow(base.DataSet.Relations["FKDatabaseIDTable"]) == row )
return _Tables.IndexOf( newTable );
newTable.row.SetParentRow(row,base.DataSet.Relations["FKDatabaseIDTable"]);
int index = _Tables.Add( newTable );
return index;
}
/// <summary>
/// Creates a new ORMBiz.Table, adding it to the collection.
/// </summary>
/// <remarks>
/// CommitAll() must be called to persist this to the database.
/// </remarks>
/// <returns>A new Table object</returns>
public virtual ORMBiz.Table NewTable()
{
if ( _Tables == null ) refreshTables();
ORMBiz.Table newTable = new ORMBiz.Table(base.DataContext, base.DataSet.Tables["Table"].NewRow());
base.DataSet.Tables["Table"].Rows.Add(newTable.row);
this.AddTable(newTable);
return newTable;
}
}
/// <summary>
/// Wraps a datarow, exposing it's richest features as properties and methods.
/// </summary>
public abstract class DataTypeOrmTemplate : Business
{
/// <summary>
/// Default Constructor
/// </summary>
/// <param name="dataContext">The DataManager this object should perform it's operations with</param>
/// <param name="ROW">The underlying row that this object will wrap</param>
internal DataTypeOrmTemplate( DataManager dataContext, DataRow ROW) : base(dataContext)
{
row = ROW;
}
/// <summary>
/// Gets and sets the property at the underlying row index.
/// </summary>
public object this[int index]
{
get
{
if ( this.row.IsNull(index) )
return null;
else
return this.row[index];
}
set
{
if ( value == null )
this.row[index] = DBNull.Value;
else
this.row[index] = value;
}
}
/// <summary>
/// Gets and sets the property by its name.
/// </summary>
/// <remarks>
/// Do not use the underlying column name if it is different.
/// </remarks>
public object this[string property]
{
get
{
System.Reflection.PropertyInfo pi = this.GetType().GetProperty(property);
if ( pi != null && pi.CanRead )
return pi.GetValue(this, null);
System.Reflection.MethodInfo mi = this.GetType().GetMethod("Get" + property,new Type[]{});
if ( mi != null )
return mi.Invoke(this, null);
return null;
}
set
{
System.Reflection.PropertyInfo pi = this.GetType().GetProperty(property);
if ( pi != null && pi.CanWrite )
{
pi.SetValue(this, value, null);
return;
}
System.Reflection.MethodInfo mi = this.GetType().GetMethod("Set" + property,new Type[]{value.GetType()});
if ( mi != null )
mi.Invoke(this, new object[]{value});
}
}
/// <summary>
/// Returns true if the underlying DataRow.RowState is marked as DataRowState.Deleted
/// </summary>
/// <returns>true if deleted</returns>
public virtual bool IsDeleted()
{
return row.RowState == DataRowState.Deleted;
}
/// <summary>
/// Gets the ID.
/// </summary>
/// <value>
/// The underlying rows ID cell
/// </value>
public virtual System.Int32 ID
{
get
{
if (row.RowState != DataRowState.Deleted)
return (System.Int32) row["ID"];
else
return (System.Int32) row["ID", DataRowVersion.Original];
//System.Int32
}
}
/// <summary>
/// Gets and Sets the SqlType.
/// </summary>
/// <value>
/// The underlying rows SqlType cell
/// </value>
public virtual System.String SqlType
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("SqlType") ? null : (System.String) row["SqlType"];
else
return row.IsNull(row.Table.Columns["SqlType"], DataRowVersion.Original) ? null : (System.String) row["SqlType", DataRowVersion.Original];
//System.String
}
set
{
row["SqlType"] = value;
}
}
/// <summary>
/// Gets and Sets the NetType.
/// </summary>
/// <value>
/// The underlying rows NetType cell
/// </value>
public virtual System.String NetType
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("NetType") ? null : (System.String) row["NetType"];
else
return row.IsNull(row.Table.Columns["NetType"], DataRowVersion.Original) ? null : (System.String) row["NetType", DataRowVersion.Original];
//System.String
}
set
{
row["NetType"] = value;
}
}
/// <summary>
/// Gets and Sets the XmlType.
/// </summary>
/// <value>
/// The underlying rows XmlType cell
/// </value>
public virtual System.String XmlType
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("XmlType") ? null : (System.String) row["XmlType"];
else
return row.IsNull(row.Table.Columns["XmlType"], DataRowVersion.Original) ? null : (System.String) row["XmlType", DataRowVersion.Original];
//System.String
}
set
{
row["XmlType"] = value;
}
}
/// <summary>
/// Gets and Sets the NetSqlType.
/// </summary>
/// <value>
/// The underlying rows NetSqlType cell
/// </value>
public virtual System.String NetSqlType
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -