/// <summary> /// 执行工作流 /// </summary> /// <param name="isSubmit"></param> /// <returns></returns> bool RunWorkflow(bool isSubmit) { WorkflowDataFields fields = WorkflowContext.Current.DataFields; string sWorkflowNO = fields["Title"].ToString(); bool isSuccess = true; List<NameCollection> listApprovers = GetDMMBDApprover();// OSPCommon.GetTaskUsers("wf_OSP"); if (null == listApprovers || listApprovers.Count == 0) { return false; } DataTable dt = DataEdit1.GetResultDt(sWorkflowNO); if (null == dt || dt.Rows.Count == 0) { DisplayMessage("No avaliable data!"); return false; } else { OSPCommon comm = new OSPCommon(); comm.DeleteData(sWorkflowNO);//删除老数据 comm.BatchAddToListByDatatable(dt, "OSPItems");//添加新数据 WorkflowContext context = WorkflowContext.Current; string sOSPActions = string.Empty; if (isSubmit)//是提交 { bool isNotNeedApprove = DataEdit1.IsNotNeedApprove(); if (isNotNeedApprove)//不需要审批 { bool isAllUpdated = DataEdit1.UpdateToSAP(sWorkflowNO); if (isAllUpdated)//全部更新成功。 { sOSPActions = OSPCommon.End; fields["Status"] = CAWorkflowStatus.Completed; } else { isSuccess = false; } } else//需要审批 { sOSPActions = OSPCommon.Submit; } } else//save agin { sOSPActions = OSPCommon.Save; } fields["Applicant"] = CurrentEmployee.DisplayName + "(" + CurrentEmployee.UserAccount + ")"; SPUser ApplicantSPUser = SPContext.Current.Web.EnsureUser(Userinfo1.Applicant.UserAccount); fields["ApplicantSPUser"] = ApplicantSPUser; context.UpdateWorkflowVariable("DMMApprover", listApprovers[0]); if (listApprovers[1] == null) { context.UpdateWorkflowVariable("IsSkipBD", true); fields["IsSkipBD"] = true; } else { context.UpdateWorkflowVariable("IsSkipBD", false); fields["IsSkipBD"] = false; context.UpdateWorkflowVariable("BDApprover", listApprovers[1]);// } context.UpdateWorkflowVariable("OSPActions", sOSPActions); return isSuccess; } }
/// <summary> /// 开启工作流 /// </summary> /// <param name="isSubmit"></param> /// <returns></returns> bool StartWorkflow(bool isSubmit) { bool isOK = DataEditEdit.CheckData(); if (!isOK) { return false; } string sWorkflowNumber = CreateWorkFlowNumber(); DataTable dt = DataEditEdit.GetResultDt(sWorkflowNumber); if (null == dt || dt.Rows.Count == 0) { DisplayMessage("No avaliable data!"); return false; } else { if (SetWorkflowVariable(sWorkflowNumber, isSubmit))//保存 { OSPCommon comm = new OSPCommon(); comm.BatchAddToListByDatatable(dt, "OSPItems"); if (HiddenFieldIsNotNeedApprove.Value=="1")//不需要通过审批 { WorkflowContext context = WorkflowContext.Current; WorkflowDataFields fields = WorkflowContext.Current.DataFields; context.UpdateWorkflowVariable("OSPActions", OSPCommon.End); fields["Status"] = CAWorkflowStatus.Completed; comm.UpdateOSPSuccess(sWorkflowNumber); } return true; } else { return false; } } }