Example #1
0
 //得到审核的历史
 public APWorkFlow.NodeStatusDataTable getApprovalStatus(string processInstanceID)
 {
     try {
         if (String.IsNullOrEmpty(processInstanceID))
         {
             throw new Exception("getAprovalStatus - processInstanceID is empty");
         }
         //string sql = "SELECT ASSIGNED_DATE, CANCELLED_DATE, COMPLETED_DATE, DUE_DATE, CREATED_DATE, STATUS, USER_ID, CLIENT_DATA,'' as " + StatusColumnName.APPROVED_BY + ", 0 as " + StatusColumnName.IS_APPROVED + ",'' as " + StatusColumnName.COMMENTS + " FROM WF_MANUAL_WORKITEMS where PROC_INST_ID='" + processInstanceID + "' order by ASSIGNED_DATE asc";
         string    sql    = "select CLIENT_DATA FROM WF_MANUAL_WORKITEMS where PROC_INST_ID='" + processInstanceID + "' order by ASSIGNED_DATE asc";
         String[]  sqlRet = api.QueryDatabaseEx(sql);
         DataTable dt     = getDataTableFromXML(sqlRet[0], sqlRet[1]);
         if (dt != null)
         {
             APWorkFlow.NodeStatusDataTable result = new APWorkFlow.NodeStatusDataTable();
             foreach (DataRow row in dt.Rows)
             {
                 string clientData;
                 try {
                     clientData = (string)row["CLIENT_DATA"];
                 } catch (Exception ee) {
                     clientData = null;
                 }
                 if (!String.IsNullOrEmpty(clientData))
                 {
                     APWorkFlow.NodeStatusDataTable cddt = new APWorkFlow.NodeStatusDataTable();
                     StringReader sr = new StringReader(clientData);
                     cddt.ReadXml(sr);
                     if (cddt != null && cddt.Rows.Count > 0)
                     {
                         result.ImportRow(cddt[0]);
                     }
                 }
             }
             return(result);
         }
         else
         {
             return(null);
         }
     } catch (Exception e) {
         throw new Exception(errorMSGPrefix + e.Message, e);
     }
 }
Example #2
0
        //
        /// <summary>
        /// ApprovedDate【0】,LastApprover【1】,Comment【2】,ApproverIds【3】
        /// </summary>
        /// <param name="processInstanceID"></param>
        /// <returns>ApprovedDate【0】,LastApprover【1】,Comment【2】,ApproverIds【3】</returns>
        public string[] GetProcessApproveUser(string processInstanceID)
        {
            DateTime ApprovedDate = DateTime.MinValue;
            string   LastApprover = "";
            string   Comment      = "";
            string   ApproverIds  = "";

            string[] ApproveInfo = new string[4];
            APWorkFlowTableAdapters.StuffUserInfoTableAdapter TAStuffUserinfo = new APWorkFlowTableAdapters.StuffUserInfoTableAdapter();
            if (String.IsNullOrEmpty(processInstanceID))
            {
                throw new Exception("GetProcessApproveUser - processInstanceID is empty");
            }
            string sql = "select CLIENT_DATA FROM WF_MANUAL_WORKITEMS where CLIENT_DATA like '%</APPROVED_BY>%' and PROC_INST_ID='" + processInstanceID + "' order by ASSIGNED_DATE asc";

            String[]  sqlRet     = api.QueryDatabaseEx(sql);
            DataTable l_dtclient = getDataTableFromXML(sqlRet[0], sqlRet[1]);

            APWorkFlow.NodeStatusDataTable l_dtapprove = new APWorkFlow.NodeStatusDataTable();
            int i = 0;

            foreach (DataRow l_dr in l_dtclient.Rows)
            {
                StringReader sr = new StringReader(l_dr["CLIENT_DATA"].ToString());
                l_dtapprove.ReadXml(sr);
                if (Convert.ToDateTime(l_dtapprove[0].COMPLETED_DATE) > ApprovedDate)
                {
                    ApprovedDate = Convert.ToDateTime(l_dtapprove[0].COMPLETED_DATE);
                    LastApprover = TAStuffUserinfo.GetDataByStuffName(l_dtapprove[0].APPROVED_BY)[0].StuffUserId.ToString();
                    Comment      = l_dtapprove[0].COMMENTS;
                }
                if (!string.IsNullOrEmpty(l_dtapprove[i].APPROVED_BY))
                {
                    ApproverIds += ("P" + TAStuffUserinfo.GetDataByStuffName(l_dtapprove[i].APPROVED_BY)[0].StuffUserId + "P");
                }
                i++;
            }
            ApproveInfo[0] = ApprovedDate.ToString();
            ApproveInfo[1] = LastApprover;
            ApproveInfo[2] = Comment;
            ApproveInfo[3] = ApproverIds;
            return(ApproveInfo);
        }
Example #3
0
        //找到下个节点
        private string prepareNextNode(string processInstanceID, string lastUserID, int OrganizationUnitID, ref string email)
        {
            WFManualWorkItem nextNode = getNextNode(processInstanceID);

            if (nextNode == null)
            {
                return(null); //process finished
            }
            else
            {
                string participant      = "";
                string participantEmail = "";
                nextNode.UserID = nextNode.UserID.Split('\\')[1].ToString();

                //translate participant(防止多个流程角色)
                string[] ids = nextNode.OriginalUserID.Split('\\')[1].ToString().Split("|".ToCharArray());
                for (int i = 0; i < ids.Length; i++)
                {
                    string uid = string.Empty;

                    string PositionTypeCode = ids[i].ToString();
                    getUserIDByIdentifier(PositionTypeCode, OrganizationUnitID, ref uid, ref email);

                    //当前角色下找不到人
                    if (uid == "none")
                    {
                        continue;
                    }
                    else
                    {
                        participant      += uid + "&";
                        participantEmail += email;
                    }
                }
                participant = participant.TrimEnd('&');
                // update workitem
                APWorkFlow.NodeStatusDataTable dt = new APWorkFlow.NodeStatusDataTable();
                APWorkFlow.NodeStatusRow       dr = dt.NewNodeStatusRow();
                if (!String.IsNullOrEmpty(participant) && participant != "none")   //user found
                {
                    dr.STATUS      = FlowNodeStatus.ASSIGNED;
                    dr.PARTICIPANT = participant;
                    //dr.AcceptChanges();
                    dt.AddNodeStatusRow(dr);
                    dt.AcceptChanges();
                    StringWriter sw = new StringWriter();
                    dt.WriteXml(sw);
                    string clientData = sw.ToString();

                    System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                    attrList.Add(new NameValue("UserID", dr.PARTICIPANT));//更新该步骤的userid
                    attrList.Add(new NameValue("CLIENT_DATA", clientData));
                    NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                    api.UpdateWorkItem(nextNode.WorkItemID, attributes);
                    //update email
                    if (!String.IsNullOrEmpty(participantEmail))
                    {
                        email = participantEmail;
                    }
                    return(dr.PARTICIPANT);
                }
                else     // 没有找到人员
                {
                    dr.STATUS      = FlowNodeStatus.ONERROR;
                    dr.PARTICIPANT = "P" + lastUserID + "P";
                    //dr.ERROR_MSG = "错误代码:Invalid UserId (" + nextNode.ProcInstName + "," + nextNode.OriginalUserID + "," + nextNode.UserID + ")";
                    dr.ERROR_MSG = "未能找到下一步审批人!";
                    //dr.AcceptChanges();
                    dt.AddNodeStatusRow(dr);
                    dt.AcceptChanges();
                    StringWriter sw = new StringWriter();
                    dt.WriteXml(sw);
                    string clientData = sw.ToString();

                    System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                    attrList.Add(new NameValue("UserID", dr.PARTICIPANT));
                    attrList.Add(new NameValue("CLIENT_DATA", clientData));
                    NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                    api.UpdateWorkItem(nextNode.WorkItemID, attributes);

                    // sendMail(getUserEmailByID(int.Parse(lastUserID)), "", "您提交的单据发生错误", "单据编号为:" + nextNode.ProcInstName);

                    throw new ApplicationException(dr.ERROR_MSG);
                }
            }
        }
