Esempio n. 1
0
        /// <summary>
        /// 创建流程实例
        /// </summary>
        /// <param name="wfItem"></param>
        /// <returns></returns>
        public WfReturn CreateInstance(WfItem wfItem)
        {
            WfReturn result = new WfReturn();
            ItemState itemState = ItemState.Beginning;
            WfState wfState = WfState.Normal;
            string orderNo = string.Empty;

            try
            {
                ////判断该项目的状态是否可以操作
                DataTable dt = OracleHelper.ExecuteDataTable("select * from xm_xmxx where ItemCode in (" + wfItem.ItemCode + ")");
                WfState ItemWfState = (WfState)EnumHelper.StringValueToEnum(typeof(WfState), dt.Rows[0]["wfState"].ToString());

                if (ItemWfState != WfState.Normal)
                {
                    result.Success = false;
                    result.ResultDesc = string.Format("该项目处于{0}状态,无法操作",
                        EnumHelper.GetFieldDescription(typeof(WfState), (int)ItemWfState));
                    return result;
                }

                ////当前环节信息(0为开始环节)
                WfNode curNode = this.GetNodeInfo(this.strFlowId, wfItem.NodeId);
                if (curNode == null)
                {
                    result.Success = false;
                    result.ResultDesc = "获取当前环节信息失败!";
                    return result;
                }

                ////下一环节信息
                WfNode nextNode = null;
                string perNodeId = string.Empty;
                string nextNodeId = string.Empty;
                ////存在跳转ID
                if (!string.IsNullOrEmpty(wfItem.SwicthNode))
                {
                    perNodeId = wfItem.SwicthNode;
                    nextNodeId = wfItem.SwicthNode;
                }
                else
                {
                    perNodeId = curNode.PerNode;
                    nextNodeId = curNode.NextNode;
                }

                ////退回操作--上一结点
                if (wfItem.Result == WfResult.Return)
                    nextNode = this.GetNodeInfo(this.strFlowId, perNodeId);
                ////同意操作--下一结点
                if (wfItem.Result == WfResult.Agree)
                    nextNode = this.GetNodeInfo(this.strFlowId, nextNodeId);

                ArrayList strSql = new ArrayList();
                string tmpSql = string.Empty;

                if (curNode.PerNode == ((int)WorkFlowNode.Begin).ToString())////开始结点
                {
                    //// 1 删除该项目所有进程信息
                    tmpSql = "delete from wf_instance where itemcode = '{0}'";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode);
                    strSql.Add(tmpSql);
                    //// 2 插入开始环节的已完成记录
                    tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)"
                        + " values ('{0}','{1}',1,'{2}','{3}','{4}','{5}','{6}','{7}','{8}',sysdate,sysdate,1)";
                    tmpSql = string.Format(tmpSql, strFlowId, wfItem.ItemCode, curNode.NodeId,
                        curNode.PerNode, curNode.NextNode, wfItem.UserId, wfItem.UserName,
                        ((int)wfItem.Result).ToString(), wfItem.ResultDesc);
                    strSql.Add(tmpSql);
                    //// 3 插入下一环节的未完成记录
                    tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)"
                       + " values ('{0}','{1}',2,'{2}','{3}','{4}','','','','',sysdate,'',0)";
                    tmpSql = string.Format(tmpSql, strFlowId, wfItem.ItemCode, nextNode.NodeId,
                        nextNode.PerNode, nextNode.NextNode);
                    strSql.Add(tmpSql);
                    itemState = ItemState.Progressing;
                    wfState = WfState.Normal;
                }
                else ////任务结点
                {
                    //// 更新项目进程表中当前环节的状态
                    tmpSql = "update wf_instance set enddate = sysdate, state = 1,userid = '{2}',username = '******',result = '{4}', resultdesc = '{5}'"
                          + " where itemCode in ({0}) and nodeid = {1} and state = 0";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode, wfItem.NodeId, wfItem.UserId, wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc);
                    strSql.Add(tmpSql);

                    //// 插入下一环节的进程信息
                    if (wfItem.Result != WfResult.Delete)
                    {
                        tmpSql = "delete from wf_instance where itemCode in ({0}) and nodeid = {1} and state = 0";
                        tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.NodeId);
                        strSql.Add(tmpSql);

                        ////针对批量操作
                        string[] itemAry = wfItem.ItemCode.Split(',');

                        for (int i = 0; i < itemAry.Length; i++)
                        {
                            orderNo = getOrdernoByItem(itemAry[i]);
                            //// 插入下一环节的未完成记录
                            tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)"
                               + " values ('{0}','{1}','{2}','{3}','{4}','{5}','','','','',sysdate,'',0)";
                            tmpSql = string.Format(tmpSql, strFlowId, itemAry[i], orderNo, nextNode.NodeId,
                                nextNode.PerNode, nextNode.NextNode);
                            strSql.Add(tmpSql);
                        }
                    }
                    if (nextNode != null)
                    {
                        if (nextNode.NodeType == NodeType.EndNode)
                        {
                            tmpSql = "update wf_instance set enddate = sysdate, state = 1,userid = '{2}',username = '******',result = '{4}', resultdesc = '{5}'"
                                   + " where itemCode in ({0}) and nodeid = {1} and state = 0";
                            tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.NodeId, wfItem.UserId,
                                wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc);
                            strSql.Add(tmpSql);
                        }
                    }

                    switch (wfItem.Result)
                    {
                        case WfResult.Agree:
                            if (nextNode.NodeType == NodeType.EndNode)
                            {
                                wfState = WfState.Normal;
                                itemState = ItemState.Ending;
                            }
                            else
                            {
                                wfState = WfState.Normal;
                                itemState = ItemState.Progressing;
                            }
                            break;
                        case WfResult.Return:
                            wfState = WfState.Normal;
                            itemState = ItemState.Progressing;
                            break;
                        case WfResult.Delete:
                            wfState = WfState.Delete;
                            itemState = ItemState.Ending;
                            break;
                    }
                }

                if (wfItem.Result == WfResult.Delete)
                {
                    tmpSql = "update xm_xmxx set itemstate = '{1}', wfstate = '{2}', ItemDesc = '{3}',read = 0 where ItemCode in ({0})";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode, ((int)itemState).ToString(), ((int)wfState).ToString(), wfItem.ResultDesc);
                    strSql.Add(tmpSql);
                }
                else
                {
                    //// 更新项目主表的状态标识
                    tmpSql = "update xm_xmxx set itemstage = '{1}', nodeid = '{2}', itemstate = '{3}', wfstate = '{4}',read = 0  where ItemCode in ({0})";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.Stage, nextNode.NodeId, ((int)itemState).ToString(), ((int)wfState).ToString());
                    strSql.Add(tmpSql);
                }

                bool succ = OracleHelper.ExecuteCommand(strSql);

                if (succ)
                {
                    if (curNode.NotifyType != string.Empty && nextNode != null)////有消息发送设置
                    {
                        ////发送消息
                        this.notifyUser(curNode, nextNode, wfItem);
                    }
                    result.Success = true;
                    result.ResultDesc = "成功";
                    if (nextNode != null)
                    {
                        result.Stage = nextNode.Stage;
                        result.NodeName = nextNode.NodeName;
                        this.changeNodeQx(wfItem.ItemCode.Split(',')[0], ref nextNode);
                        result.DepartList = this.getItemName(1, nextNode.NodeDepartCode);
                        result.RoleList = this.getItemName(2, nextNode.NodeRoleId);
                        result.UserList = this.getItemName(3, nextNode.NodeUserId);
                    }
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
            return result;
        }
