分享

BLL 业务逻辑层代码生成器

 悟静 2011-12-02

<%--
Name:
Author:
Description:
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="Text" Src="" Inherits="" Debug="False" Description="Template description here." %>
<%@ Property Name="SampleStringProperty" Type="System.String" Default="SomeValue" Optional="True" Category="Strings" Description="This is a sample string property." %>
<%@ Property Name="SampleBooleanProperty" Type="System.Boolean" Default="True" Optional="False" Category="Booleans" Description="This is a sample boolean property." %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="System.Data" %>
<%@ Property Name="nameSpace" Type="String" Default="Eatery" Optional="False" Category="" Description="" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<%@ Property Name="index" Type="System.int32" Default="0" Optional="False" Category="" Description="" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<%@ Property Name="db" Type="SchemaExplorer.DatabaseSchema" Default="" Optional="False" Category="Context" Description="???" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.IO" %>
using System;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Model;
using <%=nameSpace %>DAL;

namespace <%=nameSpace %>BLL
{
 public class <%=GetClassName() %>BLL
 {
  private <%=GetClassName() %>DAL <%=GetObjectName() %>DAL = new <%=GetClassName() %>DAL();
  
  public int Add(<%=GetClassName() %> <%=GetObjectName() %>)
        {
            return <%=GetObjectName() %>DAL.Add(<%=GetObjectName() %>);
        }
  
  public int AddReturn<%=StringUtil.ToPascalCase(db.Tables[index].Columns[0].Name) %>(<%=GetClassName() %> <%=GetObjectName() %>)
        {
            return <%=GetObjectName() %>DAL.AddReturn<%=StringUtil.ToPascalCase(db.Tables[index].Columns[0].Name) %>(<%=GetObjectName() %>);
        }
  
  public int Update(<%=GetClassName() %> <%=GetObjectName() %>)
  {
   return <%=GetObjectName() %>DAL.Update(<%=GetObjectName() %>);
  }
  
  public int Delete(int <%=StringUtil.ToCamelCase(GetPrimaryKey()) %>)
  {
   return <%=GetObjectName() %>DAL.Delete(<%=StringUtil.ToCamelCase(GetPrimaryKey()) %>);
  }
 
  public List<<%=GetClassName() %>> GetAll()
  {
   return <%=GetObjectName() %>DAL.GetAll();
  }
  
  public <%=GetClassName() %> GetSingle(int <%=StringUtil.ToCamelCase(GetPrimaryKey()) %>)
        {
            return <%=GetObjectName() %>DAL.GetSingle(<%=StringUtil.ToCamelCase(GetPrimaryKey()) %>);
  }
  
  public List<<%=GetClassName() %>> GetAllByConditions(string conditions)
  {
   return <%=GetObjectName() %>DAL.GetAllByConditions(conditions);
  }
 }
}
<script runat="template">
 public string GetClassName()
 {
  return StringUtil.ToPascalCase(db.Tables[index].Name);
 }
 public string GetObjectName()
 {
  return StringUtil.ToCamelCase(db.Tables[index].Name); 
 }
 public string GetPrimaryKey()
 {
  return db.Tables[index].Columns[0].Name ; 
 }
 public override void Render(TextWriter writer)
 {
  string path1 =OutputDirectory + GetClassName()  + "BLL.cs";
  System.Diagnostics.Trace.WriteLine(path1);
  StreamWriter fileWriter1 = new StreamWriter(path1,false);
  this.Response.AddTextWriter(fileWriter1);
  base.Render(writer);
  fileWriter1.Close();
 }
 private string _outputDirectory = String.Empty;

 [Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
 [Optional]
 [Category("Output")]
 [Description("The directory to output the results to.")]
 public string OutputDirectory
 {
  get
  {
    // default to the directory that the template is located in
    if (_outputDirectory.Length == 0) return this.CodeTemplateInfo.DirectoryName;
 
    return _outputDirectory;
  }
  set
  {
    if (!value.EndsWith("//")) value += "//";
    _outputDirectory = value;
  }
 }
</script>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多