Example #4
0
        public string approve(bool isApproved, string approvalComment, string userID, string userName, string processInstanceID, string proxyUserName, int OrganizationUnitID, ref string email)
        {
            try {
                if (String.IsNullOrEmpty(processInstanceID))
                {
                    throw new Exception("approve - processInstanceID is empty");
                }
                if (String.IsNullOrEmpty(userID))
                {
                    throw new Exception("approve - userID is empty");
                }
                if (String.IsNullOrEmpty(userName))
                {
                    throw new Exception("approve - userName is empty");
                }

                string where = "WF_MANUAL_WORKITEMS.PROC_INST_ID='" + processInstanceID + "' and WF_MANUAL_WORKITEMS.STATUS in ('" + WFManualWorkItem.ASSIGNED + "','" + WFManualWorkItem.OVERDUE + "','" + WFManualWorkItem.REASSIGNED + "','" + WFManualWorkItem.PSEUDO + "') and CHARINDEX('P" + userID + "P',WF_MANUAL_WORKITEMS.USER_ID)>0";
                WFManualWorkItem[] wis = api.QueryWorkListEx(where);

                if (wis.Length > 0)
                {
                    WFManualWorkItem wi = wis[0];
                    APWorkFlow.NodeStatusDataTable dt = new APWorkFlow.NodeStatusDataTable();
                    StringReader sr = new StringReader(wi.ClientData);
                    dt.ReadXml(sr);
                    APWorkFlow.NodeStatusRow dr = dt[0];
                    if (String.IsNullOrEmpty(proxyUserName))
                    {
                        dr.APPROVED_BY = userName;
                    }
                    else
                    {
                        dr.APPROVED_BY = proxyUserName + " 代理 " + userName;
                    }
                    if (String.IsNullOrEmpty(approvalComment))
                    {
                        dr.COMMENTS = "";
                    }
                    else
                    {
                        dr.COMMENTS = approvalComment;
                    }
                    dr.COMPLETED_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    if (isApproved)//若状态为通过
                    {
                        //  首先判断是否为尝试修复的
                        if (dr.STATUS.Equals(FlowNodeStatus.ONERROR))
                        {
                            // recover this node
                            System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                            attrList.Add(new NameValue("UserID", wi.OriginalUserID));
                            NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                            api.UpdateWorkItem(wi.WorkItemID, attributes);
                        }
                        else
                        {
                            dr.STATUS = FlowNodeStatus.APPROVED;//通过
                            //dr.AcceptChanges();
                            dt.AcceptChanges();
                            StringWriter sw = new StringWriter();
                            dt.WriteXml(sw);
                            string clientData = sw.ToString();                               //将信息写入XML并保存

                            WFEvent evt = api.CompleteWorkItemEx(wi.WorkItemID, clientData); //完成当前步骤
                            evt = getFullEvent(evt);
                            if (!String.IsNullOrEmpty(evt.Error))
                            {
                                throw new Exception("approve - " + evt.Error);
                            }
                        }
                    }
                    else
                    {
                        //直接取消流程

                        if (dr.STATUS.Equals(FlowNodeStatus.ONERROR))
                        {
                            dr.COMMENTS = dr.ERROR_MSG;
                        }
                        dr.STATUS = FlowNodeStatus.CANCELLED;
                        //dr.AcceptChanges();
                        dt.AcceptChanges();
                        StringWriter sw = new StringWriter();
                        dt.WriteXml(sw);
                        string clientData = sw.ToString();

                        ArrayList attrList = new ArrayList();
                        attrList.Add(new NameValue("CLIENT_DATA", clientData));
                        NameValue[] nv = (NameValue[])attrList.ToArray(typeof(NameValue));
                        api.UpdateWorkItem(wi.WorkItemID, nv);
                        WFEvent evt = api.CancelProcInst(processInstanceID);
                        evt = getFullEvent(evt);
                        if (!String.IsNullOrEmpty(evt.Error))
                        {
                            throw new Exception("approve - " + evt.Error);
                        }
                    }

                    //prepare next node

                    string nextUser = prepareNextNode(processInstanceID, userID, OrganizationUnitID, ref email);
                    //if (!String.IsNullOrEmpty(nextUser) && nextUser == "P" + userID + "P") // 如果下一步包有且只有同一个人就自动审批(后面需要在审批历史里加入自动通过的标识)
                    //    return approve(isApproved, approvalComment, userID, userName, processInstanceID, proxyUserName, OrganizationUnitID, ref email);
                    //else
                    return(nextUser);
                }
                else
                {
                    throw new Exception("approve - 用户不能操作当前流程");
                }
            } catch (Exception e) {
                if (e is ApplicationException)
                {
                    throw e;
                }
                throw new Exception(errorMSGPrefix + e.Message, e);
            }
        }
Example #5
0
        //找到下个节点
        private string prepareNextNode(string processInstanceID, string lastUserID, int OrganizationUnitID, ref string email)
        {
            WFManualWorkItem nextNode = getNextNode(processInstanceID);

            if (nextNode == null) {
                return null; //process finished

            } else {
                string participant = "";
                string participantEmail = "";
                nextNode.UserID = nextNode.UserID.Split('\\')[1].ToString();

                //translate participant(防止多个流程角色)
                string[] ids = nextNode.OriginalUserID.Split('\\')[1].ToString().Split("|".ToCharArray());
                for (int i = 0; i < ids.Length; i++) {

                    string uid = string.Empty;

                    string PositionTypeCode = ids[i].ToString();
                    getUserIDByIdentifier(PositionTypeCode, OrganizationUnitID, ref uid, ref email);

                    //当前角色下找不到人
                    if (uid == "none") {
                        continue;
                    } else {
                        participant += uid + "&";
                        participantEmail += email;
                    }
                }
                participant = participant.TrimEnd('&');
                // update workitem
                APWorkFlow.NodeStatusDataTable dt = new APWorkFlow.NodeStatusDataTable();
                APWorkFlow.NodeStatusRow dr = dt.NewNodeStatusRow();
                if (!String.IsNullOrEmpty(participant) && participant != "none") { //user found
                    dr.STATUS = FlowNodeStatus.ASSIGNED;
                    dr.PARTICIPANT = participant;
                    //dr.AcceptChanges();
                    dt.AddNodeStatusRow(dr);
                    dt.AcceptChanges();
                    StringWriter sw = new StringWriter();
                    dt.WriteXml(sw);
                    string clientData = sw.ToString();

                    System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                    attrList.Add(new NameValue("UserID", dr.PARTICIPANT));//更新该步骤的userid
                    attrList.Add(new NameValue("CLIENT_DATA", clientData));
                    NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                    api.UpdateWorkItem(nextNode.WorkItemID, attributes);
                    //update email
                    if (!String.IsNullOrEmpty(participantEmail)) {
                        email = participantEmail;
                    }
                    return dr.PARTICIPANT;
                } else { // 没有找到人员
                    dr.STATUS = FlowNodeStatus.ONERROR;
                    dr.PARTICIPANT = "P" + lastUserID + "P";
                    //dr.ERROR_MSG = "错误代码:Invalid UserId (" + nextNode.ProcInstName + "," + nextNode.OriginalUserID + "," + nextNode.UserID + ")";
                    dr.ERROR_MSG = "未能找到下一步审批人!";
                    //dr.AcceptChanges();
                    dt.AddNodeStatusRow(dr);
                    dt.AcceptChanges();
                    StringWriter sw = new StringWriter();
                    dt.WriteXml(sw);
                    string clientData = sw.ToString();

                    System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                    attrList.Add(new NameValue("UserID", dr.PARTICIPANT));
                    attrList.Add(new NameValue("CLIENT_DATA", clientData));
                    NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                    api.UpdateWorkItem(nextNode.WorkItemID, attributes);

                    // sendMail(getUserEmailByID(int.Parse(lastUserID)), "", "您提交的单据发生错误", "单据编号为:" + nextNode.ProcInstName);

                    throw new ApplicationException(dr.ERROR_MSG);
                }
            }
        }
