📄 database_user.atcs
字号:
<#--
User Database template.
--##>
<#@ Imports
using System;
using System.Text;
using TwoLKit.nTierBuilder.Api.DbDom;
##>
<#@ InstanceMembers
private IDatabase Database
{
get { return (IDatabase)Environment["Database"]; }
}
public override bool RewriteExistingFile
{
get { return false; }
}
public override string RelativeFilePath
{
get { return GetClassName() + ".vb"; }
}
private string GetClassName()
{
return Database.CodeName;
}
private string GetNamespace()
{
return SharedUtils.GetDbTierNamespace(Database);
}
private string GetTableClassName(ITable table)
{
return table.CodeName + (table.View ? "View" : "Table");
}
private string GetRowClassName(ITable table)
{
return table.CodeName + "Row";
}
private string QuoteSnippetString(string value, string indent)
{
int maxLength = 80 - indent.Length * 4;
StringBuilder dynStr = new StringBuilder(value.Length + 5);
dynStr.Append("\"");
for(int i = 0; i < value.Length; i++)
{
char ch = value[i];
if('"' == ch)
dynStr.Append("\"\"");
else
dynStr.Append(ch);
if(i > 0 && i % maxLength == 0)
{
dynStr.Append("\" + _\r\n");
dynStr.Append(indent);
dynStr.Append("\"");
}
}
dynStr.Append("\"");
return dynStr.ToString();
}
##>
' <fileinfo name="<#= RelativeFilePath #>">
' <copyright owner="<#= Environment["CopyrightOwner"] #>">
' All Rights Reserved.
' </copyright>
' <remarks>
' You can update this source code manually. If the file
' already exist it will not be rewrited by the generator.
' </remarks>
' <generator rewritefile="<#= RewriteExistingFile #>" infourl="http://www.2LKit.com">2LKit nTier Builder</generator>
' <created><#= DateTime.Now.ToString("f") #></created>
' </fileinfo>
Option Strict Off
Option Explicit On
Imports System
Imports System.Data
'' <summary>
'' Represents an open connection to a database.
'' </summary>
'' <remarks>
'' If the <#= GetClassName() #> goes out of scope, the connection to the DB
'' is not closed automatically. Therefore, you must explicitly close the
'' connection by calling Close or Dispose.
'' </remarks>
<# if(0 < Database.Tables.Count)
{ ##>
'' <example>
'' using(<#= GetClassName() #> db = new <#= GetClassName() #>())
'' {
'' <#= GetRowClassName(Database.Tables[0])#>[] rows = db.<#=
GetTableClassName(Database.Tables[0]) #>.GetAll();
'' }
'' </example>
<# } ##>
Public Class <#= GetClassName() #>
Inherits <#= GetClassName() #>_Base
'' <summary>
'' Initializes a new instance of the <#= GetClassName() #> class.
'' </summary>
Public Sub New()
MyBase.New()
' EMPTY
End Sub
'' <summary>
'' Creates a new connection to the database.
'' </summary>
'' <returns>An IDbConnection object.</returns>
Protected Overrides Function CreateConnection() As IDbConnection
#If SQL_CLIENT Then
Return new System.Data.SqlClient.SqlConnection("<#=
"INSERT MS SQL SERVER CONNECTION STRING" #>")
#ElseIf ORACLE_CLIENT Then
Return new System.Data.OracleClient.OracleConnection("<#=
"INSERT ORACLE CONNECTION STRING" #>")
#ElseIf ODBC Then
Return new Microsoft.Data.Odbc.OdbcConnection("<#=
"INSERT ODBC CONNECTION STRING" #>")
#Else
Return new System.Data.OleDb.OleDbConnection( _
<#= QuoteSnippetString(Database.Connection, " ") #>)
#End If
End Function
'' <summary>
'' Returns a data provider specific SQL statement parameter name. For example it
'' returns ? for OleDb provider, or @paramName for MS SQL provider.
'' </summary>
'' <param name="paramName">The data provider neutral SQL parameter name.</param>
Protected Friend Overrides Function CreateSqlParameterName(paramName As String) As String
#If SQL_CLIENT Then
Return "@" + paramName
#ElseIf ORACLE_CLIENT Then
Return ":" + paramName
#ElseIf ODBC Then
Return "?"
#Else
Return "?"
#End If
End Function
'' <summary>
'' Creates a .Net data provider specific name that is used by the
'' AddParameter method.
'' </summary>
'' <param name="baseParamName">The base name of the parameter.</param>
'' <returns>The full data provider specific parameter name.</returns>
Protected Overrides Function CreateCollectionParameterName(baseParamName As String) As String
#If ORACLE_CLIENT
Return baseParamName
#Else
Return "@" + baseParamName
#End If
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -