码迷,mamicode.com
首页 > 其他好文 > 详细

我的MyGeneration

时间:2015-03-30 18:28:10      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

话不多说,直接上代码

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");
    }
}    
%>

 

我的MyGeneration

标签:

原文地址:http://www.cnblogs.com/wpcnblog/p/4378369.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!