Asp.net工做流workflow實戰之工做流啓動與繼續(三)

工做流幫助類:sql

 //讓工做流繼續沿着書籤的位置向下執行
value是向書籤傳遞參數 wfc.ResumeBookmark(bookmarkName,value);

//把傳過來的數據value做爲輸出參數outResult的值 傳到書籤外面其實執行這個函數  
private void MyCallback(NativeActivityContext context, Bookmark bookmark, object value)
{數據庫

}ide


namespace EazyBPMS.WorkFlow
{
   public class WorkFlowApplicationHelper
    {
        //建立工做流
        public static WorkflowApplication CreateWorkflowApp(Activity activity,string instanceId, Dictionary<string, object> dictionary)
        {
             //每次點擊的時候都會建立新的工做流實例
            WorkflowApplication wfc = new WorkflowApplication(activity, dictionary);
            //WorkflowInvoker.Invoke(new DemoActivity());
            wfc.Idle += a =>//監控,當工做流停下來的時候執行
              {
                  Console.WriteLine("工做流停下來了....");
              };
            //當工做流停頓下來了,進行什麼操做,若是返回的是unload  就卸載當前工做流實例  持久化到數據庫中
               wfc.PersistableIdle = delegate (WorkflowApplicationIdleEventArgs e2)
                {
                    Console.WriteLine("工做流被卸載了,進行持久化");
                    return PersistableIdleAction.Unload;
                };
            //監聽卸載事件
            wfc.Unloaded += a =>
              {
                  Console.WriteLine("工做流被卸載了");
              };
            //當出現了未處理的異常的時候
            wfc.OnUnhandledException += a =>
              {
                  return UnhandledExceptionAction.Terminate;//當出現異常的時候直接結束工做流

              };
            wfc.Aborted += a =>
              {
                  Console.WriteLine("工做流終止了");
              };
            //建立一個保存工做流實例的sqlstore對象
            SqlWorkflowInstanceStore store =
    new SqlWorkflowInstanceStore(DbHelperSQL.connectionString);

            //當前工做實例持久化的時候保存到數據庫中
            wfc.InstanceStore = store;
            // wfApp.Id;//工做流實例id須要將此實例id保存到實例數據庫中
            EazyBPMS.BLL.eazy_wf_instance bll = new BLL.eazy_wf_instance();
           EazyBPMS.Model.eazy_wf_instance model = bll.GetModel(Convert.ToInt32(instanceId));
            model.WFApplicationId = wfc.Id;
            bll.Update(model);
            wfc.Run();
            return wfc;
        }

        //繼續往下執行工做流
        public static WorkflowApplication ResumeBookMark(Activity activity,Guid InstanceId,string bookmarkName, BaseResumeBookMarkValue value)
        {
            //每次點擊的時候都會建立新的工做流實例
            WorkflowApplication wfc = new WorkflowApplication(activity);
            //WorkflowInvoker.Invoke(new DemoActivity());
            wfc.Idle += a =>//監控,當工做流停下來的時候執行
              {
                  Console.WriteLine("工做流停下來了....");
              };
            //當工做流停頓下來了,進行什麼操做,若是返回的是unload  就卸載當前工做流實例  持久化到數據庫中
               wfc.PersistableIdle = delegate (WorkflowApplicationIdleEventArgs e3)
                {
                    Console.WriteLine("工做流被卸載了,進行持久化");
                    return PersistableIdleAction.Unload;
                };
            //監聽卸載事件
            wfc.Unloaded += a =>
              {
                  Console.WriteLine("工做流被卸載了");
              };
            //當出現了未處理的異常的時候
            wfc.OnUnhandledException += a =>
              {
                  return UnhandledExceptionAction.Terminate;//當出現異常的時候直接結束工做流

              };
            wfc.Aborted += a =>
              {
                  Console.WriteLine("工做流終止了");
              };
            //建立一個保存工做流實例的sqlstore對象
            SqlWorkflowInstanceStore store =
    new SqlWorkflowInstanceStore(DbHelperSQL.connectionString);

            //當前工做實例持久化的時候保存到數據庫中
            wfc.InstanceStore = store;
            wfc.Load(InstanceId);
            //從數據庫中加載工做流狀態
            //讓工做流繼續沿着書籤的位置向下執行
            wfc.ResumeBookmark(bookmarkName,value);
            return wfc;
        }
    }
}
View Code

