[C#]一步一步開發自己的自動代碼產生工具之六:業務層模板

來源:互聯網
上載者:User

3。BLL模板

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using <xsl:value-of select="TabelModel/NameSpacePri"/>Model;
using <xsl:value-of select="TabelModel/NameSpacePri"/>DAL;
namespace <xsl:value-of select="TabelModel/NameSpacePri"/>BLL
{
 public partial class <xsl:value-of select="TabelModel/ModelName"/>BLL
 {
  #region 屬性/建構函式
  
  /// <summary>
  /// 資料鏈路訪問對象
  /// </summary>
  private <xsl:value-of select="TabelModel/ModelName"/>DAL DAL = null;
  /// <summary>
  /// 預設建構函式
  ///</summary>
  public <xsl:value-of select="TabelModel/ModelName"/>BLL()
  {
   DAL = new <xsl:value-of select="TabelModel/ModelName"/>DAL();
  }
  
  #endregion
  
  #region 資料檢測
  <xsl:if test="TabelModel/HasPK = 'true'">
  /// <summary>
  /// 是否存在指定主鍵的資料
  ///</summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true']">
  /// <param><xsl:attribute name="name"><xsl:value-of select="VarName"/></xsl:attribute>指定<xsl:value-of select="VarName"/></param>
  </xsl:for-each> 
  /// <returns>True/False</returns>
  public bool ExistsWithPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.ExistsWithPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  <xsl:if test="TabelModel/HasLogicKey = 'true'">
  /// <summary>
  /// 是否存在指定邏輯主鍵的資料
  ///</summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true']">
  /// <param><xsl:attribute name="name"><xsl:value-of select="VarName"/></xsl:attribute>指定<xsl:value-of select="VarName"/></param>
  </xsl:for-each> 
  /// <returns>True/False</returns>
  public bool ExistsWithLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.ExistsWithLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  /// <summary>
  /// 是否存在滿足指定條件的資料
  ///</summary>
  /// <param name="strWhere">條件(不包含“Where”關鍵字)</param>
  /// <returns>True/False</returns>
  public bool ExistsWithParam(string strWhere)
  {
   return DAL.ExistsWithParam(strWhere);
  }
  #endregion
  #region 資料檢索
  
  <xsl:if test="TabelModel/HasPK = 'true'">
  /// <summary>
  /// 根據主鍵檢索資料實體
  /// </summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true']">
  /// <param>
   <xsl:attribute name="name">
    <xsl:value-of select="VarName"/>
   </xsl:attribute>
   <xsl:value-of select="VarName"/>
  </param>
  </xsl:for-each>
  /// <returns>檢索結果</returns>
  public <xsl:value-of select="TabelModel/ModelName"/>Model Get<xsl:value-of select="TabelModel/ModelName"/>ByPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.Get<xsl:value-of select="TabelModel/ModelName"/>ByPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  <xsl:if test="TabelModel/HasLogicKey = 'true'">
  /// <summary>
  /// 根據邏輯主鍵檢索資料實體
  /// </summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true']">
  /// <param>
   <xsl:attribute name="name">
    <xsl:value-of select="VarName"/>
   </xsl:attribute>
   <xsl:value-of select="VarName"/>
  </param>
  </xsl:for-each>
  /// <returns>檢索結果</returns>
  public <xsl:value-of select="TabelModel/ModelName"/>Model Get<xsl:value-of select="TabelModel/ModelName"/>ByLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.Get<xsl:value-of select="TabelModel/ModelName"/>ByLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  /// <summary>
  /// 根據條件檢索資料實體
  /// </summary>
  /// <param name="strWhere">條件</param>
  /// <returns>檢索結果</returns>
  public <xsl:value-of select="TabelModel/ModelName"/>Model Get<xsl:value-of select="TabelModel/ModelName"/>ByParam(string strWhere)
  {
   return DAL.Get<xsl:value-of select="TabelModel/ModelName"/>ByParam(strWhere);
  }
  
  <xsl:if test="TabelModel/HasPK = 'true'">
  /// <summary>
  /// 根據主鍵檢索資料(DataRow)
  /// </summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true']">
  /// <param>
    <xsl:attribute name="name">
     <xsl:value-of select="VarName"/>
    </xsl:attribute>
    <xsl:value-of select="VarName"/>
   </param>
  </xsl:for-each>
  /// <returns>檢索結果</returns>
  public DataRow GetRowByPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.GetRowByPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  <xsl:if test="TabelModel/HasLogicKey = 'true'">
  /// <summary>
  /// 根據邏輯主鍵檢索資料(DataRow)
  /// </summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true']">
  /// <param>
    <xsl:attribute name="name">
     <xsl:value-of select="VarName"/>
    </xsl:attribute>
    <xsl:value-of select="VarName"/>
   </param>
  </xsl:for-each>
  /// <returns>檢索結果</returns>
  public DataRow GetRowByLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.GetRowByLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  /// <summary>
  /// 根據條件檢索資料(DataRow)
  /// </summary>
  /// <param name="strWhere">條件</param>
  /// <returns>檢索結果</returns>
  public DataRow GetRowByParam(string strWhere)
  {
   return DAL.GetRowByParam(strWhere);
  }
  /// <summary>
  /// 擷取所有資料實體列表
  /// </summary>
  /// <returns>檢索結果</returns>
  public List<xsl:text disable-output-escaping="yes">&lt;</xsl:text><xsl:value-of select="TabelModel/ModelName"/>Model<xsl:text disable-output-escaping="yes">&gt;</xsl:text> Get<xsl:value-of select="TabelModel/ModelName"/>List()
  {
   return DAL.Get<xsl:value-of select="TabelModel/ModelName"/>List();
  }
  /// <summary>
  /// 根據條件檢索資料實體列表
  /// </summary>
  /// <param name="strWhere">條件</param>
  /// <returns>檢索結果</returns>
  public List<xsl:text disable-output-escaping="yes">&lt;</xsl:text><xsl:value-of select="TabelModel/ModelName"/>Model<xsl:text disable-output-escaping="yes">&gt;</xsl:text> Get<xsl:value-of select="TabelModel/ModelName"/>ListByParam(string strWhere)
  {
   return DAL.Get<xsl:value-of select="TabelModel/ModelName"/>ListByParam(strWhere);
  }
  /// <summary>
  /// 擷取所有資料列表(DataTable)
  /// </summary>
  /// <returns>檢索結果</returns>
  public DataTable GetTable()
  {
   return DAL.GetTableByParam(String.Empty);
  }
  /// <summary>
  /// 根據條件擷取資料列表(DataTable)
  /// </summary>
  /// <param name="strWhere">條件</param>
  /// <returns>檢索結果</returns>
  public DataTable GetTableByParam(string strWhere)
  {
   return DAL.GetTableByParam(strWhere);
  }
  #endregion
  <xsl:if test="TabelModel/IsView = 'false'">
  #region 資料增/刪/改
  /// <summary>
  /// 新增
  ///</summary>
  /// <param name="model">資料實體</param>
  /// <returns></returns>
  public int Add<xsl:value-of select="TabelModel/ModelName"/>(<xsl:value-of select="TabelModel/ModelName"/>Model model)
  {
   return DAL.Add<xsl:value-of select="TabelModel/ModelName"/>(model);
  }
  <xsl:if test="TabelModel/HasPK = 'true'">
  /// <summary>
  /// 編輯
  /// </summary>
  /// <param name="model">資料實體</param>
  /// <returns></returns>
  public int Update<xsl:value-of select="TabelModel/ModelName"/>(<xsl:value-of select="TabelModel/ModelName"/>Model model)
  {
   return DAL.Update<xsl:value-of select="TabelModel/ModelName"/>(model);
  }

  /// <summary>
  /// 刪除資料實體
  /// </summary>
  /// <param name="model">資料實體</param>
  /// <returns></returns>
  public int Delete<xsl:value-of select="TabelModel/ModelName"/>(<xsl:value-of select="TabelModel/ModelName"/>Model model)
  {
   return DAL.Delete<xsl:value-of select="TabelModel/ModelName"/>(model);
  }

  /// <summary>
  /// 根據主鍵刪除
  /// </summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true']">
  /// <param>
    <xsl:attribute name="name">
     <xsl:value-of select="VarName"/>
    </xsl:attribute>
    <xsl:value-of select="VarName"/>
   </param>
  </xsl:for-each>
  /// <returns></returns>
  public int DeleteWithPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.DeleteWithPK(<xsl:value-of select="TabelModel/Fields/FieldModel[IsPK = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsPK = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  <xsl:if test="TabelModel/HasLogicKey = 'true'">
  /// <summary>
  /// 編輯(根據邏輯主鍵)
  /// </summary>
  /// <param name="model">資料實體</param>
  /// <returns></returns>
  public int Update<xsl:value-of select="TabelModel/ModelName"/>WithLogicKey(<xsl:value-of select="TabelModel/ModelName"/>Model model)
  {
   return DAL.Update<xsl:value-of select="TabelModel/ModelName"/>WithLogicKey(model);
  }

  /// <summary>
  /// 刪除資料實體(根據邏輯主鍵)
  /// </summary>
  /// <param name="model">資料實體</param>
  /// <returns></returns>
  public int Delete<xsl:value-of select="TabelModel/ModelName"/>WithLogicKey(<xsl:value-of select="TabelModel/ModelName"/>Model model)
  {
   return DAL.Delete<xsl:value-of select="TabelModel/ModelName"/>WithLogicKey(model);
  }

  /// <summary>
  /// 根據邏輯主鍵刪除
  /// </summary>
  <xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true']">
  /// <param>
    <xsl:attribute name="name">
     <xsl:value-of select="VarName"/>
    </xsl:attribute>
    <xsl:value-of select="VarName"/>
   </param>
  </xsl:for-each>
  /// <returns></returns>
  public int DeleteWithLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarType"/><xsl:text> </xsl:text><xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarType"/><xsl:text> </xsl:text><xsl:value-of select="VarName"/></xsl:for-each>)
  {
   return DAL.DeleteWithLogicKey(<xsl:value-of select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][1]/VarName"/><xsl:for-each select="TabelModel/Fields/FieldModel[IsLogicKey = 'true'][position()>1]">, <xsl:value-of select="VarName"/></xsl:for-each>);
  }
  </xsl:if>
  
  /// <summary>
  /// 根據條件刪除
  /// </summary>
  /// <param name="strWhere">條件</param>
  /// <returns>刪除條數</returns>
  public int DeleteByParam(string strWhere)
  {
   return DAL.DeleteByParam(strWhere);
  }
  
  #endregion
  </xsl:if>
 }
}
 </xsl:template>
</xsl:stylesheet>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.