Example #6
0
        public string approve(bool isApproved, string approvalComment, string userID, string userName, string processInstanceID, string proxyUserName, int OrganizationUnitID, ref string email)
        {
            try {
                if (String.IsNullOrEmpty(processInstanceID))
                    throw new Exception("approve - processInstanceID is empty");
                if (String.IsNullOrEmpty(userID))
                    throw new Exception("approve - userID is empty");
                if (String.IsNullOrEmpty(userName))
                    throw new Exception("approve - userName is empty");

                string where = "WF_MANUAL_WORKITEMS.PROC_INST_ID='" + processInstanceID + "' and WF_MANUAL_WORKITEMS.STATUS in ('" + WFManualWorkItem.ASSIGNED + "','" + WFManualWorkItem.OVERDUE + "','" + WFManualWorkItem.REASSIGNED + "','" + WFManualWorkItem.PSEUDO + "') and CHARINDEX('P" + userID + "P',WF_MANUAL_WORKITEMS.USER_ID)>0";
                WFManualWorkItem[] wis = api.QueryWorkListEx(where);

                if (wis.Length > 0) {
                    WFManualWorkItem wi = wis[0];
                    APWorkFlow.NodeStatusDataTable dt = new APWorkFlow.NodeStatusDataTable();
                    StringReader sr = new StringReader(wi.ClientData);
                    dt.ReadXml(sr);
                    APWorkFlow.NodeStatusRow dr = dt[0];
                    if (String.IsNullOrEmpty(proxyUserName))
                        dr.APPROVED_BY = userName;
                    else
                        dr.APPROVED_BY = proxyUserName + " 代理 " + userName;
                    if (String.IsNullOrEmpty(approvalComment))
                        dr.COMMENTS = "";
                    else
                        dr.COMMENTS = approvalComment;
                    dr.COMPLETED_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    if (isApproved)//若状态为通过
                    {
                        //  首先判断是否为尝试修复的
                        if (dr.STATUS.Equals(FlowNodeStatus.ONERROR)) {
                            // recover this node
                            System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                            attrList.Add(new NameValue("UserID", wi.OriginalUserID));
                            NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                            api.UpdateWorkItem(wi.WorkItemID, attributes);
                        } else {
                            dr.STATUS = FlowNodeStatus.APPROVED;//通过
                            //dr.AcceptChanges();
                            dt.AcceptChanges();
                            StringWriter sw = new StringWriter();
                            dt.WriteXml(sw);
                            string clientData = sw.ToString();//将信息写入XML并保存

                            WFEvent evt = api.CompleteWorkItemEx(wi.WorkItemID, clientData);//完成当前步骤
                            evt = getFullEvent(evt);
                            if (!String.IsNullOrEmpty(evt.Error))
                                throw new Exception("approve - " + evt.Error);

                        }
                    } else {
                        //直接取消流程

                        if (dr.STATUS.Equals(FlowNodeStatus.ONERROR))
                            dr.COMMENTS = dr.ERROR_MSG;
                        dr.STATUS = FlowNodeStatus.CANCELLED;
                        //dr.AcceptChanges();
                        dt.AcceptChanges();
                        StringWriter sw = new StringWriter();
                        dt.WriteXml(sw);
                        string clientData = sw.ToString();

                        ArrayList attrList = new ArrayList();
                        attrList.Add(new NameValue("CLIENT_DATA", clientData));
                        NameValue[] nv = (NameValue[])attrList.ToArray(typeof(NameValue));
                        api.UpdateWorkItem(wi.WorkItemID, nv);
                        WFEvent evt = api.CancelProcInst(processInstanceID);
                        evt = getFullEvent(evt);
                        if (!String.IsNullOrEmpty(evt.Error))
                            throw new Exception("approve - " + evt.Error);

                    }

                    //prepare next node

                    string nextUser = prepareNextNode(processInstanceID, userID, OrganizationUnitID, ref email);
                    //if (!String.IsNullOrEmpty(nextUser) && nextUser == "P" + userID + "P") // 如果下一步包有且只有同一个人就自动审批(后面需要在审批历史里加入自动通过的标识)
                    //    return approve(isApproved, approvalComment, userID, userName, processInstanceID, proxyUserName, OrganizationUnitID, ref email);
                    //else
                    return nextUser;
                } else {
                    throw new Exception("approve - 用户不能操作当前流程");
                }
            } catch (Exception e) {
                if (e is ApplicationException)
                    throw e;
                throw new Exception(errorMSGPrefix + e.Message, e);
            }
        }
Example #7
0
 //
 /// <summary>
 /// ApprovedDate【0】,LastApprover【1】,Comment【2】,ApproverIds【3】
 /// </summary>
 /// <param name="processInstanceID"></param>
 /// <returns>ApprovedDate【0】,LastApprover【1】,Comment【2】,ApproverIds【3】</returns>
 public string[] GetProcessApproveUser(string processInstanceID)
 {
     DateTime ApprovedDate = DateTime.MinValue;
     string LastApprover = "";
     string Comment = "";
     string ApproverIds = "";
     string[] ApproveInfo = new string[4];
     APWorkFlowTableAdapters.StuffUserInfoTableAdapter TAStuffUserinfo = new APWorkFlowTableAdapters.StuffUserInfoTableAdapter();
     if (String.IsNullOrEmpty(processInstanceID))
         throw new Exception("GetProcessApproveUser - processInstanceID is empty");
     string sql = "select CLIENT_DATA FROM WF_MANUAL_WORKITEMS where CLIENT_DATA like '%</APPROVED_BY>%' and PROC_INST_ID='" + processInstanceID + "' order by ASSIGNED_DATE asc";
     String[] sqlRet = api.QueryDatabaseEx(sql);
     DataTable l_dtclient = getDataTableFromXML(sqlRet[0], sqlRet[1]);
     APWorkFlow.NodeStatusDataTable l_dtapprove = new APWorkFlow.NodeStatusDataTable();
     int i = 0;
     foreach (DataRow l_dr in l_dtclient.Rows) {
         StringReader sr = new StringReader(l_dr["CLIENT_DATA"].ToString());
         l_dtapprove.ReadXml(sr);
         if (Convert.ToDateTime(l_dtapprove[0].COMPLETED_DATE) > ApprovedDate) {
             ApprovedDate = Convert.ToDateTime(l_dtapprove[0].COMPLETED_DATE);
             LastApprover = TAStuffUserinfo.GetDataByStuffName(l_dtapprove[0].APPROVED_BY)[0].StuffUserId.ToString();
             Comment = l_dtapprove[0].COMMENTS;
         }
         if (!string.IsNullOrEmpty(l_dtapprove[i].APPROVED_BY))
             ApproverIds += ("P" + TAStuffUserinfo.GetDataByStuffName(l_dtapprove[i].APPROVED_BY)[0].StuffUserId + "P");
         i++;
     }
     ApproveInfo[0] = ApprovedDate.ToString();
     ApproveInfo[1] = LastApprover;
     ApproveInfo[2] = Comment;
     ApproveInfo[3] = ApproverIds;
     return ApproveInfo;
 }
Example #8
0
        //得到审核的历史
        public APWorkFlow.NodeStatusDataTable getApprovalStatus(string processInstanceID)
        {
            try {
                if (String.IsNullOrEmpty(processInstanceID))
                    throw new Exception("getAprovalStatus - processInstanceID is empty");
                //string sql = "SELECT ASSIGNED_DATE, CANCELLED_DATE, COMPLETED_DATE, DUE_DATE, CREATED_DATE, STATUS, USER_ID, CLIENT_DATA,'' as " + StatusColumnName.APPROVED_BY + ", 0 as " + StatusColumnName.IS_APPROVED + ",'' as " + StatusColumnName.COMMENTS + " FROM WF_MANUAL_WORKITEMS where PROC_INST_ID='" + processInstanceID + "' order by ASSIGNED_DATE asc";
                string sql = "select CLIENT_DATA FROM WF_MANUAL_WORKITEMS where PROC_INST_ID='" + processInstanceID + "' order by ASSIGNED_DATE asc";
                String[] sqlRet = api.QueryDatabaseEx(sql);
                DataTable dt = getDataTableFromXML(sqlRet[0], sqlRet[1]);
                if (dt != null) {
                    APWorkFlow.NodeStatusDataTable result = new APWorkFlow.NodeStatusDataTable();
                    foreach (DataRow row in dt.Rows) {
                        string clientData;
                        try {
                            clientData = (string)row["CLIENT_DATA"];
                        } catch (Exception ee) {
                            clientData = null;
                        }
                        if (!String.IsNullOrEmpty(clientData)) {
                            APWorkFlow.NodeStatusDataTable cddt = new APWorkFlow.NodeStatusDataTable();
                            StringReader sr = new StringReader(clientData);
                            cddt.ReadXml(sr);
                            if (cddt != null && cddt.Rows.Count > 0) {
                                result.ImportRow(cddt[0]);
                            }
                        }
                    }
                    return result;
                } else {
                    return null;
                }

            } catch (Exception e) {
                throw new Exception(errorMSGPrefix + e.Message, e);
            }
        }
Example #9
0
        //如是最后一个节点 则创建一个任务
        public bool LastCreateWorkItem(string processInstanceID, int positionID, ref string approve)
        {
            try {
                string admin = (String)ConfigurationManager.AppSettings["APAdmin"];
                APWorkFlowTableAdapters.StuffUserTableAdapter TAStuffUser = new APWorkFlowTableAdapters.StuffUserTableAdapter();
                APWorkFlowTableAdapters.StuffUserAndPositionTableAdapter TAUserAndPosition = new APWorkFlowTableAdapters.StuffUserAndPositionTableAdapter();
                APWorkFlowTableAdapters.ProcessLastNameTableAdapter TAProcessLastName = new APWorkFlowTableAdapters.ProcessLastNameTableAdapter();
                APWorkFlow.StuffUserAndPositionDataTable dtStuffUserAndPosition = TAUserAndPosition.GetDataByPositionId(positionID);
                if (dtStuffUserAndPosition.Rows.Count == 0) {
                    return false;
                }
                string lastName = "";
                WFBaseProcessInstance pi = api.GetProcInst(processInstanceID);
                WFManualWorkItem wi = getNextNode(processInstanceID);
                WFBaseActivityInstance ai = api.GetActivityInst(wi.ActivityInstID);
                APWorkFlow.ProcessLastNameDataTable dtProcessLastName = TAProcessLastName.GetDataByTName(pi.DefName);
                if (dtProcessLastName.Rows.Count > 0) {
                    lastName = dtProcessLastName[0].lastName;
                    if (ai.DisplayName == lastName) {
                        WFTimeDuration td = new WFTimeDuration();
                        td.BusinessTime = false;
                        td.Length = "7";
                        td.Unit = WFTimeUnit.DAY;
                        foreach (APWorkFlow.StuffUserAndPositionRow drStuffUserAndPosition in dtStuffUserAndPosition.Rows) {
                            //获取审批人
                            approve += "P" + drStuffUserAndPosition.StuffUserId + "P";
                            //APWorkFlow.StuffUserDataTable dtUser=TAStuffUser.GetDataByID(drStuffUserAndPosition.StuffUserId);
                        }
                        WFEvent evt = api.CreateLinkedWorkItem(wi.WorkItemID, wi.Name, approve, td, wi.ClientData);
                        evt = getFullEvent(evt);
                        APWorkFlow.NodeStatusDataTable dt = new APWorkFlow.NodeStatusDataTable();
                        APWorkFlow.NodeStatusRow dr = dt.NewNodeStatusRow();

                        dr.STATUS = FlowNodeStatus.ASSIGNED;
                        dr.PARTICIPANT = approve;
                        //dr.AcceptChanges();
                        dt.AddNodeStatusRow(dr);
                        dt.AcceptChanges();
                        StringWriter sw = new StringWriter();
                        dt.WriteXml(sw);
                        string clientData = sw.ToString();

                        System.Collections.ArrayList attrList = new System.Collections.ArrayList();
                        attrList.Add(new NameValue("UserID", dr.PARTICIPANT));//更新该步骤的userid
                        attrList.Add(new NameValue("CLIENT_DATA", clientData));
                        NameValue[] attributes = (NameValue[])attrList.ToArray(typeof(NameValue));
                        api.UpdateWorkItem(evt.WorkItemID, attributes);
                        api.GetWorkItem(evt.WorkItemID).DisplayName = "总经理审批";
                        if (string.IsNullOrEmpty(evt.Error))
                            return true;
                        return false;
                    }
                }
                return false;
            } catch {
                return false;
            }
        }