Example #1
0
        protected void BtnApply_Click(object sender, EventArgs e)
        {
            CollectSelected();

            RequestForm requserform = new RequestForm();
            requserform.ApplyReason = txtApplyReason.Text.ToString();
            requserform.ApplyUserName = txtName.Text.ToString();
            requserform.BeginTime = DateTime.Parse(txtBeginTime.Text.ToString());
            requserform.EndTime = DateTime.Parse(txtEndTime.Text.ToString());
            requserform.StartDestination = txtStartDes.Text.ToString();
            requserform.EndDestination = txtEndDes.Text.ToString();
            requserform.Comment = txtComment.Text.ToString();
            requserform.usecartypeID = int.Parse(ddlCarType.SelectedValue);
            requserform.Usecaranduser = CollectUser();
            UseCarWorkFlowProcess.CreateAndRun(requserform);
            lbMsg.Text = "申请成功,等待管理员审核...";
            BtnApply.Visible = false;
            BtnCause.Visible = false;
        }
        public static Guid CreateAndRun(RequestForm requsetForm)
        {
            //工作流服务实例的状态信息持久保存到数据库中
            //SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore("server=.;database=aspnetdb;uid=sa;pwd=0000");
            SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"Data Source=.\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True");//在宿主程序中首先我们创建SqlWorkflowInstanceStore的实例
            InstanceView             view          = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));

            instanceStore.DefaultInstanceOwner = view.InstanceOwner;//对SqlWorkflowInstanceStore实例的各种配置

            IDictionary <string, object> input = new Dictionary <string, object>
            {
                { "Request", requsetForm }
            };

            WorkflowApplication application = new WorkflowApplication(new UseCarApply(), input);

            application.InstanceStore   = instanceStore; //并将application的InstanceStore属性设置为该实例来指定使用的持久化存储
            application.PersistableIdle = (e) =>         //获取工作流实例处于空闲状态并且可被保留时调用
            {
                instanceUnloaded.Set();
                return(PersistableIdleAction.Unload);  //保持并且卸载工作流
            };
            application.Unloaded = (e) =>              //获取或设置卸载当前工作流时调用
            {
                instanceUnloaded.Set();                //将事件设置为主终止状态允许其他的线程继续。
            };
            application.OnUnhandledException = (ex) => //异常
            {
                Console.Write("Exception");
                return(UnhandledExceptionAction.Terminate);
            };

            Guid id = application.Id;

            //application.Persist();
            application.Run();
            instanceUnloaded.WaitOne();//阻止当前线程,直到收到信号
            return(id);
        }
        public static Guid CreateAndRun(RequestForm requsetForm)
        {
            //工作流服务实例的状态信息持久保存到数据库中
            //SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore("server=.;database=aspnetdb;uid=sa;pwd=0000");
            SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"Data Source=.\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True");//在宿主程序中首先我们创建SqlWorkflowInstanceStore的实例
            InstanceView view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));

            instanceStore.DefaultInstanceOwner = view.InstanceOwner;//对SqlWorkflowInstanceStore实例的各种配置

            IDictionary<string, object> input = new Dictionary<string, object>
            {
                { "Request" , requsetForm }
            };

            WorkflowApplication application = new WorkflowApplication(new UseCarApply(), input);

            application.InstanceStore = instanceStore;//并将application的InstanceStore属性设置为该实例来指定使用的持久化存储
            application.PersistableIdle = (e) =>//获取工作流实例处于空闲状态并且可被保留时调用
            {
                instanceUnloaded.Set();
                return PersistableIdleAction.Unload;//保持并且卸载工作流
            };
            application.Unloaded = (e) =>//获取或设置卸载当前工作流时调用
            {
                instanceUnloaded.Set();//将事件设置为主终止状态允许其他的线程继续。
            };
            application.OnUnhandledException = (ex) =>//异常
            {
                Console.Write("Exception");
                return UnhandledExceptionAction.Terminate;
            };

            Guid id = application.Id;
            //application.Persist();
            application.Run();
            instanceUnloaded.WaitOne();//阻止当前线程,直到收到信号
            return id;
        }