DNN Module Development Series (7)--coding with Codesmith templates

Source: Internet
Author: User
Tags dnn

Before using Codesmith templates for code writing, we should complete the design of the data table first. Because Codesmith templates generate the corresponding code based on the fields of the datasheet.

First, according to the DNN Module Development Series (1)--analysis design, the definition of the Mycompany_article article Information table is designed in the SQL Server database. Remember to design the primary foreign key, especially the association with the modules table.

Second, we can also write the stored procedures used by the program first. When writing a stored procedure, we can write a stored procedure using the STOREDPROCEDURES.CST template in Codesmith templates. But the code it writes seems to be different from the naming conventions I usually use, so I use some of the code it generates, such as the variable definition section. The function of this article module is relatively simple, is to add, edit, delete, view the article, and can enumerate all the articles of this module. So we can use 5 of the corresponding stored procedures to complete, they are:

Mycompany_article_add add

Mycompany_article_update Editor

Mycompany_article_delete Delete

Mycompany_article_get get an article

Mycompany_article_getbymodules get all the articles in the module

You can try writing these stored procedures first, and I'll give you all the code when this series is done. When writing, be aware that all database objects need to be preceded by "dbo.", in the name of stored procedures and tables, we should also follow the "company Name _ Module Name _ function name" principle, follow good naming rules not only the code looks more readable, And in the later we only make the database installation script can easily use the find replacement method to quickly generate the database installation script.

Using Codesmith templates for programming, of course we have to use the Codesmith code to generate a sharp weapon. You can get it http://www.codesmithtools.com/here. The process and simplicity of using Codesmith templates, first I double-click the template that needs to be used. Usually, I start with the Info class, double-click the VB BLL Info class.cst template. First we need to select Multisourcetable, choose the article Information table we have created mycompany_article, the following figure:

1, click the Multisourcetable Properties Pop-up Table Picker Selection window, select the table is located in the database, select the table. If there is no database, you can click Add.

2. Add Database connection

3, input objectqualifer (any loss, seems useless), click Generate Generate Code

4. Copy this code into the Articleinfo.vb file

Use VB dataprovider.cst to generate Dataprovider.vb file code. At build time we set Includelist to false and do not generate a method to get the entire list of articles. Copy the generated code to the appropriate location in Dataprovider.vb, replacing the "Mycompany_" prefix in the code.

We then use VB BLL Controller class.cst and VB sqldataprovider.cst to generate Articlecontroller.vb and Sqldataprovider.vb code, the same method as the previous one. When generating Sqldataprovider code, we also need to modify the corresponding stored procedure name because our naming rules are different from his.

Now that we've done most of the logical layer and data access layer code, there's only the code for the presentation layer. We modified each of the three controls Article.ascx, Articleedit.ascx, and Settings.ascx, adding some asp.net controls to complete the design requirements. Now it's the same as developing other asp.net programs, with no other tricks or difficulties. Just note in the writing of the DNN other modules of the code to see how they are all the structure, DNN Project templates also added a lot of code for us, we fill the remaining part of the entire module even if it is done.

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.