📄 templates.cs
字号:
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Collections;
using System.ComponentModel;
namespace ORMBiz
{
/// <summary>
/// Wraps a datarow, exposing it's richest features as properties and methods.
/// </summary>
public abstract class ColumnOrmTemplate : 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 ColumnOrmTemplate( 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 FKTableID.
/// </summary>
/// <value>
/// The underlying rows FKTableID cell
/// </value>
public virtual System.Data.SqlTypes.SqlInt32 FKTableID
{
get
{
if (row.RowState != DataRowState.Deleted)
{
if (row.IsNull("FKTableID"))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["FKTableID"]);
}
else
{
if (row.IsNull(row.Table.Columns["FKTableID"], DataRowVersion.Original))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["FKTableID", DataRowVersion.Original]);
}
}
set
{
if ( value.IsNull )
row["FKTableID"] = DBNull.Value;
else
row["FKTableID"] = value.Value;
}
}
/// <summary>
/// Gets and Sets the Name.
/// </summary>
/// <value>
/// The underlying rows Name cell
/// </value>
public virtual System.String Name
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("Name") ? null : (System.String) row["Name"];
else
return row.IsNull(row.Table.Columns["Name"], DataRowVersion.Original) ? null : (System.String) row["Name", DataRowVersion.Original];
//System.String
}
set
{
row["Name"] = value;
}
}
/// <summary>
/// Gets and Sets the FKDataTypeID.
/// </summary>
/// <value>
/// The underlying rows FKDataTypeID cell
/// </value>
public virtual System.Data.SqlTypes.SqlInt32 FKDataTypeID
{
get
{
if (row.RowState != DataRowState.Deleted)
{
if (row.IsNull("FKDataTypeID"))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["FKDataTypeID"]);
}
else
{
if (row.IsNull(row.Table.Columns["FKDataTypeID"], DataRowVersion.Original))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["FKDataTypeID", DataRowVersion.Original]);
}
}
set
{
if ( value.IsNull )
row["FKDataTypeID"] = DBNull.Value;
else
row["FKDataTypeID"] = value.Value;
}
}
/// <summary>
/// Gets and Sets the Length.
/// </summary>
/// <value>
/// The underlying rows Length cell
/// </value>
public virtual System.Data.SqlTypes.SqlInt32 Length
{
get
{
if (row.RowState != DataRowState.Deleted)
{
if (row.IsNull("Length"))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["Length"]);
}
else
{
if (row.IsNull(row.Table.Columns["Length"], DataRowVersion.Original))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["Length", DataRowVersion.Original]);
}
}
set
{
if ( value.IsNull )
row["Length"] = DBNull.Value;
else
row["Length"] = value.Value;
}
}
/// <summary>
/// Gets and Sets the PrimaryKey.
/// </summary>
/// <value>
/// The underlying rows PrimaryKey cell
/// </value>
public virtual System.String PrimaryKey
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("PrimaryKey") ? null : (System.String) row["PrimaryKey"];
else
return row.IsNull(row.Table.Columns["PrimaryKey"], DataRowVersion.Original) ? null : (System.String) row["PrimaryKey", DataRowVersion.Original];
//System.String
}
set
{
row["PrimaryKey"] = value;
}
}
/// <summary>
/// Gets and Sets the SetAccessor.
/// </summary>
/// <value>
/// The underlying rows SetAccessor cell
/// </value>
public virtual System.String SetAccessor
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("SetAccessor") ? null : (System.String) row["SetAccessor"];
else
return row.IsNull(row.Table.Columns["SetAccessor"], DataRowVersion.Original) ? null : (System.String) row["SetAccessor", DataRowVersion.Original];
//System.String
}
set
{
row["SetAccessor"] = value;
}
}
/// <summary>
/// Gets and Sets the GetAccessor.
/// </summary>
/// <value>
/// The underlying rows GetAccessor cell
/// </value>
public virtual System.String GetAccessor
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("GetAccessor") ? null : (System.String) row["GetAccessor"];
else
return row.IsNull(row.Table.Columns["GetAccessor"], DataRowVersion.Original) ? null : (System.String) row["GetAccessor", DataRowVersion.Original];
//System.String
}
set
{
row["GetAccessor"] = value;
}
}
/// <summary>
/// Gets and Sets the RequiredForInstantiation.
/// </summary>
/// <value>
/// The underlying rows RequiredForInstantiation cell
/// </value>
public virtual System.String RequiredForInstantiation
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("RequiredForInstantiation") ? null : (System.String) row["RequiredForInstantiation"];
else
return row.IsNull(row.Table.Columns["RequiredForInstantiation"], DataRowVersion.Original) ? null : (System.String) row["RequiredForInstantiation", DataRowVersion.Original];
//System.String
}
set
{
row["RequiredForInstantiation"] = value;
}
}
/// <summary>
/// Gets and Sets the AccessorName.
/// </summary>
/// <value>
/// The underlying rows AccessorName cell
/// </value>
public virtual System.String AccessorName
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("AccessorName") ? null : (System.String) row["AccessorName"];
else
return row.IsNull(row.Table.Columns["AccessorName"], DataRowVersion.Original) ? null : (System.String) row["AccessorName", DataRowVersion.Original];
//System.String
}
set
{
row["AccessorName"] = value;
}
}
/// <summary>
/// Gets and Sets the Nullable.
/// </summary>
/// <value>
/// The underlying rows Nullable cell
/// </value>
public virtual System.String Nullable
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("Nullable") ? null : (System.String) row["Nullable"];
else
return row.IsNull(row.Table.Columns["Nullable"], DataRowVersion.Original) ? null : (System.String) row["Nullable", DataRowVersion.Original];
//System.String
}
set
{
row["Nullable"] = value;
}
}
/// <summary>
/// Gets and Sets the IsIdentity.
/// </summary>
/// <value>
/// The underlying rows IsIdentity cell
/// </value>
public virtual System.String IsIdentity
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("IsIdentity") ? null : (System.String) row["IsIdentity"];
else
return row.IsNull(row.Table.Columns["IsIdentity"], DataRowVersion.Original) ? null : (System.String) row["IsIdentity", DataRowVersion.Original];
//System.String
}
set
{
row["IsIdentity"] = value;
}
}
/// <summary>
/// Gets and Sets the IsReadOnly.
/// </summary>
/// <value>
/// The underlying rows IsReadOnly cell
/// </value>
public virtual System.String IsReadOnly
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("IsReadOnly") ? null : (System.String) row["IsReadOnly"];
else
return row.IsNull(row.Table.Columns["IsReadOnly"], DataRowVersion.Original) ? null : (System.String) row["IsReadOnly", DataRowVersion.Original];
//System.String
}
set
{
row["IsReadOnly"] = value;
}
}
/// <summary>
/// Gets and Sets the DeclaredType.
/// </summary>
/// <value>
/// The underlying rows DeclaredType cell
/// </value>
public virtual System.String DeclaredType
{
get
{
if (row.RowState != DataRowState.Deleted)
return row.IsNull("DeclaredType") ? null : (System.String) row["DeclaredType"];
else
return row.IsNull(row.Table.Columns["DeclaredType"], DataRowVersion.Original) ? null : (System.String) row["DeclaredType", DataRowVersion.Original];
//System.String
}
set
{
row["DeclaredType"] = value;
}
}
/// <summary>
/// Gets and Sets the Precision.
/// </summary>
/// <value>
/// The underlying rows Precision cell
/// </value>
public virtual System.Data.SqlTypes.SqlInt32 Precision
{
get
{
if (row.RowState != DataRowState.Deleted)
{
if (row.IsNull("Precision"))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["Precision"]);
}
else
{
if (row.IsNull(row.Table.Columns["Precision"], DataRowVersion.Original))
return System.Data.SqlTypes.SqlInt32.Null;
else
return new System.Data.SqlTypes.SqlInt32((System.Int32)row["Precision", DataRowVersion.Original]);
}
}
set
{
if ( value.IsNull )
row["Precision"] = DBNull.Value;
else
row["Precision"] = value.Value;
}
}
/// <summary>
/// Gets and Sets the parent ORMBiz.DataType.
/// </summary>
[System.ComponentModel.Bindable(false)]
public virtual ORMBiz.DataType DataType
{
get
{
if (row.GetParentRow(base.DataSet.Relations["FKDataTypeIDColumn"]) != null)
return new ORMBiz.DataType( DataContext, row.GetParentRow("FKDataTypeIDColumn"));
else
return null;
}
set
{
if ( value == null )
{
row.SetParentRow(null, base.DataSet.Relations["FKDataTypeIDColumn"] );
}
else
row.SetParentRow( value.row, base.DataSet.Relations["FKDataTypeIDColumn"] );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -