93 lines
3.7 KiB
Plaintext
93 lines
3.7 KiB
Plaintext
|
<%@ Template Language="C#" TargetLanguage="Text" %>
|
|||
|
<%-- 注册要生成的模板 --%>
|
|||
|
<%@ Register Name="basicImplements" Template="basicImplements.cst" MergeProperties="Flase" ExcludeProperties=""%>
|
|||
|
<%@ Register Name="basicObject" Template="basicObject.cst" MergeProperties="Flase" ExcludeProperties=""%>
|
|||
|
<%@ Register Name="extModelClass" Template="extModelClass.cst" MergeProperties="Flase" ExcludeProperties=""%>
|
|||
|
<%@ Register Name="extModelImpl" Template="extModelImpl.cst" MergeProperties="Flase" ExcludeProperties=""%>
|
|||
|
|
|||
|
<%--声明数据库的参数,在左下角的Database属性中,选择要操作的数据库名称--%>
|
|||
|
<%@ Property Category="Database" Name="SourceDatabase" Type="SchemaExplorer.DatabaseSchema" Optional="False" Description="Database the table enums will come from." %>
|
|||
|
<%--Type数据类型为TableSchema,表明参数Table是一个表对象。--%>
|
|||
|
<%--@ Property Name="SourceTable" Type="TableSchema" DeepLoad="True" Optional="False" Category="Table" Description="Table Name"--%>
|
|||
|
<%-- 执行输出文件的函数 --%>
|
|||
|
<% eachTable();%>
|
|||
|
|
|||
|
<%-- this.OutPutFile(); --%>
|
|||
|
<script runat="template">
|
|||
|
TableSchema SourceTable;
|
|||
|
|
|||
|
public string getClassName()
|
|||
|
{
|
|||
|
string tablename = this.SourceTable.Name.Substring(2);
|
|||
|
string firstChar = tablename.Substring(0,1);
|
|||
|
string className = firstChar.ToUpper() + tablename.Substring(1);
|
|||
|
return className ;
|
|||
|
//return this.SourceTable.Name.Substring(2);
|
|||
|
}
|
|||
|
|
|||
|
private void eachTable(){
|
|||
|
|
|||
|
foreach(TableSchema table in SourceDatabase.Tables){
|
|||
|
this.SourceTable = table;
|
|||
|
|
|||
|
|
|||
|
OutPutFile();
|
|||
|
Response.WriteLine("Hello, processed table " + this.SourceTable.Name + "!");
|
|||
|
}
|
|||
|
Response.WriteLine(" !!---- e n d --------------!! " );
|
|||
|
}
|
|||
|
|
|||
|
//输出文件
|
|||
|
private void OutPutFile()
|
|||
|
{
|
|||
|
//生成列举表名的模板
|
|||
|
CodeTemplate basicImplements =new basicImplements();
|
|||
|
//指定输出路径
|
|||
|
string filePath = OutputDirectory +"\\data\\basic\\"+ getClassName() + "_base_Imp" +".cs";
|
|||
|
//给子模板参数赋值
|
|||
|
basicImplements.SetProperty("SourceTable",this.SourceTable);
|
|||
|
basicImplements.RenderToFile(filePath,true);
|
|||
|
|
|||
|
//生成列表表字段的模板
|
|||
|
CodeTemplate basicObject =new basicObject();
|
|||
|
//指定输出路径
|
|||
|
filePath = OutputDirectory +"\\data\\basic\\"+ getClassName() + "_base" +".cs";
|
|||
|
//给子模板参数赋值
|
|||
|
basicObject.SetProperty("SourceTable",this.SourceTable);
|
|||
|
basicObject.RenderToFile(filePath,true);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
CodeTemplate extModelImpl =new extModelImpl();
|
|||
|
//指定输出路径
|
|||
|
filePath = OutputDirectory +"\\data\\"+ getClassName() + "_Imp" +".cs";
|
|||
|
//给子模板参数赋值
|
|||
|
extModelImpl.SetProperty("SourceTable",this.SourceTable);
|
|||
|
// extModelImpl.RenderToFile(filePath,false);//not overwrite
|
|||
|
|
|||
|
CodeTemplate extModelClass =new extModelClass();
|
|||
|
//指定输出路径
|
|||
|
filePath = OutputDirectory +"\\tables\\"+ getClassName() +".cs";
|
|||
|
//给子模板参数赋值
|
|||
|
extModelClass.SetProperty("SourceTable",this.SourceTable);
|
|||
|
extModelClass.RenderToFile(filePath,false);//not overwrite
|
|||
|
|
|||
|
}
|
|||
|
//解决方案输出路径
|
|||
|
private string Directory = String.Empty;
|
|||
|
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
|
|||
|
[Optional, NotChecked]
|
|||
|
[DefaultValue("")]
|
|||
|
public string OutputDirectory
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Directory;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value.EndsWith("\\")) value = value.Substring(0, value.Length -1);
|
|||
|
Directory = value;
|
|||
|
}
|
|||
|
}
|
|||
|
</script>
|