private void BindFormData()
    {
        try
        {
            InstructionOfPKURGIInfo obj = Aitems.Get(FormID);
            if (obj != null)
            {
                tbReportCode.Text              = obj.FormID;
                tbDepartName.Text              = obj.DeptName;
                lbDeptCode.Text                = obj.DeptCode;
                tbDateTime.Text                = obj.DateTime;
                tbUserName.Text                = obj.UserName;
                tbMobile.Text                  = obj.Mobile;
                tbTitle.Text                   = obj.Title;
                tbContent.Text                 = obj.Content;
                cbIsReport.Checked             = obj.IsReport == "1" ? true : false;
                cblSecurityLevel.SelectedValue = obj.SecurityLevel != null?obj.SecurityLevel.ToString() : "-1";

                cblUrgenLevel.SelectedValue = obj.UrgenLevel != null?obj.UrgenLevel.ToString() : "-1";
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private bool SaveWorkFlowInstance(InstructionOfPKURGIInfo obj, string WfStatus, DateTime?SumitTime, string WfInstanceId)
    {
        bool             result           = false;
        WorkFlowInstance workFlowInstance = null;

        try
        {
            workFlowInstance = wf_WorkFlowInstance.GetWorkFlowInstanceByFormId(obj.FormID);
            bool isEdit = false;
            if (workFlowInstance == null)
            {
                workFlowInstance                  = new WorkFlowInstance();
                workFlowInstance.InstanceId       = Guid.NewGuid().ToString();
                workFlowInstance.CreateDeptCode   = ddlDepartName.SelectedItem.Value.ToString();
                workFlowInstance.CreateDeptName   = ddlDepartName.SelectedItem.Text;
                workFlowInstance.CreateAtTime     = DateTime.Now;
                workFlowInstance.CreateByUserCode = CurrentEmployee.EmployeeCode;
                workFlowInstance.CreateByUserName = CurrentEmployee.EmployeeName;
                workFlowInstance.AppId            = "3001";
            }
            else
            {
                workFlowInstance.CreateAtTime     = DateTime.Now;
                workFlowInstance.UpdateByUserCode = CurrentEmployee.EmployeeCode;
                workFlowInstance.UpdateByUserName = CurrentEmployee.EmployeeName;
                isEdit = true;
            }
            workFlowInstance.FormId    = obj.FormID;
            workFlowInstance.FormTitle = obj.Title;
            workFlowInstance.WfStatus  = WfStatus;
            if (SumitTime != null)
            {
                workFlowInstance.SumitTime = SumitTime;
            }

            if (WfInstanceId != "")
            {
                workFlowInstance.WfInstanceId = WfInstanceId;
            }

            if (!isEdit)
            {
                result = wf_WorkFlowInstance.AddWorkFlowInstance(workFlowInstance);
            }
            else
            {
                result = wf_WorkFlowInstance.UpdateWorkFlowInstance(workFlowInstance);
            }
            FlowRelated1.ProcId = workFlowInstance.InstanceId;
            Countersign1.ProcId = workFlowInstance.InstanceId;
            Countersign1.SaveData(true);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return(result);
    }
    private InstructionOfPKURGIInfo SaveData(string ID, string wfStatus)
    {
        SaveWFParams();
        InstructionOfPKURGIInfo obj = null;

        try
        {
            UploadAttachments1.SaveAttachment(ViewState["FormID"].ToString());
            obj = Eitems.Get(ID);
            bool isEdit = false;
            if (obj == null)
            {
                obj        = new InstructionOfPKURGIInfo();
                obj.FormID = ViewState["FormID"].ToString();
            }
            else
            {
                isEdit     = true;
                obj.FormID = ViewState["FormID"].ToString();
                //obj.ApproveStatus = wfStatus;
            }

            obj.DeptCode        = ddlDepartName.SelectedItem.Value.ToString();
            obj.DeptName        = ddlDepartName.SelectedItem.Text;
            obj.UserName        = tbUserName.Text;
            obj.Mobile          = tbMobile.Text;
            obj.Title           = tbTitle.Text;
            obj.DateTime        = UpdatedTextBox.Value;
            obj.Content         = tbContent.Text;
            obj.LeadersSelected = lblApprovers.Text;
            if (cblSecurityLevel.SelectedIndex != -1)
            {
                obj.SecurityLevel = cblSecurityLevel.SelectedValue.ToString();
            }
            if (cblUrgenLevel.SelectedIndex != -1)
            {
                obj.UrgenLevel = cblUrgenLevel.SelectedValue.ToString();
            }
            obj.IsReport = cbIsReport.Checked ? "1" : "0";
            if (!isEdit)
            {
                Eitems.Insert(obj);
            }
            else
            {
                Eitems.Update(obj);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return(obj);
    }
    private void BindFormData()
    {
        try
        {
            WorkFlowInstance Instance = wf_WorkFlowInstance.GetWorkFlowInstanceById(ViewState["InstanceID"].ToString());
            if (Instance == null)
            {
                ExceptionHander.GoToErrorPage("记录不存在");
            }
            InstructionOfPKURGIInfo obj = Vitems.Get(Instance.FormId.ToString());
            if (obj == null)
            {
                ExceptionHander.GoToErrorPage("记录不存在");
            }
            if (obj != null)
            {
                tbReportCode.Text = obj.FormID;
                tbDepartName.Text = obj.DeptName;
                lbDeptCode.Text   = obj.DeptCode;
                tbDateTime.Text   = obj.DateTime;
                tbUserName.Text   = obj.UserName;
                tbMobile.Text     = obj.Mobile;
                tbTitle.Text      = obj.Title;
                //tbContent.Text = Server.HtmlDecode( obj.Content);
                tbContent.Text                 = obj.Content.Replace(" ", "&nbsp;").Replace("\n", "<br/>");
                cbIsReport.Checked             = obj.IsReport == "1" ? true : false;
                cblSecurityLevel.SelectedValue = obj.SecurityLevel != null?obj.SecurityLevel.ToString() : "-1";

                cblUrgenLevel.SelectedValue = obj.UrgenLevel != null?obj.UrgenLevel.ToString() : "-1";
            }
            FlowRelated1.ProcId       = ViewState["InstanceID"].ToString();
            Countersign1.ProcId       = ViewState["InstanceID"].ToString();
            UploadAttachments1.ProcId = ViewState["InstanceID"].ToString();
            #region 审批意见框
            OpinionDeptManager.InstanceId = ViewState["InstanceID"].ToString();
            OpinionCountersign.InstanceId = ViewState["InstanceID"].ToString();
            OpinionAP.InstanceId          = ViewState["InstanceID"].ToString();
            OpinionVP.InstanceId          = ViewState["InstanceID"].ToString();
            OpinionDirectors.InstanceId   = ViewState["InstanceID"].ToString();
            OpinionPresident.InstanceId   = ViewState["InstanceID"].ToString();
            OpinionChairman.InstanceId    = ViewState["InstanceID"].ToString();
            #endregion
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        string id = ViewState["FormID"].ToString();
        InstructionOfPKURGIInfo obj = SaveData(id, "00");

        if (obj != null)
        {
            if (SaveWorkFlowInstance(obj, "0", null, ""))
            {
                Alert(Page, "保存成功!");
            }
        }
        else
        {
            Alert(Page, "保存失败");
        }
    }
    private void BindFormData()
    {
        try
        {
            InstructionOfPKURGIInfo obj = Eitems.Get(ViewState["FormID"].ToString());

            lbIsReport.Text = string.IsNullOrEmpty(obj.RelatedFormID) ? "0" : "1";
            if (lbIsReport.Text == "0")
            {
                ListItem item = ddlDepartName.Items.FindByValue(obj.DeptCode);
                if (item != null)
                {
                    ddlDepartName.SelectedIndex = ddlDepartName.Items.IndexOf(item);
                }
            }
            else
            {
                ddlDepartName.Items.Clear();
                string     CompanyCode = BPMHelp.GetCompanyCodeByDeptID(obj.DeptCode);
                Department deptInfo    = new Pkurg.PWorld.Services.DepartmentService().GetByDepartCode(CompanyCode);

                ListItem item = new ListItem {
                    Text = deptInfo.DepartName, Value = CompanyCode
                };
                ddlDepartName.Items.Add(item);
                ddlDepartName.Enabled = false;
            }
            tbReportCode.Text              = obj.FormID;
            tbUserName.Text                = obj.UserName;
            tbMobile.Text                  = obj.Mobile;
            tbTitle.Text                   = obj.Title;
            tbContent.Text                 = obj.Content;
            UpdatedTextBox.Value           = !string.IsNullOrEmpty(obj.DateTime) ? obj.DateTime : DateTime.Now.ToShortDateString();
            cblSecurityLevel.SelectedValue = obj.SecurityLevel != null?obj.SecurityLevel.ToString() : "-1";

            cblUrgenLevel.SelectedValue = obj.UrgenLevel != null?obj.UrgenLevel.ToString() : "-1";

            cbIsReport.Checked = obj.IsReport == "1" ? true : false;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void SaveData(string ID, string wfStatus)
    {
        InstructionOfPKURGIInfo obj = null;

        try
        {
            obj                 = Aitems.Get(ID);
            obj.FormID          = ViewState["FormID"].ToString();
            obj.LeadersSelected = lblApprovers.Text;
            obj.IsReport        = cbIsReport.Checked ? "1" : "0";
            obj.Content         = tbContent.Text;
            obj.Title           = tbTitle.Text;

            Aitems.Update(obj);

            WorkFlowInstance workFlowInstance = wf_WorkFlowInstance.GetWorkFlowInstanceByFormId(obj.FormID);
            Countersign1.ProcId = workFlowInstance.InstanceId;
            Countersign1.SaveData(true);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        string id = ViewState["FormID"].ToString();
        string SaveVerification = SaveWFParams();

        if (string.IsNullOrEmpty(SaveVerification))
        {
            return;
        }
        #region 工作流参数
        NameValueCollection dataFields = SetWFParams();
        if (dataFields == null)
        {
            return;
        }
        #endregion

        InstructionOfPKURGIInfo obj = SaveData(id, "02");
        if (obj != null)
        {
            //开启流程
            WorkflowHelper.CurrentUser = "******" + _BPMContext.CurrentUser.LoginId;
            AppDict appInfo = new Pkurg.BPM.Services.AppDictService().GetByAppId("3001");
            if (appInfo == null)
            {
                Alert("提交失败");
                return;
            }
            int wfInstanceId = 0; //process instance id
            WorkflowHelper.StartProcess(@"K2Workflow\OA_InstructionOfPKURGI", id, dataFields, ref wfInstanceId);
            if (wfInstanceId > 0)
            {
                if (SaveWorkFlowInstance(obj, "1", DateTime.Now, wfInstanceId.ToString()))
                {
                    if (Eitems.UpdateStatus(id, "02"))
                    {
                        string           Opinion          = "";
                        string           ApproveResult    = "同意";
                        string           OpinionType      = "";
                        string           IsSign           = "0";
                        string           DelegateUserName = "";
                        string           DelegateUserCode = "";
                        WorkFlowInstance workFlowInstance = wf_WorkFlowInstance.GetWorkFlowInstanceByFormId(obj.FormID);

                        var appRecord = new Pkurg.PWorldBPM.Business.Sys.WF_Approval_Record()
                        {
                            ApprovalID = Guid.NewGuid().ToString(),

                            FormID            = id,
                            InstanceID        = workFlowInstance.InstanceId,
                            Opinion           = Opinion,
                            ApproveAtTime     = DateTime.Now,
                            ApproveByUserCode = CurrentEmployee.EmployeeCode,
                            ApproveByUserName = CurrentEmployee.EmployeeName,
                            ApproveResult     = ApproveResult,
                            OpinionType       = OpinionType,
                            CurrentActiveName = "拟稿",
                            ISSign            = IsSign,

                            DelegateUserName = DelegateUserName,
                            DelegateUserCode = DelegateUserCode,
                            CreateAtTime     = DateTime.Now,
                            CreateByUserCode = CurrentEmployee.EmployeeCode,
                            CreateByUserName = CurrentEmployee.EmployeeName,
                            UpdateAtTime     = DateTime.Now,
                            UpdateByUserCode = CurrentEmployee.EmployeeCode,
                            UpdateByUserName = CurrentEmployee.EmployeeName,
                            FinishedTime     = DateTime.Now
                        };
                        BFApprovalRecord bfApproval = new BFApprovalRecord();
                        bfApproval.AddApprovalRecord(appRecord);
                    }
                    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "1", "alert('提交成功');", true);
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ajax", " window.opener=null; window.open('', '_self', '');window.close();", true);
                }
            }
        }
        Alert("提交失败");
    }
    private void InitCheckBoxList()
    {
        BFPmsUserRoleDepartment bfurd = new BFPmsUserRoleDepartment();
        DataTable dtLeaders           = bfurd.GetSelectRoleUser(GroupCode, "总办会成员");

        foreach (DataRow user in dtLeaders.Rows)
        {
            ListItem li = new ListItem();
            li.Value = "K2:Founder\\" + user["LoginName"].ToString();
            li.Text  = user["EmployeeName"].ToString();
            if (!cblDirectors.Items.Contains(li))
            {
                cblDirectors.Items.Add(li);
            }
        }

        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            XmlDocument             xmldoc       = new XmlDocument();
            InstructionOfPKURGIInfo formDataInfo = Eitems.Get(FormId);
            if (!string.IsNullOrEmpty(formDataInfo.LeadersSelected))
            {
                xmldoc.LoadXml(formDataInfo.LeadersSelected);
            }

            XmlNode NodeLeaders = xmldoc.SelectSingleNode("//Directors");
            if (NodeLeaders != null && NodeLeaders.Attributes["ID"].Value.Length > 0)
            {
                foreach (string UserGuid in NodeLeaders.Attributes["ID"].Value.Split(','))
                {
                    for (int i = 0; i < cblDirectors.Items.Count; i++)
                    {
                        if (cblDirectors.Items[i].Value == UserGuid)
                        {
                            cblDirectors.Items[i].Selected = true;
                        }
                    }
                }
            }
            XmlNode NodeChairman = xmldoc.SelectSingleNode("//Chairman");
            if (NodeChairman != null && NodeChairman.Attributes["ID"].Value != "noapprovers")
            {
                cbChairman.Checked = true;
            }
            else
            {
                cbChairman.Checked = false;
            }
            //XmlNode NodePresident = xmldoc.SelectSingleNode("//President");
            //if (NodePresident != null && NodePresident.Attributes["ID"].Value != "noapprovers")
            //{
            //    cbPresident.Checked = true;
            //}
            XmlNode NodeVP = xmldoc.SelectSingleNode("//VicePresident");
            if (NodeVP != null && NodeVP.Attributes["ID"].Value != "noapprovers")
            {
                cbVP.Checked = true;
            }
            else
            {
                cbVP.Checked = false;
            }
            XmlNode NodeAP = xmldoc.SelectSingleNode("//AssiPresident");
            if (NodeAP != null && NodeAP.Attributes["ID"].Value != "noapprovers")
            {
                cbAP.Checked = true;
            }
            else
            {
                cbAP.Checked = false;
            }
        }
        else
        {
            for (int i = 0; i < cblDirectors.Items.Count; i++)
            {
                cblDirectors.Items[i].Selected = false;
            }
        }
    }