• 我的MyGeneration


    话不多说,直接上代码

    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");
        }
    }    
    %>
  • 相关阅读:
    linux 终端相关
    「CF10D」LCIS
    「SP1043」GSS1
    「NOI2009」二叉查找树
    「CF650E」Clockwork Bomb
    「UVA10559」Blocks
    「LuoguP3979」遥远的国度
    「SDOI2015」寻宝游戏
    「CF741D」Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
    「CF600E」Lomsat gelral
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/4378369.html
Copyright © 2020-2023  润新知