//Bind Basic Info
    private void BindData()
    {
        EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);

        //绑定流程信息
        lbl_Applyer.Text = new Org_StaffBLL(task.Model.Initiator).Model.RealName;
        lbl_AppName.Text = new EWF_Flow_AppBLL(task.Model.App).Model.Name;
        tbx_Topic.Text = task.Model.Title;

        lb_StartTime.Text = task.Model.StartTime.ToString();
        if (task.Model.EndTime != new DateTime(1900, 1, 1))
            lb_EndTime.Text = task.Model.EndTime.ToString();
        else
            lb_EndTime.Text = "未结束";

        if (task.Model.RelateURL != "")
        {
            hyl_RelateURL.NavigateUrl = task.Model.RelateURL;
            hyl_RelateURL.Visible = true;
        }
        else
            hyl_RelateURL.Visible = false;

        //Bind the dataobject info
        NameValueCollection dataobjects = task.GetDataObjectValue();
        pl_dataobjectinfo.BindData(dataobjects);
    }
    public string GetDataObjectValue(Guid DataObjectID)
    {
        EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);

        if (DataObjectID != Guid.Empty)
            return task.GetDataObjectValue()[new EWF_Flow_DataObjectBLL(DataObjectID).Model.Name];
        else
            return "";
    }
    //确定发起
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);

        if (task.Start() >= 0)
        {
            MessageBox.ShowAndRedirect(this, "流程已成功发起!!", "TaskDetail.aspx?TaskID=" + task.Model.ID.ToString());
        }
        else
        {
            MessageBox.Show(this, "对不起,流程发起失败,请确认该申请流程有开始环节!");
        }
    }
    //暂存意见
    protected void bt_SaveDecisionComment_Click(object sender, EventArgs e)
    {
        if (tbx_DecisionComment.Text == "")
        {
            MessageBox.Show(this, "审批意见必填");
            return;
        }

        string comment = tbx_DecisionComment.Text.Trim();
        comment += "<br/>------" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "-------<br/>";

        EWF_Task_InviteConsultBLL InviteConsultBLL = new EWF_Task_InviteConsultBLL((int)ViewState["InviteConsult"]);
        InviteConsultBLL.SaveConsultComment(comment);

        #region 更新任务备注信息
        string remark = "协助时间:<b><font color=red>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</font></b> ";
        remark += "协助审批人:<b><font color=red>" + Session["UserRealName"].ToString() + "</font></b> ";
        remark += " 审批意见:<b><font color=red>" + tbx_DecisionComment.Text + "</font></b> ";
        remark += "<br/>";

        EWF_TaskBLL taskbll = new EWF_TaskBLL((int)ViewState["TaskID"]);
        taskbll.AppendRemark(remark);

        if (cbx_NotifyInitiator.Checked)
        {
            string _content = "<b><font color=red>工作流处理通知!您发起的协助邀审有了回复!</font></b><br/>";
            _content += "工作流:<font color=red>" + lbl_AppName.Text + "</font><br/>";
            _content += "主题:<font color=red>" + lbl_Title.Text + "</font><br/><br/>";
            _content += remark;

            _content += "<br/><a href='" + this.ResolveUrl("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + ViewState["TaskID"].ToString()) + "' target='_blank'><font color=blue>点击查看工作流详细情况</font></a><br/>";

            DataTable _users = new Org_StaffBLL(InviteConsultBLL.Model.InvitedStaff).GetUserList();
            foreach (DataRow dr_user in _users.Rows)
            {
                SendSM(dr_user["UserName"].ToString(), _content);
            }
        }
        #endregion

        MessageBox.ShowAndRedirect(this, "保存成功!", "TaskList_InviteConsult.aspx");
    }
    //Submit the Apply
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        EWF_TaskBLL task;
        if ((int)ViewState["TaskID"] == 0)
        {
            task = new EWF_TaskBLL();
            task.Model.App = (Guid)ViewState["AppID"];
            task.Model.Initiator = (int)Session["UserID"];
            task.Model.Title = tbx_Topic.Text;
            task.Model.DataObjectValues = pl_dataobjectinfo.GetData();
            task.Add();
        }
        else
        {
            task = new EWF_TaskBLL((int)ViewState["TaskID"]);
            task.SetDataObjectValue(pl_dataobjectinfo.GetData());
        }
        task.Start();

        MessageBox.ShowAndRedirect(this, "流程已成功发起!!", "TaskDetail.aspx?TaskID=" + task.Model.ID.ToString());
    }
    protected void btn_pass_Click(object sender, EventArgs e)
    {
        int TaskID, JobCCID;
        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cb_check = (CheckBox)row.FindControl("cb_Check");
            if (cb_check.Checked)
            {
                TaskID = int.Parse(gv_List.DataKeys[row.RowIndex]["TaskID"].ToString());
                JobCCID = int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString());
                EWF_TaskBLL taskbll = new EWF_TaskBLL(TaskID);
                EWF_Task_JobCCBLL JobCCBLL = new EWF_Task_JobCCBLL(JobCCID);
                if (taskbll.Model.EndTime == new DateTime(1900, 1, 1) && JobCCBLL.Model.ReadFlag != "Y")
                {
                    string comment = "已阅";
                    comment += "<br/>------" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "-------<br/>";
                    JobCCBLL.SaveComment(comment);

                    #region 更新任务备注信息
                    string remark = "抄送批注时间:<b><font color=red>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</font></b> ";
                    remark += "抄送批注人:<b><font color=red>" + Session["UserRealName"].ToString() + "</font></b> ";
                    remark += " 批注意见:<b><font color=red>已阅</font></b> ";
                    remark += "<br/>";

                    taskbll.AppendRemark(remark);

                    #endregion

                }
                if (JobCCBLL.Model.ReadFlag != "Y")
                {
                    JobCCBLL.SetReadFlag("Y");
                }

            }
        }
        MessageBox.Show(this, "批量审阅成功!");
        BindGrid();
    }
    private void BindData()
    {
        int id = (int)ViewState["ID"];

        FNA_FeeApply apply = new FNA_FeeApplyBLL(id).Model;
        ViewState["AccountMonth"] = apply.AccountMonth;

        if (apply == null) Response.Redirect("FeeApplyList.aspx");

        pn_FeeApply.BindData(apply);

        Label lb_OrganizeCity = (Label)pn_FeeApply.FindControl("FNA_FeeApply_OrganizeCity");
        lb_OrganizeCity.Text = TreeTableBLL.GetFullPathName("MCS_Sys.dbo.Addr_OrganizeCity", apply.OrganizeCity);

        #region 将备注信息单独显示出来
        Label lb_remark = (Label)pn_FeeApply.FindControl("FNA_FeeApply_Remark");
        if (lb_remark != null)
        {
            lb_remark.Text = apply["Remark"].Replace("\r\n", "<br/>");
        }
        #endregion

        BindGrid();

        #region 获取流程审批意见
        int TaskID = 0;

        if (int.TryParse(apply["TaskID"], out TaskID) && TaskID > 0)
        {
            EWF_TaskBLL task = new EWF_TaskBLL(TaskID);
            if (task.Model != null)
            {
                lb_TaskApproveInfo.Text = task.Model.Remark;
            }
        }
        #endregion
    }
    //绑定开始环节详细信息
    private void BindTaskInfo()
    {
        EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);

        #region 如果任务在待审批状态,且正好是待当前人审批,则直接切换到审批页面
        if (task.Model.Status == 3)
        {
            int job = EWF_TaskBLL.StaffCanApproveTask(task.Model.ID, (int)Session["UserID"]);
            if (job > 0) Response.Redirect("Recipient.aspx?CurrentJobID=" + job.ToString() + "&TaskID=" + task.Model.ID.ToString());
        }
        #endregion

        EWF_Flow_App app = new EWF_Flow_AppBLL(task.Model.App).Model;

        #region 绑定流程信息
        lbl_ID.Text = task.Model.ID.ToString();
        lbl_Applyer.Text = new Org_StaffBLL(task.Model.Initiator).Model.RealName;
        lbl_AppName.Text = app.Name;

        lbl_Applyer_Position.Text = new Org_PositionBLL(new Org_StaffBLL(task.Model.Initiator).Model.Position).Model.Name;

        lbl_Title.Text = task.Model.Title;
        lb_Status.Text = DictionaryBLL.GetDicCollections("EWF_Task_TaskStatus")[task.Model.Status.ToString()].Name;

        lb_StartTime.Text = task.Model.StartTime.ToString();
        if (task.Model.EndTime != new DateTime(1900, 1, 1))
            lb_EndTime.Text = task.Model.EndTime.ToString();
        else
            lb_EndTime.Text = "未结束";

        lt_Remark.Text = task.Model.Remark;

        #region 绑定流程当前环节信息
        if (task.Model.Status < 5)
        {
            IList<EWF_Task_Job> jobs = EWF_Task_JobBLL.GetModelList("Task=" + task.Model.ID.ToString() + " ORDER BY StartTime DESC");
            if (jobs.Count > 0)
            {
                EWF_Flow_Process process = new EWF_Flow_ProcessBLL(jobs[0].CurrentProcess).Model;
                if (process != null)
                {
                    lb_CurrentJobInfo.Text = process.Name;
                    if (process.Type == 3)
                    {
                        lb_CurrentJobInfo.Text += " 等待审批人:";
                        foreach (EWF_Task_JobDecision decision in EWF_Task_JobDecisionBLL.GetModelList("Job=" + jobs[0].ID.ToString()))
                        {
                            MCSFramework.Model.Org_Staff staff = new Org_StaffBLL(decision.RecipientStaff).Model;
                            if (staff != null) lb_CurrentJobInfo.Text += staff.RealName + "   ";
                        }
                    }
                }
            }
        }
        else
            tr_CurrentProcessInfo.Visible = false;
        #endregion

        #endregion

        #region 控制流程状态
        if (task.Model.Initiator == (int)Session["UserID"])
        {
            //只有流程发起的本人,才可控制流程状态

            if (task.Model.Status == 6)
            {
                MessageBox.Show(this, "您的流程因故停止流转,请尽快联系系统管理员排查原因,或点击“继续执行”按钮以重新启动流程的流转!");
                bt_Restart.Visible = true;
            }

            if (task.Model.Status == 4)
            {
                MessageBox.Show(this, "您的流程被最后一审批人设为了待处理状态,请补充相关信息附件后,或点击“继续执行”按钮以重新启动流程的流转!");
                bt_Restart.Visible = true;

            }

            if (task.Model.Status == 1)
            {
                MessageBox.Show(this, "您的流程还没正式发起申请,请尽快点击“确定发起”按钮以发起流程!");
                btn_Start.Visible = true;
            }

            if (task.Model.Status != 5)
            {
                //未完成
                if (app.RelateBusiness == "N")
                    bt_Cancel.Visible = true;
                tr_UploadAtt.Visible = true;
            }
        }
        #endregion

        #region 显示申请详细信息IFrame
        //显示申请详细信息IFrame
        if (!string.IsNullOrEmpty(task.Model.RelateURL))
        {
            hyl_RelateURL.NavigateUrl = task.Model.RelateURL;
            tr_RelateUrl.Visible = true;
            string url = this.ResolveClientUrl(task.Model.RelateURL);
            if (url.IndexOf('?') >= 0)
                url += "&ViewFramework=False";
            else
                url += "?ViewFramework=False";
            frame_relateurl.Attributes.Add("src", url);
        }
        else
        {
            tr_RelateUrl.Visible = false;
            hyl_RelateURL.Visible = false;
        }
        #endregion

        //Bind the dataobject info
        pl_dataobjectinfo.BindData(task.Model.DataObjectValues);
        if (task.Model.Status > 1)
        {
            pl_dataobjectinfo.SetPanelEnable(false);

            TextBox tbx_ReMark = pl_dataobjectinfo.FindControl("C_Remark") != null ? (TextBox)pl_dataobjectinfo.FindControl("C_Remark") : null;
            if (tbx_ReMark != null)
            {
                tbx_ReMark.Enabled = true;
                tbx_ReMark.ReadOnly = true;
            }

        }

        //绑定环节列表
        gv_List_JobList.BindGrid<EWF_Task_Job>(task.GetJobList());
    }
 //绑定环节列表
 private void BindProcessList()
 {
     EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);
 }
    //绑定条件判断环节详细信息
    private void BindConditionProcessInfo(int JobID)
    {
        EWF_Task_JobBLL job = new EWF_Task_JobBLL(JobID);
        EWF_TaskBLL task = new EWF_TaskBLL(job.Model.Task);
        EWF_Flow_ProcessConditionBLL process = new EWF_Flow_ProcessConditionBLL(job.Model.CurrentProcess);
        EWF_Flow_DataObjectBLL dataobject = new EWF_Flow_DataObjectBLL(process.Model.DataObject);

        this.lbl_DataObjectName.Text = dataobject.Model.Name;
        this.lbl_DataObjectDisPlayName.Text = dataobject.Model.DisplayName;

        this.lbl_DataObjectValue.Text = task.GetDataObjectValue()[dataobject.Model.Name]; ;
        this.lbl_OperatorTypeName.Text = DictionaryBLL.GetDicCollections("EWF_Flow_OperatorType")[process.Model.OperatorType.ToString()].Name;

        this.lbl_Value1.Text = process.Model.Value1;
        this.lbl_Value2.Text = process.Model.Value2;
    }
 private void BindAttachmentList()
 {
     //绑定附件
     EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);
     gv_List_Attachment.BindGrid<EWF_Task_Attachment>(task.GetAttachmentsList());
 }
    //继续执行
    protected void bt_Restart_Click(object sender, EventArgs e)
    {
        EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);

        task.ReStart();
        MessageBox.ShowAndRedirect(this, "流程已继续执行!!", "../desktop.aspx");
    }
    //绑定基本信息
    private void BindTaskData()
    {
        #region 绑定当前工作项
        EWF_Task_InviteConsultBLL InviteConsultBLL = new EWF_Task_InviteConsultBLL((int)ViewState["InviteConsult"]);
        if (InviteConsultBLL.Model == null || InviteConsultBLL.Model.RecipientStaff != (int)Session["UserID"])
        {
            Response.Redirect("~/SubModule/DeskTop.aspx");
            return;
        }

        if (InviteConsultBLL.Model.ReadFlag != "Y")
        {
            InviteConsultBLL.SetReadFlag("Y");
        }

        EWF_Task_JobBLL JobBLL = new EWF_Task_JobBLL(InviteConsultBLL.Model.Job);
        if (JobBLL.Model.Status != 3)
        {
            MessageBox.Show(this, "该流程已不在等待邀请协助审批状态!");
            bt_SaveDecisionComment.Visible = false;
            tbx_DecisionComment.Visible = false;
        }
        //绑定当前邀审相关信息
        lbl_CurrentJobName.Text = new EWF_Flow_ProcessBLL(JobBLL.Model.CurrentProcess).Model.Name;
        lbl_InvitedStaff.Text = new Org_StaffBLL(InviteConsultBLL.Model.InvitedStaff).Model.RealName;
        lbl_InvitedTime.Text = InviteConsultBLL.Model.InvitedTime.ToString("yyyy-MM-dd HH:mm");
        lb_DecisionComment.Text = InviteConsultBLL.Model.ConsultComment;
        #endregion

        #region 绑定流程信息
        EWF_TaskBLL task = new EWF_TaskBLL((int)ViewState["TaskID"]);
        ViewState["Initiator"] = task.Model.Initiator;
        //绑定流程信息
        lbl_Applyer.Text = new Org_StaffBLL(task.Model.Initiator).Model.RealName;
        lbl_AppName.Text = new EWF_Flow_AppBLL(task.Model.App).Model.Name;
        lbl_Title.Text = task.Model.Title;
        hyl_RelateURL.NavigateUrl = task.Model.RelateURL;
        lb_Status.Text = DictionaryBLL.GetDicCollections("EWF_Task_TaskStatus")[task.Model.Status.ToString()].Name;

        lb_StartTime.Text = task.Model.StartTime.ToString();
        if (task.Model.EndTime != new DateTime(1900, 1, 1))
            lb_EndTime.Text = task.Model.EndTime.ToString();
        else
            lb_EndTime.Text = "未结束";

        lt_Remark.Text = task.Model.Remark;

        //显示申请详细信息IFrame
        if (!string.IsNullOrEmpty(task.Model.RelateURL))
        {
            tr_RelateUrl.Visible = true;
            string url = this.ResolveClientUrl(task.Model.RelateURL);
            if (url.IndexOf('?') >= 0)
                url += "&ViewFramework=false&Decision=Y";
            else
                url += "?ViewFramework=false&Decision=Y";
            frame_relateurl.Attributes.Add("src", url);
        }
        else
        {
            tr_RelateUrl.Visible = false;
        }

        //Bind the dataobject info
        NameValueCollection dataobjects = task.GetDataObjectValue();
        pl_dataobjectinfo.BindData(dataobjects);
        pl_dataobjectinfo.SetPanelEnable(false);
        TextBox tbx_ReMark = pl_dataobjectinfo.FindControl("C_Remark") != null ? (TextBox)pl_dataobjectinfo.FindControl("C_Remark") : null;
        if (tbx_ReMark != null)
        {
            tbx_ReMark.Enabled = true;
            tbx_ReMark.ReadOnly = true;
        }
        //绑定审批历史
        this.gv_List_DecisionHistory.DataSource = task.GetDecisionHistory();
        this.gv_List_DecisionHistory.DataBind();

        //绑定附件
        gv_List_Attachment.BindGrid<EWF_Task_Attachment>(task.GetAttachmentsList());
        #endregion
    }