Esempio n. 2
0
        /// <summary>
        /// 创建流程实例
        /// </summary>
        /// <param name="wfItem"></param>
        /// <returns></returns>
        public WfReturn CreateInstance(WfItem wfItem)
        {
            WfReturn  result    = new WfReturn();
            ItemState itemState = ItemState.Beginning;
            WfState   wfState   = WfState.Normal;
            string    orderNo   = string.Empty;

            try
            {
                ////判断该项目的状态是否可以操作
                DataTable dt          = OracleHelper.ExecuteDataTable("select * from xm_xmxx where ItemCode in (" + wfItem.ItemCode + ")");
                WfState   ItemWfState = (WfState)EnumHelper.StringValueToEnum(typeof(WfState), dt.Rows[0]["wfState"].ToString());

                if (ItemWfState != WfState.Normal)
                {
                    result.Success    = false;
                    result.ResultDesc = string.Format("该项目处于{0}状态,无法操作",
                                                      EnumHelper.GetFieldDescription(typeof(WfState), (int)ItemWfState));
                    return(result);
                }

                ////当前环节信息(0为开始环节)
                WfNode curNode = this.GetNodeInfo(this.strFlowId, wfItem.NodeId);
                if (curNode == null)
                {
                    result.Success    = false;
                    result.ResultDesc = "获取当前环节信息失败!";
                    return(result);
                }

                ////下一环节信息
                WfNode nextNode   = null;
                string perNodeId  = string.Empty;
                string nextNodeId = string.Empty;
                ////存在跳转ID
                if (!string.IsNullOrEmpty(wfItem.SwicthNode))
                {
                    perNodeId  = wfItem.SwicthNode;
                    nextNodeId = wfItem.SwicthNode;
                }
                else
                {
                    perNodeId  = curNode.PerNode;
                    nextNodeId = curNode.NextNode;
                }

                ////退回操作--上一结点
                if (wfItem.Result == WfResult.Return)
                {
                    nextNode = this.GetNodeInfo(this.strFlowId, perNodeId);
                }
                ////同意操作--下一结点
                if (wfItem.Result == WfResult.Agree)
                {
                    nextNode = this.GetNodeInfo(this.strFlowId, nextNodeId);
                }

                ArrayList strSql = new ArrayList();
                string    tmpSql = string.Empty;

                if (curNode.PerNode == ((int)WorkFlowNode.Begin).ToString())////开始结点
                {
                    //// 1 删除该项目所有进程信息
                    tmpSql = "delete from wf_instance where itemcode = '{0}'";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode);
                    strSql.Add(tmpSql);
                    //// 2 插入开始环节的已完成记录
                    tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)"
                             + " values ('{0}','{1}',1,'{2}','{3}','{4}','{5}','{6}','{7}','{8}',sysdate,sysdate,1)";
                    tmpSql = string.Format(tmpSql, strFlowId, wfItem.ItemCode, curNode.NodeId,
                                           curNode.PerNode, curNode.NextNode, wfItem.UserId, wfItem.UserName,
                                           ((int)wfItem.Result).ToString(), wfItem.ResultDesc);
                    strSql.Add(tmpSql);
                    //// 3 插入下一环节的未完成记录
                    tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)"
                             + " values ('{0}','{1}',2,'{2}','{3}','{4}','','','','',sysdate,'',0)";
                    tmpSql = string.Format(tmpSql, strFlowId, wfItem.ItemCode, nextNode.NodeId,
                                           nextNode.PerNode, nextNode.NextNode);
                    strSql.Add(tmpSql);
                    itemState = ItemState.Progressing;
                    wfState   = WfState.Normal;
                }
                else ////任务结点
                {
                    //// 更新项目进程表中当前环节的状态
                    tmpSql = "update wf_instance set enddate = sysdate, state = 1,userid = '{2}',username = '******',result = '{4}', resultdesc = '{5}'"
                             + " where itemCode in ({0}) and nodeid = {1} and state = 0";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode, wfItem.NodeId, wfItem.UserId, wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc);
                    strSql.Add(tmpSql);

                    //// 插入下一环节的进程信息
                    if (wfItem.Result != WfResult.Delete)
                    {
                        tmpSql = "delete from wf_instance where itemCode in ({0}) and nodeid = {1} and state = 0";
                        tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.NodeId);
                        strSql.Add(tmpSql);

                        ////针对批量操作
                        string[] itemAry = wfItem.ItemCode.Split(',');

                        for (int i = 0; i < itemAry.Length; i++)
                        {
                            orderNo = getOrdernoByItem(itemAry[i]);
                            //// 插入下一环节的未完成记录
                            tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)"
                                     + " values ('{0}','{1}','{2}','{3}','{4}','{5}','','','','',sysdate,'',0)";
                            tmpSql = string.Format(tmpSql, strFlowId, itemAry[i], orderNo, nextNode.NodeId,
                                                   nextNode.PerNode, nextNode.NextNode);
                            strSql.Add(tmpSql);
                        }
                    }
                    if (nextNode != null)
                    {
                        if (nextNode.NodeType == NodeType.EndNode)
                        {
                            tmpSql = "update wf_instance set enddate = sysdate, state = 1,userid = '{2}',username = '******',result = '{4}', resultdesc = '{5}'"
                                     + " where itemCode in ({0}) and nodeid = {1} and state = 0";
                            tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.NodeId, wfItem.UserId,
                                                   wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc);
                            strSql.Add(tmpSql);
                        }
                    }

                    switch (wfItem.Result)
                    {
                    case WfResult.Agree:
                        if (nextNode.NodeType == NodeType.EndNode)
                        {
                            wfState   = WfState.Normal;
                            itemState = ItemState.Ending;
                        }
                        else
                        {
                            wfState   = WfState.Normal;
                            itemState = ItemState.Progressing;
                        }
                        break;

                    case WfResult.Return:
                        wfState   = WfState.Normal;
                        itemState = ItemState.Progressing;
                        break;

                    case WfResult.Delete:
                        wfState   = WfState.Delete;
                        itemState = ItemState.Ending;
                        break;
                    }
                }

                if (wfItem.Result == WfResult.Delete)
                {
                    tmpSql = "update xm_xmxx set itemstate = '{1}', wfstate = '{2}', ItemDesc = '{3}',read = 0 where ItemCode in ({0})";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode, ((int)itemState).ToString(), ((int)wfState).ToString(), wfItem.ResultDesc);
                    strSql.Add(tmpSql);
                }
                else
                {
                    //// 更新项目主表的状态标识
                    tmpSql = "update xm_xmxx set itemstage = '{1}', nodeid = '{2}', itemstate = '{3}', wfstate = '{4}',read = 0  where ItemCode in ({0})";
                    tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.Stage, nextNode.NodeId, ((int)itemState).ToString(), ((int)wfState).ToString());
                    strSql.Add(tmpSql);
                }

                bool succ = OracleHelper.ExecuteCommand(strSql);

                if (succ)
                {
                    if (curNode.NotifyType != string.Empty && nextNode != null)////有消息发送设置
                    {
                        ////发送消息
                        this.notifyUser(curNode, nextNode, wfItem);
                    }
                    result.Success    = true;
                    result.ResultDesc = "成功";
                    if (nextNode != null)
                    {
                        result.Stage    = nextNode.Stage;
                        result.NodeName = nextNode.NodeName;
                        this.changeNodeQx(wfItem.ItemCode.Split(',')[0], ref nextNode);
                        result.DepartList = this.getItemName(1, nextNode.NodeDepartCode);
                        result.RoleList   = this.getItemName(2, nextNode.NodeRoleId);
                        result.UserList   = this.getItemName(3, nextNode.NodeUserId);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 站内发送短消息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="wfItem"></param>
        private void notifyUser(WfNode curNode, WfNode nextNode, WfItem wfItem)
        {
            string[] notifyAry = curNode.NotifyType.Split(new char[] { ',' });
            string msg = string.Empty;
            List<string> userId = new List<string>();
            string[] itemAry = wfItem.ItemCode.Split(',');

            for (int i = 0; i < itemAry.Length; i++)
            {
                string itemName = this.getItemName(itemAry[i]);

                List<string> beginuserId = new List<string>();
                List<string> nextuserId = new List<string>();
                List<string> historyuserId = new List<string>();

                if (curNode.NodeType == NodeType.BeginNode)////开始结点
                {
                    //beginuserId = wfItem.UserId;
                    //historyuserId = wfItem.UserId;
                }
                else
                {
                    beginuserId = this.getBeginUserId(itemAry[i]);
                    historyuserId = this.getHistoryUserId(itemAry[i]);
                }
                if (nextNode != null)
                    nextuserId = this.getUserId(itemAry[i], nextNode.NodeDepartCode, nextNode.NodeRoleId, nextNode.NodeUserId);

                for (int j = 0; j < notifyAry.Length; j++)
                {
                    WfNotifyType notifyEnum = (WfNotifyType)EnumHelper.StringValueToEnum(typeof(WfNotifyType), notifyAry[j]);
                    switch (notifyEnum)
                    {
                        case WfNotifyType.Begin:
                            msg = curNode.BeginText.Replace("{wf_username}", wfItem.UserName)
                                .Replace("{wf_time}", DateTime.Now.ToString())
                                .Replace("{wf_title}", itemName)
                                .Replace("{wf_stage}",
                                string.Format("{0}-{1}",
                                EnumHelper.GetFieldDescription(typeof(ItemStage), int.Parse(nextNode.Stage)),
                                EnumHelper.GetFieldDescription(typeof(WorkFlowNode),int.Parse(nextNode.NodeId))));
                            userId = beginuserId;
                            break;
                        case WfNotifyType.Next:
                            msg = curNode.NextText.Replace("{wf_title}", itemName)
                                .Replace("{wf_timeout}", nextNode.TimeOut.Equals("0") ? "无" : string.Format("{0}天", nextNode.TimeOut));
                            userId = nextuserId;
                            break;
                        case WfNotifyType.History:
                            msg = curNode.HistoryText.Replace("{wf_username}", wfItem.UserName)
                                .Replace("{wf_time}", DateTime.Now.ToString())
                                .Replace("{wf_title}", itemName);
                            userId = historyuserId;
                            break;
                    }
                    if (msg != string.Empty || userId.Count > 0)
                    {
                        this.SendMessage(userId, msg);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 站内发送短消息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="wfItem"></param>
        private void notifyUser(WfNode curNode, WfNode nextNode, WfItem wfItem)
        {
            string[]      notifyAry = curNode.NotifyType.Split(new char[] { ',' });
            string        msg       = string.Empty;
            List <string> userId    = new List <string>();

            string[] itemAry = wfItem.ItemCode.Split(',');

            for (int i = 0; i < itemAry.Length; i++)
            {
                string itemName = this.getItemName(itemAry[i]);

                List <string> beginuserId   = new List <string>();
                List <string> nextuserId    = new List <string>();
                List <string> historyuserId = new List <string>();

                if (curNode.NodeType == NodeType.BeginNode)////开始结点
                {
                    //beginuserId = wfItem.UserId;
                    //historyuserId = wfItem.UserId;
                }
                else
                {
                    beginuserId   = this.getBeginUserId(itemAry[i]);
                    historyuserId = this.getHistoryUserId(itemAry[i]);
                }
                if (nextNode != null)
                {
                    nextuserId = this.getUserId(itemAry[i], nextNode.NodeDepartCode, nextNode.NodeRoleId, nextNode.NodeUserId);
                }

                for (int j = 0; j < notifyAry.Length; j++)
                {
                    WfNotifyType notifyEnum = (WfNotifyType)EnumHelper.StringValueToEnum(typeof(WfNotifyType), notifyAry[j]);
                    switch (notifyEnum)
                    {
                    case WfNotifyType.Begin:
                        msg = curNode.BeginText.Replace("{wf_username}", wfItem.UserName)
                              .Replace("{wf_time}", DateTime.Now.ToString())
                              .Replace("{wf_title}", itemName)
                              .Replace("{wf_stage}",
                                       string.Format("{0}-{1}",
                                                     EnumHelper.GetFieldDescription(typeof(ItemStage), int.Parse(nextNode.Stage)),
                                                     EnumHelper.GetFieldDescription(typeof(WorkFlowNode), int.Parse(nextNode.NodeId))));
                        userId = beginuserId;
                        break;

                    case WfNotifyType.Next:
                        msg = curNode.NextText.Replace("{wf_title}", itemName)
                              .Replace("{wf_timeout}", nextNode.TimeOut.Equals("0") ? "无" : string.Format("{0}天", nextNode.TimeOut));
                        userId = nextuserId;
                        break;

                    case WfNotifyType.History:
                        msg = curNode.HistoryText.Replace("{wf_username}", wfItem.UserName)
                              .Replace("{wf_time}", DateTime.Now.ToString())
                              .Replace("{wf_title}", itemName);
                        userId = historyuserId;
                        break;
                    }
                    if (msg != string.Empty || userId.Count > 0)
                    {
                        this.SendMessage(userId, msg);
                    }
                }
            }
        }