FINEUIMVC-based code generator (traditional three layer) v1.0-2

Source: Internet
Author: User


The first blog is just a rough explanation, in fact, this tool really use words may we have to look at, I today (overnight) to write an example, cut a few diagrams, do a custom template tutorial, because the code generation itself is a tool, animation effect is secondary, mainly the tool itself, The template that comes with it is not suitable for all development environments, so focus on template authoring and interfaces.

I'm going to write an MVC front-desk template that generates index.cshtml and Controller.cs as a table, so that's the two examples. When it comes to the template is a standard file, I would like to do a mistake as a template, and then generate their own files according to different tables, in fact, we are all programmers say this is nonsense, blog is longer, the description of the relatively fine, many, the most under the source of the environment, I first set up a fineui empty project Codefdemo generates a ASSET_A2 table with a build tool in the background layer three added to the project, generated, the table is an asset classification table the first step to do a template of the real page preparation work done, and then do a front page display, as a standard template file index.cshtml
@{viewbag.title = "Index"; var F = Html.f ();} @section Head {} @section Body {@ () F.panel (). Isviewport (True). Showborder (False). Showheader (False). Layout (layouttype.region). Items (//Intermediate Panel Query and List f.panel ()//. Isviewport (True). Boxflex (4). Layout (Layouttype.vbox). Bodypadding (0)//5. Boxconfigchildmargin ("0 0 0 0")//0 0 5 0. Showborder (False). Showheader (False). Items (//Query Form F.form (). ID ("Searchform"). Title ("Query Criteria"). Bodypadding (5). Boxconfigchildmargin ("0 5 0 5"). Boxflex (1). Layout (Layouttype.vbox). Boxconfigalign (Boxlayoutalign.stretch). Boxconfigposition (Boxlayoutposition.center). Enablecollapse (True). Labelwidth (100).          Rowsex (4, F.textbox ()               . ID ("Txtstr20"). Attribute ("Data", "sys_asset_a1_160"). Label ("category name"). Emptytext ("category name"), F.textbox (). ID ("Txtstr20"). Attribute ("Data", "sys_asset_a1_160"). Label ("category number"). Emptytext ("category number")),//List F.grid (). Title ("list"). ID ("Grid1"). Boxflex (6). Enablecheckboxselect (True). Dataidfield ("Asset_a2_autoid"). AllowPaging (True). Enableheadermenu (False). PageSize (15). Toolbars (F.toolbar ().                 Items (F.DEFAULTGRIDBTN ("Grid1"))) .   Columns (F.rownumberfield (),                      F.renderfield (). HeaderText ("ID"). Hidden (True). DataField ("Asset_a2_autoid"), F.renderfield (). HeaderText ("category name"). Expandunusedspace (True). DataField ("Asset_a2_10"), F.renderfield (). HeaderText ("classification number"). Expandunusedspace (True). DataField ("asset_a2_20"), F.renderfield (). HeaderText ("New Time"). Expandunusedspace (True). DataField ("Asset_a2_maketime")). DataSource (Viewbag.griddata)//. Listener ("Rowclick", "Ongrid1rowclick")))} @section script {<script> F.read Y (functioN () {})//list row Click event function Ongrid1rowclick (E, rowid) {f.dopostback (' @Url. Action ("grid1_        Rowclick ") ', {rowid:rowid, fields:f.ui.grid1.fields}); }//List new function Grid1new_click () {f.ui.grid1.showedit ();//new}//list modified to get list selected items ge        Tselectedrows Note Dataidfield Property function Grid1edit_click (G,rowid) {F.ui.grid1.showedit (true);//Modify        }//Remove remove this method Auto postback Grid1del_click method parameter for ID fields function Grid1delete_click (g,ids) {}//Refresh List            function Lodegrid () {f.dopostback (' @Url. Action ("Lodegrid") ', {Fields:f.ui.grid1.fields        }); }</script>}

Asset_a2controller.cs

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Codefdemo.bp;namespace codefdemo.controllers.sysapp{public    class Asset_a2controller:controller    {        // GET:SYSA1 public        ActionResult Index ()        {            bllasset_a2 BLL = new Bllasset_a2 ();            Viewbag.griddata = BLL. Getasset_a2msbyquery (New Message.msquery ()). ToArray ();            return View ();}}    }

OK, browse under (This example is only a list display)

The second step is to rewrite the standard file into a template file and then look at the code, where the grid's columns is the column loop, the query condition is also the column loop, the database table column A loop can be, so there are two templates
@{viewbag.title = "Index"; var F = Html.f ();} @section Head {} @section Body {@ () F.panel (). Isviewport (True). Showborder (False). Showheader (False). Layout (layouttype.region). Items (//Intermediate Panel Query and List f.panel ()//. Isviewport (True). Boxflex (4). Layout (Layouttype.vbox). Bodypadding (0)//5. Boxconfigchildmargin ("0 0 0 0")//0 0 5 0. Showborder (False). Showheader (False). Items (//Query Form F.form (). ID ("Searchform"). Title ("Query Criteria"). Bodypadding (5). Boxconfigchildmargin ("0 5 0 5"). Boxflex (1). Layout (Layouttype.vbox). Boxconfigalign (Boxlayoutalign.stretch). Boxconfigposition (Boxlayoutposition.center). Enablecollapse (True). Labelwidth (100).  Rowsex (4 $ $TextBoxForSearch $$               ),//List F.grid (). Title ("list"). ID ("Grid1"). Boxflex (6). Enablecheckboxselect (True). Dataidfield ("$ $KEY $$"). AllowPaging (True). Enableheadermenu (False). PageSize (15). Toolbars (F.toolbar ().                 Items (F.DEFAULTGRIDBTN ("Grid1"))) . Columns (F.rownumberfield (), F.renderfield (). HeaderText ("ID"). Hidden (True). DataField ("$ $KEY $$") $ $GridColumns $$). DataSource (Viewbag.griddata)//. Listener ("Rowclick", "Ongrid1rowclick")))} @section script {&LT;script> F.ready (function () {})//list line Click event function Ongrid1rowclick (E, rowid) {            F.dopostback (' @Url. Action ("Grid1_rowclick") ', {rowid:rowid, fields:f.ui.grid1.fields        }); }//List new function Grid1new_click () {f.ui.grid1.showedit ();//new}//list modified to get list selected items ge        Tselectedrows Note Dataidfield Property function Grid1edit_click (G,rowid) {F.ui.grid1.showedit (true);//Modify        }//Remove remove this method Auto postback Grid1del_click method parameter for ID fields function Grid1delete_click (g,ids) {}//Refresh List            function Lodegrid () {f.dopostback (' @Url. Action ("Lodegrid") ', {Fields:f.ui.grid1.fields        }); }</script>}
                    , F.textbox ()                         . ID ("txt$ $ColunName $$")                         . Attribute ("Data", "$ $ColunName $$")                         . Label ("$ $ColunNotes $$")                         . Emptytext ("$ $ColunNotes $$")

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using $$ namespace$$. Bp;namespace $ $namespace $$. controllers.sysapp{public    Class $ $tablename $ $Controller: Controller    {        //GET:SYSA1        Public ActionResult Index ()        {            bll$ $tablename $$ BLL = new bll$ $tablename $$ ();            Viewbag.griddata = BLL. get$ $tablename $ $MsByQuery (new Message.msquery ()). ToArray ();            return View ();}}    }

Where $ $namespace $$ $ $tablename $$ $ $KEY $$ $ $ColunName $$ $ $ColunNotes $$ are the system default dictionaries. Two more custom dictionaries $ $TextBoxForSearch $$ and $ $GridColumns $$, where $ $TextBoxForSearch $$ a separate template, in order to show you another way to read the interface implementation. Put the saved template in the template directory The third step is to write the template translation class new template extension class, reference CodeFactoryMVC.Main.dll, column implementation interface Icodefactory

Note Line 43rd:

Generate CodeFEx.dll, test to Bin folder, add interface on the Web

OK to complete, refresh the page to select the remaining tables, fill in the project name, click Create, copy to the original project, look for a table preview under

A list page is ready. Codefdemo project source will be placed in the Knowledge Planet to provide download, http://fineui.com/bbs/forum.php?mod=viewthread&tid=21482 not join the planet hurriedly join (more and more expensive!) )

FINEUIMVC-based code generator (traditional three layer) v1.0-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.