Beispiel #1
0
        /// <summary>
        /// 恢复已完成的流程数据到指定的节点,如果节点为0就恢复到最后一个完成的节点上去.
        /// </summary>
        /// <param name="workid">要恢复的workid</param>
        /// <param name="backToNodeID">恢复到的节点编号,如果是0,标示回复到流程最后一个节点上去.</param>
        /// <param name="note"></param>
        /// <returns></returns>
        public string DoRebackFlowData(Int64 workid, int backToNodeID, string note)
        {
            if (note.Length <= 2)
            {
                return("请填写恢复已完成的流程原因.");
            }

            Flow fl = new Flow(this.No);

            GERpt rpt = new GERpt("ND" + int.Parse(this.No) + "Rpt");

            rpt.OID = workid;
            int i = rpt.RetrieveFromDBSources();

            if (i == 0)
            {
                throw new Exception("@错误,流程数据丢失。");
            }
            if (backToNodeID == 0)
            {
                backToNodeID = rpt.FlowEndNode;
            }

            Emp empStarter = new Emp(rpt.FlowStarter);

            // 最后一个节点.
            Node          endN = new Node(backToNodeID);
            GenerWorkFlow gwf  = null;

            try
            {
                #region 创建流程引擎主表数据.
                gwf        = new GenerWorkFlow();
                gwf.WorkID = workid;
                if (gwf.RetrieveFromDBSources() == 1)
                {
                    throw new Exception("@当前工作ID为:" + workid + "的流程没有结束,不能采用此方法恢复。");
                }

                gwf.FK_Flow  = this.No;
                gwf.FlowName = this.Name;
                gwf.WorkID   = workid;
                gwf.PWorkID  = rpt.PWorkID;
                gwf.PFlowNo  = rpt.PFlowNo;
                gwf.FK_Node  = backToNodeID;
                gwf.NodeName = endN.Name;

                gwf.Starter     = rpt.FlowStarter;
                gwf.StarterName = empStarter.Name;
                gwf.FK_FlowSort = fl.FK_FlowSort;
                gwf.Title       = rpt.Title;
                gwf.WFState     = WFState.ReturnSta; /*设置为退回的状态*/
                gwf.FK_Dept     = rpt.FK_Dept;

                Dept dept = new Dept(empStarter.FK_Dept);

                gwf.DeptName = dept.Name;
                gwf.PRI      = 1;

                DateTime dttime = DateTime.Now;
                dttime = dttime.AddDays(3);

                gwf.SDTOfNode = dttime.ToString("yyyy-MM-dd");
                gwf.SDTOfFlow = dttime.ToString("yyyy-MM-dd");
                gwf.Insert(); /*插入流程引擎数据.*/

                #endregion 创建流程引擎主表数据

                int    startNode  = int.Parse(this.No + "01");
                string ndTrack    = "ND" + int.Parse(this.No) + "Track";
                string actionType = (int)ActionType.Forward + "," + (int)ActionType.FlowOver + "," + (int)ActionType.ForwardFL + "," + (int)ActionType.ForwardHL;
                // string actionType = " NDFrom=" + (int)ActionType.Forward + " OR NDFrom=" + (int)ActionType.FlowOver + " OR NDFrom=" + (int)ActionType.ForwardFL + " OR NDFrom=" + (int)ActionType.ForwardHL;
                string sql = "SELECT  * FROM " + ndTrack + " WHERE   ActionType IN (" + actionType + ")  and WorkID=" + workid + " ORDER BY RDT DESC, NDFrom ";
                System.Data.DataTable dt = DBAccess.RunSQLReturnTable(sql);
                if (dt.Rows.Count == 0)
                {
                    throw new Exception("@工作ID为:" + workid + "的数据不存在.");
                }

                string          starter        = "";
                bool            isMeetSpecNode = false;
                GenerWorkerList currWl         = new GenerWorkerList();
                foreach (DataRow dr in dt.Rows)
                {
                    int  ndFrom = int.Parse(dr["NDFrom"].ToString());
                    Node nd     = new Node(ndFrom);

                    string ndFromT = dr["NDFromT"].ToString();

                    string EmpFrom  = dr[TrackAttr.EmpFrom].ToString();
                    string EmpFromT = dr[TrackAttr.EmpFromT].ToString();

                    // 增加上 工作人员的信息.
                    GenerWorkerList gwl = new GenerWorkerList();
                    gwl.WorkID  = workid;
                    gwl.FK_Flow = this.No;

                    gwl.FK_Node     = ndFrom;
                    gwl.FK_NodeText = ndFromT;

                    if (gwl.FK_Node == backToNodeID)
                    {
                        gwl.IsPass = false;
                        currWl     = gwl;
                    }

                    gwl.FK_Emp     = EmpFrom;
                    gwl.FK_EmpText = EmpFromT;
                    if (gwl.IsExits)
                    {
                        continue; /*有可能是反复退回的情况.*/
                    }
                    Emp emp = new Emp(gwl.FK_Emp);
                    gwl.FK_Dept1 = emp.FK_Dept;

                    gwl.RDT         = dr["RDT"].ToString();
                    gwl.SDT         = dr["RDT"].ToString();
                    gwl.DTOfWarning = gwf.SDTOfNode;
                    gwl.WarningDays = nd.WarningDays;
                    gwl.IsEnable    = true;
                    gwl.WhoExeIt    = nd.WhoExeIt;
                    gwl.Insert();
                }

                #region 加入退回信息, 让接受人能够看到退回原因.
                ReturnWork rw = new ReturnWork();
                rw.WorkID         = workid;
                rw.ReturnNode     = backToNodeID;
                rw.ReturnNodeName = endN.Name;
                rw.Returner       = WebUser.No;
                rw.ReturnerName   = WebUser.Name;

                rw.ReturnToNode   = currWl.FK_Node;
                rw.ReturnToEmp    = currWl.FK_Emp;
                rw.Note           = note;
                rw.RDT            = DataType.CurrentDataTime;
                rw.IsBackTracking = false;
                rw.MyPK           = BP.DA.DBAccess.GenerGUID();
                #endregion   加入退回信息, 让接受人能够看到退回原因.

                //更新流程表的状态.
                rpt.FlowEnder   = currWl.FK_Emp;
                rpt.WFState     = WFState.ReturnSta; /*设置为退回的状态*/
                rpt.FlowEndNode = currWl.FK_Node;
                rpt.Update();

                // 向接受人发送一条消息.
                BP.WF.Dev2Interface.Port_SendMail(currWl.FK_Emp, "工作恢复:" + gwf.Title, "工作被:" + WebUser.No + " 恢复." + note, "ReBack" + workid, this.No, int.Parse(this.No + "01"), workid, 0);

                //写入该日志.
                WorkNode wn = new WorkNode(workid, currWl.FK_Node);
                wn.AddToTrack(ActionType.RebackOverFlow, currWl.FK_Emp, currWl.FK_EmpText, currWl.FK_Node, currWl.FK_NodeText, note);

                return("@已经还原成功,现在的流程已经复原到(" + currWl.FK_NodeText + "). @当前工作处理人为(" + currWl.FK_Emp + " , " + currWl.FK_EmpText + ")  @请通知他处理工作.");
            }
            catch (Exception ex)
            {
                gwf.Delete();
                GenerWorkerList wl = new GenerWorkerList();
                wl.Delete(GenerWorkerListAttr.WorkID, workid);

                string sqls = "";
                sqls += "@UPDATE " + fl.PTable + " SET WFState=" + (int)WFState.Complete + " WHERE OID=" + workid;
                DBAccess.RunSQLs(sqls);
                return("<font color=red>会滚期间出现错误</font><hr>" + ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string    strsql = @"select * from WF_GenerWorkFlow where WorkID not in (
select distinct WorkID from WF_GenerWorkerlist) and WFState<> 3 and WFState<>7 and RDT > '2014-10-01 00:00' order by RDT desc ";
            DataTable dt     = DBAccess.RunSQLReturnTable(strsql);

            foreach (DataRow row in dt.Rows)
            {
                string empwors = row["TodoEmps"].ToString();
                if (!string.IsNullOrEmpty(empwors))
                {
                    string[] emps = empwors.Split(';');
                    if (emps != null && emps.Length > 0)
                    {
                        foreach (string str in emps)
                        {
                            if (!string.IsNullOrEmpty(str))
                            {
                                string[] emp = str.Split(',');
                                BP.WF.GenerWorkerList list = new GenerWorkerList();
                                list.WorkID      = Convert.ToInt64(row["WorkID"].ToString());
                                list.FK_Emp      = emp[0];
                                list.FK_EmpText  = emp[1];
                                list.FK_Node     = Convert.ToInt32(row["FK_Node"].ToString());
                                list.FK_NodeText = row["NodeName"].ToString();
                                list.FID         = Convert.ToInt64(row["FID"].ToString());
                                list.FK_Flow     = row["FK_Flow"].ToString();
                                list.FK_Dept     = row["FK_Dept"].ToString();
                                list.SDT         = row["SDTOfNode"].ToString();
                                list.DTOfWarning = row["SDTOfFlow"].ToString();
                                list.WarningHour = 0;
                                list.RDT         = row["RDT"].ToString();
                                list.IsEnable    = true;
                                list.IsPass      = false;
                                list.WhoExeIt    = 0;
                                list.Sender      = row["Starter"].ToString();
                                list.PRI         = 1;
                                list.IsRead      = false;
                                list.PressTimes  = 0;
                                list.HungUpTimes = 0;
                                list.CDT         = row["RDT"].ToString();
                                list.Insert();
                            }
                        }
                    }
                }
            }

            try
            {
                string url = "../WF/WFRpt.aspx?DoType=View&WorkID={0}&FK_Flow={1}&FK_Node={2}";
                string sql = "SELECT top 1 OID FROM RMS.dbo.V_FlowData WHERE ProjNo in (SELECT ProjNo FROM ND137Rpt WHERE OID='{0}') AND FK_Flow='{1}' ORDER BY OID DESC";
                //列表展示
                if (this.FrmView == "1")
                {
                    sql = "SELECT ProjNo FROM ND137Rpt WHERE OID='{0}'";
                    sql = string.Format(sql, this.WorkID);
                    string projNo = DBAccess.RunSQLReturnStringIsNull(sql, "0");
                    url = "ProjectInfoView.aspx?FK_Flow=" + this.FK_Flow + "&id=" + projNo;
                    Response.Redirect(url);
                }
                else
                {
                    //如果传入项目编号,直接使用
                    if (string.IsNullOrEmpty(this.ProjNo))
                    {
                        sql = string.Format(sql, this.WorkID, this.FK_Flow);
                    }
                    else
                    {
                        sql = "SELECT top 1 OID FROM RMS.dbo.V_FlowData WHERE ProjNo ='" + this.ProjNo + "' AND FK_Flow='" + this.FK_Flow + "' ORDER BY OID DESC";
                    }
                    //查到信息进行跳转,查不到进行提示
                    string OID = BP.DA.DBAccess.RunSQLReturnString(sql);
                    if (!string.IsNullOrEmpty(OID))
                    {
                        url = string.Format(url, OID, this.FK_Flow, this.FK_Node);
                        Response.Redirect(url);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            Response.Write("所选信息不存在!");
        }