标签:
话不多说,直接上代码
Interface Code:
public class GeneratedGui : DotNetScriptGui { public GeneratedGui(ZeusContext context) : base(context) {} //----------------------------------------- // The User Interface Entry Point //----------------------------------------- public override void Setup() { // ** UNCOMMENT CODE BELOW TO SEE UI ** ui.Width = 500; ui.Height = 200; GuiLabel lblDemo = ui.AddLabel("lblDemo", "Demo", "Demo Tooltip"); GuiComboBox cbDb = ui.AddComboBox("cbDb","select the Database"); cbDb.BindData(MyMeta.Databases); ui.ShowGui = true; } }
Template Code:
<% public class GeneratedTemplate : DotNetScriptTemplate { public GeneratedTemplate(ZeusContext context) : base(context) {} //--------------------------------------------------- // Render() is where you want to write your logic //--------------------------------------------------- public override void Render() { IDatabase db = MyMeta.Databases[input["cbDb"].ToString()]; foreach(ITable tb in db.Tables) { OutModel(tb); } } public string Dtype(string dbType) { string dt = ""; switch(dbType) { case "int": dt = "int"; break; case "decimal": dt = "decimal"; break; case "datetime": dt = "DateTime"; break; case "float": dt = "decimal"; break; default: dt = "string"; break; } return dt; } public void OutModel(ITable tb) { output.clear(); output.writeln("using System;"); output.writeln("using System.Collections.Generic;"); output.writeln("using System.Linq;"); output.writeln("using System.Text;"); output.writeln(""); output.writeln("namespace Models.Entity"); output.writeln("{"); output.writeln(" public class " + tb.Name); output.writeln(" {"); output.writeln(" public " + tb.Name + "()"); output.writeln(" {"); output.writeln(" "); output.writeln(" }"); output.writeln(""); foreach(IColumn c in tb.Columns) { output.writeln(" private " + Dtype(c.DataTypeName) + " _" + c.Name + ";"); output.writeln(""); output.writeln(" /// <summary>"); output.writeln(" /// " + c.Description + "(" + c.DataTypeName + ")"); output.writeln(" /// </summary>"); output.writeln(" public " + Dtype(c.DataTypeName) + " " + c.Name); output.writeln(" {"); output.writeln(" get { return _" + c.Name + "; }"); output.writeln(" get { _" + c.Name + " = value; }"); output.writeln(" }"); output.writeln(""); } output.writeln(" }"); output.writeln("}"); output.save("D:\\testModel\\"+tb.Name+".cs","o"); } } %>
标签:
原文地址:http://www.cnblogs.com/wpcnblog/p/4378369.html