教你如何写codesmith模板(3)
教你如何写codesmith模板(3)
BLL层
<%@ CodeTemplate Language= C# TargetLanguage= Text Src= Inherits= Debug= False Description= Template description here %>
<%@ Assembly Name= SchemaExplorer %>
<%@ Assembly Name= System Data %>
<%@ Property Name= TargetTable Type= SchemaExplorer TableSchema Category= Context Description= TargetTable that the object is based on %>
<%@ Property Name= Author Type= System String Default= Xiao ChangJian Category= Context Description= The author for this procedure %>
<%@ Property Name= NameSpace Type= System String Default= MySpace Category= Context Description= TargetTable that the object is based on %>
<%@ Property Name= Description Type= System String Default= Category= Context Description= The description for this procedure %>
<%@ Map Name= CSharpAlias Src= System CSharpAlias Description= System to C# Type Map %>
<%@ Import Namespace= SchemaExplorer %>
<%@ Import Namespace= System Data %>
/*
* File Name: <%= GetTableName(TargetTable) %>Bll cs
*
* Create Author: <%= Author %>
*
* Create DateTime: <%=DateTime Now ToShortDateString() %>
*
* Description: <%= Description %>
* */
using System;
using System Collections;
using System Collections Generic;
using System Text;
namespace <%= NameSpace %>
{

public class <%= GetTableName(TargetTable) %>Bll
{
private static readonly <%= GetTableName(TargetTable) %>Bll _classinstance = new <%= GetTableName(TargetTable) %>Bll();
public static <%= GetTableName(TargetTable) %>Bll ClassInstance {get{return _classinstance; }}
/// <summary>
/// Add Record
/// </summary>
public int Insert_<%= GetTableName(TargetTable) %>(<%= GetTableName(TargetTable) %>Model instance)
{
return <%= GetTableName(TargetTable) %>Dal ClassInstance Insert_<%= GetTableName(TargetTable) %>(instance);
}
/// <summary>
/// Delete Record
/// </summary>
public int Delete_<%= GetTableName(TargetTable) %>(String pkid)
{
return <%= GetTableName(TargetTable) %>Dal ClassInstance Delete_<%= GetTableName(TargetTable) %>(pkid);
}
/// <summary>
/// Update Record
/// </summary>
public int Update_<%= GetTableName(TargetTable) %>(<%= GetTableName(TargetTable) %>Model instance)
{
return <%= GetTableName(TargetTable) %>Dal ClassInstance Update_<%= GetTableName(TargetTable) %>(instance);
}
/// <summary>
/// Get Record By Primary Key
/// </summary>
public <%= GetTableName(TargetTable) %>Model Get_<%= GetTableName(TargetTable) %>ByPKID(String pkid)
{
return <%= GetTableName(TargetTable) %>Dal ClassInstance Get_<%= GetTableName(TargetTable) %>ByPKID(pkid);
}
/// <summary>
/// Get Total Record Number
/// </summary>
public Int Get_<%= GetTableName(TargetTable) %>Count(String tablename String swhere)
{
return <%= GetTableName(TargetTable) %>Dal ClassInstance Get_<%= GetTableName(TargetTable) %>Count(tablename swhere);
}
/// <summary>
/// Get Record With Split Page
/// </summary>
public List<<%= GetTableName(TargetTable) %>Model> Get_<%= GetTableName(TargetTable) %>ByWhere
(
String tablename
String column
String swhere
String sorder
String ordertype
Int pagecurrent
Int pagecount
)
{
return <%= GetTableName(TargetTable) %>Dal ClassInstance Get_<%= GetTableName(TargetTable) %>ByWhere(tablename column swhere sorder ordertype pagecurrent pagecount);
}
}
}
<script runat= template >
//Get tablename
public string GetTableName(TableSchema table)
{
if(table==null)
{
return null;
}
return table Name ;
}
lishixinzhi/Article/program/net/201311/11682