工做流啓動:函數

 protected void btnstart_Click(object sender, EventArgs e)
        {
            try
            {
                int i = 0;
            EazyBPMS.Web.UI.ManagePage bllmanage = new UI.ManagePage();
            Model.manager currentusermodel = bllmanage.GetAdminInfo();
            txttest.Text = currentusermodel.real_name;
            int currentUserId = currentusermodel.id;

            //一、將本頁面的表單數據提交到表單實例表中(包括附件等等)
            eazy_wf_instance bll = new eazy_wf_instance();
            EazyBPMS.Model.eazy_wf_instance model = new EazyBPMS.Model.eazy_wf_instance();
            model.InstName = txtInstanceName.Text;
            model.InstanceForm = txtInstanceForm.InnerText;
            model.Remark = txtRemark.Text;
            model.SubBy = currentUserId;
            model.Status = (short)EazyEnums.WFInstanceStatusEnum.Running;
            model.WFApplicationId = Guid.Empty;
            model.WF_TempID = this.id;
            int instanceid= bll.Add(model);
            if (instanceid > 0)
            {
                i += 1;
            }

          
            //三、在步驟表中添加2個步驟:第一個爲當前已經完成的步驟,第二個爲下一步誰審批的步驟

            EazyBPMS.BLL.eazy_wf_step stepBLL = new eazy_wf_step();
            //第一個步驟  一個當前已經處理的完成步驟。
           
            EazyBPMS.Model.eazy_wf_step startStep = new Model.eazy_wf_step();
            startStep.WF_Instance = instanceid;
            startStep.Checktime = DateTime.Now;
            startStep.Comment = "任務表單提交";
            startStep.DelFlag = del;
            startStep.IsEndStep = false;
            startStep.IsStartStep = true;
            startStep.ProcessBy = currentUserId;
            startStep.Remark = "朕對本身沒意見,沒備註。";
            startStep.Result = "經過";
            startStep.SubTime = DateTime.Now;
            startStep.StepName = "任務表單提交";
            //此步驟爲開始步驟狀態爲已經完成
            startStep.Status = (short)EazyEnums.WFStepStatusEnum.End;
           int a= stepBLL.Add(startStep);
            if (a > 0)
            {
                i += 1;
            }

            //第二個步驟:下一步誰審批的步驟。

            EazyBPMS.Model.eazy_wf_step nextStep = new Model.eazy_wf_step();
            nextStep.WF_Instance = instanceid;
            nextStep.Checktime = DateTime.Now;
            nextStep.Comment = "";
            nextStep.DelFlag = del;
            nextStep.IsEndStep = false;
            nextStep.IsStartStep = false;
            nextStep.ProcessBy = Convert.ToInt32(this.txtrenyuan.Text);
            nextStep.Remark = "";
            nextStep.Result = "";         
            //此步驟爲開始步驟狀態爲已經完成
            nextStep.Status = (short)EazyEnums.WFStepStatusEnum.Running;
          int b=stepBLL.Add(nextStep);
                if (b > 0)
                {
                    i += 1;

                }





                if (i == 3)
                {
                    //二、啓動工做流實例
                    var wfApp = WorkFlowApplicationHelper.CreateWorkflowApp(new Finance_Activity(), instanceid.ToString(), new Dictionary<string, object> { { "TempBookMarkName", "項目經理審批chao" } });
                  
                    JscriptMsg("添加任務成功!", "mywork.aspx");
                }
                else
                {
                    JscriptMsg("添加任務失敗!", "mywork.aspx");
                }
            }
            catch (Exception ex)
            {

                JscriptMsg(ex.ToString(), "mywork.aspx");
            }
            
        }

工做流繼續:ui

  protected void btnstart_Click(object sender, EventArgs e)
        {
            //EazyBPMS.Model.manager_role role = new Model.manager_role();
            //EazyBPMS.BLL.manager_role rolebll = new BLL.manager_role();

            if (isplay)
            {

                if (this.txtbumen.Text != "4")
                {
                    IsPass = true;
                }
                else
                {
                    IsPass = false;

                }

            }
            else
            {
                IsPass = true;

            }



                //經過
                //首先更新當前步驟


                EazyBPMS.BLL.eazy_wf_step stepBLL = new EazyBPMS.BLL.eazy_wf_step();
            //第一個步驟  一個當前已經處理的完成步驟。

            EazyBPMS.Model.eazy_wf_step currentStep = stepBLL.GetModel(this.StepId);
            //currentStep.WF_Instance = instanceid;
            currentStep.Checktime = DateTime.Now;
            currentStep.Comment = "提交審批表單";
            currentStep.DelFlag = del;
            // currentStep.IsEndStep = false;
            currentStep.IsStartStep = false;
            //currentStep.ProcessBy = currentUserId;
            currentStep.Remark = "朕對本身沒意見,沒備註。";
            currentStep.Result = "經過";
            currentStep.SubTime = DateTime.Now;
            //currentStep.StepName = "項目經理審批";
            //此步驟爲開始步驟狀態爲已經完成
            currentStep.Status = (short)EazyEnums.WFStepStatusEnum.End;
            stepBLL.Update(currentStep);

            if (isplay)
            {

                //第二個步驟:下一步誰審批的步驟。

                EazyBPMS.Model.eazy_wf_step nextStep = new Model.eazy_wf_step();
                nextStep.WF_Instance = this.id;
                nextStep.Checktime = DateTime.Now;
                nextStep.Comment = "";
                nextStep.DelFlag = del;

                nextStep.IsStartStep = false;
                nextStep.ProcessBy = Convert.ToInt32(this.txtrenyuan.Text);
                nextStep.Remark = "";
                nextStep.Result = "";

                //此步驟爲開始步驟狀態爲已經完成
                nextStep.Status = (short)EazyEnums.WFStepStatusEnum.Running;
                stepBLL.Add(nextStep);


            }

            //讓書籤繼續往下走
            BaseResumeBookMarkValue value = new BaseResumeBookMarkValue();
            value.BookMarkName = "";
            value.value = IsPass ? 1 : 0;//經過爲1不經過爲-1
            WorkFlowApplicationHelper.ResumeBookMark(
                new Finance_Activity(), this.wfAppId, currentStep.StepName, value);
            JscriptMsg("審批成功!", "waitwork.aspx");
        }
相關文章
相關標籤/搜索