Step by step WF series (4)-simulated workflow Login

Source: Internet
Author: User

1. Summary

We have been familiar with the basic concepts of WF before, and I believe you are eager to try it. I want to enter the real WF development.

From the beginning of this article, we will first familiarize ourselves with the activities in WF.

2. Activities

The core of WF is a series of activities.

A workflow is a continuous and orderly system formed by combining multiple activities with a certain control module, which is customized and self-transferred based on business needs through the workflow engine.

With the two definitions above, we believe that we should all understand what an activity means to a workflow.

3. codeactivity

The code control is the control with the highest usage in WF. You can use the code control to complete a function.

A common function of the code control is to check the workflow status and change the local variables and information. In general, the codeCodeExternal resources, such as WebService, should not be called.

In codeactivity, executecode is the most important key event. This event occurs when the code is executed.

These functions will be gradually understood in the future instance explanation phase. Here is a simple example:

Then write the following code in the background:

Private voidHelloexecute (ObjectSender,EventargsE ){Console. Writeline ("Hello");}

We have already mentioned this before, so we will not continue here.

4. ifelseactivity

We mentioned in the first chapter that this activity is equivalent to the IF --- else in our language.

Conditional run is one of two or more activities of the ifelsebranchactivity type.

We will use instances to explain them slowly. Here, we will simulate a user login process.

First, let's prepare for a new winform to form a login interface:

Then we write the following two attributes in the workflow background code:

Private stringUsername;Private stringUserpassword;Public StringUsername {Set{Username =Value;}}Public StringUserpassword {Set{Userpassword =Value;}}

Next, we will drag and drop an ifelse control into the workflow.

Next, right-click ifelsebranchactivity1 to view an important attribute of ifelsebranchactivity1.

Ifelsebranchactivity1 is equivalent to a branch of if --- else. Therefore, we certainly need to specify its entry conditions.

Note the condition attribute. After expansion, we can see that:

In this way, let's select Add branch to add another if --- else clause:

Let's select declarative Rule Conditions for ifelsebranchactivity1:

And select ...., We will see this dialog box, and then select new:

Here, we first determine whether the user name and password are empty:

This. Username = "" | this. userpassword = "";

Then, we use the code conditions in ifelsebranchactivity2:

Then write the following code in the background:

 
Private voidValidate (ObjectSender,ConditionaleventargsE) {e. Result =This. Username. Equals ("Admin")&&This. Userpassword. Equals ("Admin");}

These are two conditions. First, judge whether the user name and password are empty. If not, then judge whether the user name and password are valid.

Then, we add three code controls to if-else:

The overall code is as follows:

Workflow2.cs:

 Public sealed partial class Workflow2 : Sequentialworkflowactivity { Private string Username; Private string Userpassword; Public String Username { Set {Username = Value ;}} Public String Userpassword { Set {Userpassword = Value ;}} Public Workflow2 () {initializecomponent ();}Private void Codeactivityappsexecutecode ( Object Sender, Eventargs E ){ MessageBox . Show ( "Username and password cannot be blank" );} Private void Validate ( Object Sender, Conditionaleventargs E) {e. Result = This . Username. Equals ( "Admin" )&& This . Userpassword. Equals ("Admin" );} Private void Codeactivity2_executecode ( Object Sender, Eventargs E ){ MessageBox . Show ( "Login successful" );} Private void Codeactivity3_executecode ( Object Sender, Eventargs E ){ MessageBox . Show ( "Incorrect user name and password" );}}

Winform background code:

Public partial class  Form1 : Form { Private  Workflowruntime Workflowruntime; Private  Workflowinstance Instance; Public Form1 () {initializecomponent (); workflowruntime = New  Workflowruntime (); Workflowruntime. startruntime ();} Private void Button#click ( Object Sender, Eventargs E ){ Dictionary < String , Object > DIC = New  Dictionary < String , Object > (); DIC. Add ( "Username" , This . Textbox1.text); DIC. Add ( "Userpassword" , This . Textbox2.text); instance = workflowruntime. createworkflow ( Typeof ( Workflow2 ), DIC); instance. Start ();}}

In this way, we have completed a login process:

Of course, this is just a simple login simulation. As for the database connection judgment, the truth is the same. You can go back and try a normal login interface to connect to the database.

5. Summary

In this article, we mainly learned how to use the code control and ifelse control, and used these two controls to create a simple login interface.

I also hope that you can tap the code again to make your impression better.

You are welcome to continue your attention. Let's learn WF step by step!

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.