Wf4.0 practice (8): implement a graphical data access layer

Source: Internet
Author: User

It is estimated that the three-tier architecture is stillProgramMembers are widely used. List the three layers first, not for fear that you do not know the three layers, but for the following requirements ,:).
1. Data access layer
2. Business logic layer
3. Presentation Layer
There is also the entity layer of data exchange
Many programmers useCodeGenerator. Generally, code generators help programmers generate data access layers and business logic layers. Because the presentation layer is ever-changing, it is difficult to generate it through a generator. When the fixed service layer cannot meet the requirements. You often need to manually modify the code.ArticleTeaches you how to customize the process-based business logic through a graphical interface without modifying your code.
Let's take a look at my data access layer:

Data access layer:

Business logic of the product to be ordered:

Entity layer:

Application Layer call:

1 Idictionary < String , Object > Input =   New Dictionary < String , Object >  
2 {
3 { " Request " , Listitem}
4 };
5
6 Workflowinvoker. Invoke ( New Yewuloji (), input );

The above shows an overview of my data access layer.

NOTE 1: In addition to the business logic of the product to be ordered, other products are generated from the code generator;

NOTE 2: All data table operations are sp.

The following describes how to implement it:

Data access layer:Take an add operation as an example. See:

This is Microsoft's new release of the ado.net operation in wf4.0. Here I use it to call the basic stored procedure that has been generated. A data-accessed XAML file corresponds to an SP in the database. The XAML file and the SP in the corresponding database are automatically generated by the generator.

Stored Procedure: automatically generated Stored Procedure

The data table structure in this example:

Order is the order table and item is the order item table. The business I want to develop is to order a batch of products. If the code is implemented, add a record to the order table in the data, add all order items to the item table. In this process, count the quantity and price of all items, and modify the itemcount and orderprice of the record in the newly added order table.

In my data access layer, there are two charts for you to choose from. The first figure is the activity of the Custom Data access layer, and the second figure is the built-in activity of wf4.0 For if, foreach, and other functions such as judgment, loop, and transaction.

By dragging the activity of the above two images, we can customize any complicated business logic, such.

Debugging and running:

DEMO code:

1 Iteminfo I1 =   New Iteminfo ();
2 I1.price =   18 ;
3 I1.productname =   " Mouse " ;
4 Iteminfo I2 =   New Iteminfo ();
5 I2.price =   32 ;
6 I2.productname =   " Keyboard " ;
7
8 Iteminfo I3 =   New Iteminfo ();
9 I3.price =   5 ;
10 I3.productname =   " Keyboard pad " ;
11
12
13 List < Iteminfo > Li =   New List < Iteminfo > ();
14 Li. Add (I1); Li. Add (I2); Li. Add (I3 );
15
16 Idictionary < String , Object > Input =   New Dictionary < String , Object >  
17 {
18 { " Itemlist " , Li}
19 };
20
21 Workflowinvoker. Invoke ( New Test2 (), input );

Result:

Advantages:

1. the business logic is Graphically displayed, which is very clear.

2. Strong scalability. common business processes can be stored in databases.

3. Easy maintenance if your business logic needs to be changed. The Service Logic XAML file can be taken out. Modify it in vs or the wf4.0 process designer of the host in windowsform or WPF. You do not need to modify or compile your code.

4. Less code. Because sp, data access layer, and general business logic are automatically generated. Only some complex and special business logic needs to be customized manually.

.......

Disadvantages:

Due to the concept of adding a workflow to the common layer-3 architecture, the efficiency may be compromised. I have not tested the number of such items.

Summary:This data access layer evolved from the data access layer I currently use. I have made all the previous Code flow. Change the. CS file to the. XAML file, but it is not complete yet.

Code:/files/zhuqil/workflowconsoleapplication12.rar

Database:/files/zhuqil/test.rar

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.