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"><</xsl:text><xsl:value-of select="TabelModel/ModelName"/>Model<xsl:text disable-output-escaping="yes">></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"><</xsl:text><xsl:value-of select="TabelModel/ModelName"/>Model<xsl:text disable-output-escaping="yes">></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>