ERP code generator (open-source, source code download)

Source: Internet
Author: User

ERPCodeGenerator

The function of this Code Generator is to make up for the lack of code Smith in batch Table Generation.

Code generator running effect

The basic method is to select a database. The tree on the left will list all tables in the database. In the parameter area, the template will list the codesmith Template under the current directory and select a template, parameter lists the parameters of the selected template, and selects the generated code storage path as target folder.

Solution View

DownloadSource codeAddProgramSet Reference, including code Smith and SMO

SMO is a very efficient API for Operating SQL Server metadata to obtain SQL Server table information.

The program code has only two forms: the main form and the form connecting to the database. After the main program is started, the database connection form is automatically opened.

The opened database and all its tables are displayed in the main form.

Click the checkbox in front of the tree node to add the table to the table for generating template code. The middle column is a text box and can be edited.

Template lists all files ending with CST in the current directory. It does not verify whether the file is a codesmith template file.

Lsttemplate. Items. Clear ();

String [] files = directory. getfiles (appdomain. currentdomain. basedirectory, "*. CST ");

Lsttemplate. Items. addrange (files );

In the parameter field, use = to pair the parameter name and value.

For target folder, the default value of the current path is given when the form is started.

Txttargetfolder. Text = appdomain. currentdomain. basedirectory;

Call the code Smith template to generate the code

Codetemplatecompiler compiler = new codetemplatecompiler (templatefile );

Compiler. Compile ();

If (compiler. errors. Count = 0 ){

Codetemplate template = compiler. createinstance ();

Databaseschema database = new databaseschema (New sqlschemaprovider (), connectionstring );

Tableschema = database. Tables [tablename];

Template. Render (writer );

}

 

This is all about the code generator. The key content is the code Smith template.

There is also a small problem here, please refer to the figure

The distance between table node and its checkbox is too small and somewhat unsightly. We cannot find how to set parameters, which can increase the distance between the checkbox and node to keep it beautiful.

 

Go to http://epn.codeplex.com/to obtain the latest code and document.

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.