<%#REFERENCE System.dll,System.Windows.Forms.dll,CommonLib.dll,myEntity.dll%><%
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using CommonLib;
using CommonLib.DatabaseSchema;
using CommonLib.TemplateEngine;
using System.Windows.Forms;
using myEntity;
namespace ConsoleApplication1
{
public class TemplateProgram : MyTemplate
{
public static void Main(string[] args)
{
string strProjectFileName = Environment.GetEnvironmentVariable("ProjectFileName", EnvironmentVariableTarget.User);
DBSchemaEnv.PopulateDBSchemaEnvBasedOnProjectFile(strProjectFileName);
TemplateProgram templateProgram = new TemplateProgram();
Form1 frm = new Form1();
frm.strProjectFileName = strProjectFileName;
frm.Text = "Select table";
frm.ShowDialog();
TableInfo selectedTable = DBSchemaEnv.dbSchemas[frm.iDBInstance].tablesInfo[frm.iDBTable];
%>//*********************************************************
// xxx Company
// <%=DateTime.Now.ToString("yyyy-mm-dd")%> Author: <%=frm.strAuthorName%>
// The entity class of table <%=selectedTable.strTableName%>
//*********************************************************
using System;
using System.Collections.Generic;
namespace DataEntity
{
public class cls<%=selectedTable.strTableName%>
{
#region private members
<%
for (int i=0;i<selectedTable.columnsInfo.Count;i++)
{
ColumnInfo currentColumn = selectedTable.columnsInfo[i];
string strDeclareTypeName = ReturnBuiltInType(currentColumn.strColumnTypeName);
%> private <%=strDeclareTypeName%> <%=GetPrefixOfMembers(currentColumn)%><%=currentColumn.strColumnName%>;
<%
}
%> #endregion
#region Properties
<%
for (int i=0;i<selectedTable.columnsInfo.Count;i++)
{
ColumnInfo currentColumn = selectedTable.columnsInfo[i];
string strDeclareTypeName = ReturnBuiltInType(currentColumn.strColumnTypeName);
%> public <%=strDeclareTypeName%> <%=currentColumn.strColumnName.ToUpper()%>
{
get
{
return _<%=GetPrefixOfMembers(currentColumn)%><%=currentColumn.strColumnName%>;
}
set
{
<%=GetPrefixOfMembers(currentColumn)%><%=currentColumn.strColumnName%> = value;
}
}
<%
}
%> #endregion
}
}
<%
templateProgram.SaveOutputToFile(Application.StartupPath + """" + selectedTable.strTableName + ".cs");
MessageBox.Show("Hello");
}
public static string GetPrefixOfMembers(ColumnInfo oInputColumn)
{
string strResult = string.Empty;
if (oInputColumn.strColumnTypeName == "System.String")
{
strResult = "str";
}
else if (oInputColumn.strColumnTypeName == "System.Int32")
{
strResult = "i";
}
else if (oInputColumn.strColumnTypeName == "System.DateTime")
{
strResult = "date";
}
return strResult;
}
public static string ReturnBuiltInType(string strInput)
{
if (strInput == "System.String")
{
return "string";
}
else if (strInput == "System.Int32")
{
return "int";
}
return strInput;
}
}
}
%>