熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

教你如何寫codesmith模板(3)

2022-06-13   來源: .NET編程 

  BLL層

  <%@ CodeTemplate Language=C# TargetLanguage=Text Src= Inherits= Debug=False Description=Template description here %>

  <%@ Assembly Name=SchemaExplorer %>

  <%@ Assembly Name=SystemData %>

  <%@ Property Name=TargetTable Type=SchemaExplorerTableSchema Category=Context      Description=TargetTable that the object is based on %>

  <%@ Property Name=Author Type=SystemString Default=Xiao ChangJian  Category=Context  Description=The author for this procedure %>

  <%@ Property Name=NameSpace Type=SystemString Default=MySpace  Category=Context  Description=TargetTable that the object is based on %>

  <%@ Property Name=Description Type=SystemString Default= Category=Context Description=The description for this procedure%>

  <%@ Map Name=CSharpAlias Src=SystemCSharpAlias Description=System to C# Type Map %>

  <%@ Import Namespace=SchemaExplorer %>

  <%@ Import Namespace=SystemData %>

  /*

  * File Name: <%= GetTableName(TargetTable) %>Bllcs

  *

  * Create Author: <%= Author %>

  *

  * Create DateTime: <%=DateTimeNowToShortDateString() %>

  *

  * Description: <%= Description %>

  **/

  using System;

  using SystemCollections;

  using SystemCollectionsGeneric;

  using SystemText;

  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) %>DalClassInstanceInsert_<%= GetTableName(TargetTable) %>(instance);

  }

  /// <summary>

  /// Delete Record

  /// </summary>

  public int Delete_<%= GetTableName(TargetTable) %>(String pkid)

  {

  return <%= GetTableName(TargetTable) %>DalClassInstanceDelete_<%= GetTableName(TargetTable) %>(pkid);

  }

  /// <summary>

  /// Update Record

  /// </summary>

  public int Update_<%= GetTableName(TargetTable) %>(<%= GetTableName(TargetTable) %>Model instance)

  {

  return <%= GetTableName(TargetTable) %>DalClassInstanceUpdate_<%= GetTableName(TargetTable) %>(instance);

  }

  /// <summary>

  /// Get Record By Primary Key

  /// </summary>

  public <%= GetTableName(TargetTable) %>Model Get_<%= GetTableName(TargetTable) %>ByPKID(String pkid)

  {

  return <%= GetTableName(TargetTable) %>DalClassInstanceGet_<%= GetTableName(TargetTable) %>ByPKID(pkid);

  }

  /// <summary>

  /// Get Total Record Number

  /// </summary>

  public Int Get_<%= GetTableName(TargetTable) %>Count(String tablename String swhere)

  {

  return <%= GetTableName(TargetTable) %>DalClassInstanceGet_<%= GetTableName(TargetTable) %>Count(tablenameswhere);

  }

  /// <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) %>DalClassInstanceGet_<%= GetTableName(TargetTable) %>ByWhere(tablenamecolumnswheresorderordertypepagecurrentpagecount);

  }

  }

  }

  <script runat=template>

  //Get tablename

  public string GetTableName(TableSchema table)

  {

  if(table==null)

  {

  return null;

  }

  return tableName ;

  }

  </script>


From:http://tw.wingwit.com/Article/program/net/201311/11682.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.