读书人

CodeSmith模板(业务逻辑种)

发布时间: 2012-09-21 15:47:26 作者: rapoo

CodeSmith模板(业务逻辑类)

<%@ CodeTemplate Language="C#" TargetLanguage="C#" Src="ToolsCodeTemplate.cs" Inherits="ToolsCodeTemplate" ResponseEncoding="UTF-8"%>
<%@ Property Name="TargetTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="TargetTable that the object is based on." %>

<%@ Property Name="ModelNamespace" Default="CX.Model" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %>
<%@ Property Name="DALNamespace" Default="CX.DAL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %>
<%@ Property Name="BLLNamespace" Default="CX.BLL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %>

<%@ Property Name="BLLClassNameSurfix" Default="Manager" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %>
<%@ Property Name="DALClassNameSurfix" Default="Service" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %>

<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
using System;
using System.Collections.Generic;
using System.Text;
using <%= DALNamespace %>;
using <%= ModelNamespace %>;

namespace <%= BLLNamespace %>
{

public partial class <%= GetBLLClassName() %>
{
private <%= GetDALClassName() %> <%= MakeCamel(GetDALClassName()) %>=new <%= GetDALClassName() %>();

public bool Add<%= GetModelClassName() %>(<%= GetModelClassNameWithInfo() %> <%= GetModelParamName() %>)
{
return <%= MakeCamel(GetDALClassName()) %>.Add<%= GetModelClassName() %>(<%= GetModelParamName() %>);
}

public bool Delete<%= GetModelClassName() %>By<%= GetPKName() %>(<%= GetPKPropertyType() %> <%= GetPKParamName() %>)
{
return <%= MakeCamel(GetDALClassName()) %>.Delete<%= GetModelClassName() %>By<%= GetPKName() %>(<%= GetPKParamName() %>);
}

public bool Update<%= GetModelClassName() %>(<%= GetModelClassNameWithInfo() %> <%= GetModelParamName() %>)
{
return <%= MakeCamel(GetDALClassName()) %>.Update<%= GetModelClassName() %>(<%= GetModelParamName() %>);
}

public List<<%= GetModelClassNameWithInfo() %>> GetAll<%= GetModelClassName() %>()
{
return <%= MakeCamel(GetDALClassName()) %>.GetAll<%= GetModelClassName() %>();
}

public <%= GetModelClassNameWithInfo() %> Get<%= GetModelClassName() %>By<%= GetPKName() %>(<%= GetPKPropertyType() %> <%= GetPKParamName() %>)
{
return <%= MakeCamel(GetDALClassName()) %>.Get<%= GetModelClassName() %>By<%= GetPKName() %>(<%= GetPKParamName() %>);
}
public int GetTotalCount()
{
return <%= MakeCamel(GetDALClassName()) %>.GetTotalCount();
}

public List<<%= GetModelClassNameWithInfo() %>> Get<%= GetModelClassName() %>ByPage(int minrownum,int maxrownum)
{
return <%= MakeCamel(GetDALClassName()) %>.Get<%= GetModelClassName() %>ByPage(minrownum,maxrownum);
}


}
}
<script runat="template">

public string GetBLLClassName()
{
return GetModelClassName() + BLLClassNameSurfix;
}

public string GetDALClassName()
{
return GetModelClassName() + DALClassNameSurfix;
}


public string GetModelParamName()
{
return MakeCamel(GetModelClassName());
}

public string GetModelClassName()
{
return GetModelClassName(TargetTable);
}

public string GetModelClassNameWithInfo()
{
return GetModelClassName(TargetTable)+"Info";
}

//获取属性类型 int
public string GetPKPropertyType()
{
return GetPKType(TargetTable);
}

//首字母小写
public string GetPKParamName()
{
return MakeCamel(GetPKName());
}

//首字母大写
public string GetPKName()
{
return MakePascal(GetPKName(TargetTable));
}

</script>

读书人网 >编程

热点推荐