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.