1. Add dynamic soft generation project
Add dynamics to the project according to the previous article
double click soft
After completing the new database server, you need to close and reopen
Choose simple three layers, pay attention to save location
Pay attention to switch databases:
Copy five folders to the project directory after generation
Note the directory structure:
Add four items to the original project:
Right-click the project-"Add-"Existing projects, add them to the project one by one:
2. Modify the project content
Add references (the main project is the project MangeSystem created by yourself, and other projects refer to it)
Modify the Web.config file configuration and add a database connection:
Modify the PubConstant in the "DBUtility" project to read the database connection field as a connection string
Also modify the GetConnectionString function
PS: A field can be understood as a member variable Get method of a class to read the content of the field, which is actually similar to a function.
3. Debugging test
After the above work is completed, you can do a simple test program (you can skip the following steps if you confirm that it is normal)
Test code (delete after testing)
F9 to add or delete a breakpoint (breakpoint means in debug mode, break here, and then you can execute step by step)
F10 If there is a function call in this line of code, do not enter the function call, and execute one step
F11 If there is a function call in this line of code, enter the function call and trace it to the calling function
F5 to enter debug mode
Debugging effect (add a few records to the bill table of the database for testing)
The above code:
First create a new BLL, a business logic object, to implement operations
Pay attention to the layer-by-layer call relationship of C# through the namespace: Maticsoft.BLL.bill (three layers)
Call the GetModelList function of BLL (this function is automatically generated by DynamicSoft, and it is a conditional query function) to obtain the records in the data table, where the parameter is an empty string to indicate that all records are taken out, and this parameter is the Where clause of SQL
The obtained records are stored in the List container, generic! The things stored are specified in <…>
List< Maticsoft.Model.bill> (three layers again, but here is Model)
The effect is as follows, the database records are read normally!
The above operations indicate that the normal access to the database can be completed.
4. Functions provided by DynamicSoft
The common functions provided by Dynamicsoft are:
1. Add (only the picture of BLL is cut, the specific implementation of DAL can be ignored, of course, you can also check it in the project)
2、 Update
3、Delete 与 DeleteList
4. GetModel checks the object according to the id
5. GetModelList returns the query set according to the conditions (multiple or empty record sets that meet the conditions)
Other functions can basically be ignored. The above 5 important functions are automatically generated for each table. More than 80% of the operations of adding, deleting, checking and modifying can be completed by them. The operation steps are as follows:
First, new a corresponding bll business logic object, for example: Maticsoft.BLL.user bll = new Maticsoft.BLL.bill();
Note that the class names corresponding to each table are different;
Then, use bll to implement corresponding operations, such as:
Maticsoft.Model.user mod = new Maticsoft.Model.user();
//填写新用户的信息
mod.userName = "test";
mod.password = "123456";
//利用BLL添加到数据表
bll.Add(mod);
The remaining 20% can also be realized by modifying the corresponding codes of BLL and DAL (below).