Click here to Skip to main content
15,884,986 members
Articles / Programming Languages / C#

Windows Workflow Foundation ASP.NET State Machine

Rate me:
Please Sign up or sign in to vote.
4.00/5 (17 votes)
12 May 2006CPOL5 min read 154.2K   1.5K   46  
Single Page State Machine workflow
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Workflow.Runtime.Hosting;
using System.Workflow;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using System.Workflow.Runtime;

public partial class _Default : System.Web.UI.Page 
{
    WorkflowRuntime wr;
    WorkflowInstance wi;
    JQD.LocalService locSvc;
    ManualWorkflowSchedulerService ms;
    JQD.IProcessing p = new JQD.TestProcessor();

    protected void Page_Load(object sender, EventArgs e)
    {
        wr = JQD.WorkflowHost.RuntimeWithServices;
        if (Session["wfi_id"] == null)
        {
            wi = wr.CreateWorkflow(typeof(RegMachineWorkflow.RegStateMachine));
            Session["wfi_id"] = wi.InstanceId;
            wi.Start();
        }
        else
        {
            wi = wr.CreateWorkflow(typeof(RegMachineWorkflow.RegStateMachine),null,(Guid) Session["wfi_id"]);
        }
        ms = wr.GetService<ManualWorkflowSchedulerService>();
        locSvc = wr.GetService<JQD.LocalService>();
        ms.RunWorkflow(wi.InstanceId);
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        // SnapShot activity cannot be inserted into "End" Container activity. So SnapShot data=null
        // All Error Out set nextPage="End"
        if (HttpContext.Current.Items["SnapShotData"] == null ||
            ((JQD.SnapShotData)HttpContext.Current.Items["SnapShotData"]).NextStage=="End"
            )
        {
            Session["wfi_id"] = null;
            IsRegTypeSelectionStep = true;
            DataBind();
            return;
        }
        string ns=((JQD.SnapShotData)HttpContext.Current.Items["SnapShotData"]).NextStage;
        IsRegTypeSelectionStep = (ns == "selectRegType");
        IsValidationStep = (ns == "submitValidationInfo");
        IsRegDataEntryStep = (ns == "submitRegInfo");
        DataBind();
       
    }


    public bool IsRegTypeSelectionStep;
    public bool IsValidationStep;
    public bool IsRegDataEntryStep;


    protected void CasualReg_Click(object sender, EventArgs e)
    {
        JQD.RegEventArgs e1 = new JQD.RegEventArgs(wi.InstanceId, "selectRegType");
        locSvc.RaiseEvent_CasualRegSelected(p, e1);
        ms.RunWorkflow(wi.InstanceId);
    }
    protected void SubmitRegInfo_Click(object sender, EventArgs e)
    {
        JQD.RegEventArgs e1 = new JQD.RegEventArgs(wi.InstanceId, "submitRegInfo");
        locSvc.RaiseEvent_RegInfoSubmitted(p, e1);
        ms.RunWorkflow(wi.InstanceId);
    }

    protected void ValidatingReg_Click(object sender, EventArgs e)
    {
        JQD.RegEventArgs e1 = new JQD.RegEventArgs(wi.InstanceId, "selectRegType");
        locSvc.RaiseEvent_ValidatingRegSelected(p, e1);
        ms.RunWorkflow(wi.InstanceId);
    }
    protected void AgentValidation_Click(object sender, EventArgs e)
    {
        JQD.RegEventArgs e1 = new JQD.RegEventArgs(wi.InstanceId, "submitValidationInfo");
        e1.AgentID = this.tbAgnetID.Text;
        locSvc.RaiseEvent_AgentInfoSubmitted(p, e1);
        ms.RunWorkflow(wi.InstanceId);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        JQD.RegEventArgs e1 = new JQD.RegEventArgs(wi.InstanceId, "submitValidationInfo");
        locSvc.RaiseEvent_OwnerInfoSubmitted(p, e1);
        ms.RunWorkflow(wi.InstanceId);
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
I am a Microsoft Certified Application Developer (MCAD), currently focusing on using .Net Framework to develop Business Solutions. I am mostly language neutral. I have used C, C++, ATL, MFC, VB.Net, C#, VB 6, PL/SQL, Transact SQL, ASP, Fortran, etc.

Comments and Discussions