public IActionResult InstanceManage()
        {
            string groupId = Request.Querys("groupid");

            Business.FlowTask flowTask = new Business.FlowTask();
            var groupTasks             = flowTask.GetListByGroupId(groupId.ToGuid());

            Newtonsoft.Json.Linq.JArray jArray = new Newtonsoft.Json.Linq.JArray();
            foreach (var groupTask in groupTasks)
            {
                Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject();
                string opation = "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"cngStatus('" + groupTask.Id.ToString() + "');\"><i class=\"fa fa-exclamation\"></i>状态</a>";
                if (groupTask.ExecuteType.In(0, 1) && 5 != groupTask.TaskType)
                {
                    opation += "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"designate('" + groupTask.Id.ToString() + "');\"><i class=\"fa fa-hand-o-right\"></i>指派</a>"
                               + "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"goTo('" + groupTask.Id.ToString() + "');\"><i class=\"fa fa-level-up\"></i>跳转</a>";
                }
                jObject.Add("id", groupTask.Id);
                jObject.Add("StepID", groupTask.StepName);
                jObject.Add("SenderName", groupTask.SenderName);
                jObject.Add("ReceiveTime", groupTask.ReceiveTime.ToDateTimeString());
                jObject.Add("ReceiveName", groupTask.ReceiveName);
                jObject.Add("CompletedTime1", groupTask.CompletedTime1.HasValue ? groupTask.CompletedTime1.Value.ToDateTimeString() : "");
                jObject.Add("Status", flowTask.GetExecuteTypeTitle(groupTask.ExecuteType));
                jObject.Add("Comment", groupTask.Comments);
                jObject.Add("Note", groupTask.Note);
                jObject.Add("Opation", opation);
                jArray.Add(jObject);
            }
            ViewData["json"]     = jArray.ToString();
            ViewData["appid"]    = Request.Querys("appid");
            ViewData["iframeid"] = Request.Querys("iframeid");
            return(View());
        }
        public string Withdraw()
        {
            string withdrawtaskid  = Request.Querys("withdrawtaskid");
            string withdrawgroupid = Request.Querys("withdrawgroupid");

            if (!withdrawgroupid.IsGuid(out Guid groupId) || !withdrawtaskid.IsGuid(out Guid taskId))
            {
                return("任务Id错误!");
            }
            Business.FlowTask flowTask = new Business.FlowTask();
            var groupTasks             = flowTask.GetListByGroupId(groupId);
            var tasks = groupTasks.FindAll(p => p.PrevId == taskId && p.Status == 0);
            List <Model.FlowTask> removeTasks = new List <Model.FlowTask>();

            foreach (var task in tasks)
            {
                removeTasks.Add(task);
            }
            List <Model.FlowTask> updateTasks = new List <Model.FlowTask>();
            var currentTask = groupTasks.Find(p => p.Id == taskId);

            if (null == currentTask)
            {
                return("未找到当前任务!");
            }
            currentTask.Status         = 0;
            currentTask.ExecuteType    = 0;
            currentTask.Comments       = "";
            currentTask.IsSign         = 0;
            currentTask.CompletedTime1 = new DateTime?();
            updateTasks.Add(currentTask);
            flowTask.Update(removeTasks, updateTasks, null, null);
            return("收回成功!");
        }
        public string HastenSave()
        {
            string hastentaskid  = Request.Querys("hastentaskid");
            string hastengroupid = Request.Querys("hastengroupid");

            if (!hastengroupid.IsGuid(out Guid groupId) || !hastentaskid.IsGuid(out Guid taskId))
            {
                return("Id错误!");
            }
            string Users    = Request.Forms("Users");
            string Model    = Request.Forms("Model");
            string Contents = Request.Forms("Contents");

            Business.FlowTask flowTask = new Business.FlowTask();
            //得到可以催办的人员
            var groupTasks  = flowTask.GetListByGroupId(groupId);
            var hastenTasks = groupTasks.FindAll(p => p.PrevId == taskId && p.Status.In(0, 1));
            List <Model.FlowTask> hastenTasks1 = new List <Model.FlowTask>();

            foreach (var task in hastenTasks)
            {
                if (task.Status.In(0, 1) && Users.ContainsIgnoreCase(task.ReceiveId.ToString()))
                {
                    hastenTasks1.Add(task);
                }
            }

            flowTask.SendMessage(hastenTasks1, Current.User, Model, Contents);
            return("催办成功!");
        }
        public IActionResult Hasten()
        {
            string hastentaskid  = Request.Querys("hastentaskid");
            string hastengroupid = Request.Querys("hastengroupid");

            if (!hastengroupid.IsGuid(out Guid groupId) || !hastentaskid.IsGuid(out Guid taskId))
            {
                return(new ContentResult()
                {
                    Content = "任务Id错误!"
                });
            }
            Business.FlowTask flowTask = new Business.FlowTask();
            //得到可以催办的人员
            var           groupTasks    = flowTask.GetListByGroupId(groupId);
            var           hastenTasks   = groupTasks.FindAll(p => p.PrevId == taskId && p.Status.In(0, 1));
            List <Guid>   userIds       = new List <Guid>();
            StringBuilder stringBuilder = new StringBuilder();

            foreach (var task in hastenTasks)
            {
                if (task.Status.In(0, 1) && !userIds.Contains(task.ReceiveId))
                {
                    userIds.Add(task.ReceiveId);
                    stringBuilder.Append("<input checked=\"checked\" type=\"checkbox\" style=\"vertical-align:middle;\" value=\"" + Business.Organize.PREFIX_USER + task.ReceiveId.ToString() + "\" name=\"Users\" id=\"Users_" + task.ReceiveId.ToString("N") + "\" /><label style=\"vertical-align:middle;\" for=\"Users_" + task.ReceiveId.ToString("N") + "\">" + task.ReceiveName + "</label>");
                }
            }
            ViewData["Users"]       = stringBuilder.ToString();
            ViewData["Contents"]    = "您有一个待办事项“" + (hastenTasks.Any() ? hastenTasks.First().Title : "") + "”,请尽快处理!";
            ViewData["queryString"] = Request.UrlQuery();
            return(View());
        }
        public string DeleteInstance()
        {
            string groupId = Request.Querys("groupid");

            if (!groupId.IsGuid(out Guid guid))
            {
                return("组ID错误!");
            }
            Business.FlowTask flowTask = new Business.FlowTask();
            var groupTasks             = flowTask.GetListByGroupId(guid);

            if (groupTasks.Count > 0)
            {
                flowTask.DeleteByGroupId(groupTasks.ToArray());

                Business.Log.Add("删除了流程实例-" + groupTasks.First().Title, Newtonsoft.Json.JsonConvert.SerializeObject(groupTasks), Business.Log.Type.流程运行);
            }
            return("删除成功!");
        }
        public IActionResult DetailSubFlow()
        {
            string taskid   = Request.Querys("taskid");
            string ismobile = Request.Querys("ismobile");

            if (!taskid.IsGuid(out Guid taskId))
            {
                return(new ContentResult()
                {
                    Content = "任务ID错误!"
                });
            }
            Business.FlowTask flowTask = new Business.FlowTask();
            var currentTask            = flowTask.Get(taskId);

            if (null == currentTask)
            {
                return(new ContentResult()
                {
                    Content = "未找到当前任务!"
                });
            }
            if (currentTask.SubFlowGroupId.IsNullOrWhiteSpace())
            {
                return(new ContentResult()
                {
                    Content = "未找到当前任务的子流程任务!"
                });
            }
            string[] subFlowGroupIds = currentTask.SubFlowGroupId.Split(',');

            if (subFlowGroupIds.Length == 1)
            {
                var groupTasks = flowTask.GetListByGroupId(subFlowGroupIds[0].ToGuid());
                if (groupTasks.Count > 0)
                {
                    return(Redirect("Detail?flowid=" + groupTasks.First().FlowId + "&stepid=" + groupTasks.First().StepId +
                                    "&groupid=" + subFlowGroupIds[0] + "&taskid=" + groupTasks.First().Id + "&appid=" + Request.Querys("appid")
                                    + "&tabid=" + Request.Querys("tabid") + "&iframeid=" + Request.Querys("iframeid") + "&ismobile=" + ismobile));
                }
            }
            else
            {
                Newtonsoft.Json.Linq.JArray jArray = new Newtonsoft.Json.Linq.JArray();
                foreach (var id in subFlowGroupIds)
                {
                    var groupTasks = flowTask.GetListByGroupId(id.ToGuid());
                    if (groupTasks.Count == 0)
                    {
                        continue;
                    }
                    var groupTask = groupTasks.First();
                    Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject
                    {
                        { "FlowName", groupTask.FlowName },
                        { "StepName", groupTask.StepName },
                        { "SenderName", groupTask.SenderName },
                        { "SenderTime", groupTask.ReceiveTime.ToDateTimeString() },
                        { "ReceiveName", groupTask.ReceiveName },
                        { "CompletedTime1", groupTask.CompletedTime1.HasValue ? groupTask.CompletedTime1.Value.ToShortDateString() : "" },
                        { "StatusTitle", flowTask.GetExecuteTypeTitle(groupTask.ExecuteType) },
                        { "Show", "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"detail('" + groupTask.FlowId + "', '" + groupTask.GroupId + "');return false;\"><i class=\"fa fa-search\"></i>查看</a>" }
                    };
                    jArray.Add(jObject);
                }
                ViewData["json"]     = jArray.ToString();
                ViewData["ismobile"] = ismobile;
            }
            return(View());
        }
        public IActionResult Detail()
        {
            string flowid       = Request.Querys("flowid");
            string groupid      = Request.Querys("groupid");
            string taskid       = Request.Querys("taskie");
            string appid        = Request.Querys("appid");
            string tabid        = Request.Querys("tabid");
            string displaymodel = Request.Querys("displaymodel");
            string ismobile     = Request.Querys("ismobile");

            Business.FlowTask bflowTask = new Business.FlowTask();
            var flowTasks = bflowTask.GetListByGroupId(groupid.ToGuid());

            //判断不是流程参与者不能查看
            if (!flowTasks.Exists(p => p.ReceiveId == Current.UserId))
            {
                return(new ContentResult()
                {
                    Content = "您不是流程参与者,不能查看!"
                });
            }

            Newtonsoft.Json.Linq.JArray jArray  = new Newtonsoft.Json.Linq.JArray();
            Newtonsoft.Json.Linq.JArray jArray1 = new Newtonsoft.Json.Linq.JArray();
            foreach (var flowTask in flowTasks)
            {
                string stepName = flowTask.StepName;
                if (!flowTask.SubFlowGroupId.IsNullOrWhiteSpace())
                {
                    stepName = "<a href=\"javascript:;\" class=\"blue1\" onclick=\"showSubFlow('" + flowTask.Id + "')\">" + stepName + "</a>";
                }
                Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject
                {
                    { "StepName", stepName },
                    { "SenderName", flowTask.SenderName },
                    { "SenderTime", flowTask.ReceiveTime.ToDateTimeString() },
                    { "ReceiveName", flowTask.ReceiveName },
                    { "CompletedTime1", flowTask.CompletedTime1.ToDateTimeString() },
                    { "StatusTitle", bflowTask.GetExecuteTypeTitle(flowTask.ExecuteType) },
                    { "Comment", flowTask.Comments },
                    { "Note", flowTask.Note }
                };
                jArray.Add(jObject);
                if (true)
                {
                    Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject
                    {
                        { "stepid", flowTask.StepId },
                        { "prevstepid", flowTask.PrevStepId },
                        { "status", flowTask.Status },
                        { "sender", flowTask.SenderName },
                        { "sendtime", flowTask.ReceiveTime.ToDateTimeString() },
                        { "receiver", flowTask.ReceiveName },
                        { "completedtime1", flowTask.CompletedTime1.ToDateTimeString() },
                        { "comment", flowTask.Comments },
                        { "sort", flowTask.Sort },
                        { "tasktype", flowTask.TaskType },
                        { "statustitle", bflowTask.GetExecuteTypeTitle(flowTask.ExecuteType) }
                    };
                    jArray1.Add(jObject1);
                }
            }
            ViewData["json"]         = jArray.ToString();
            ViewData["json1"]        = jArray1.ToString();
            ViewData["displaymodel"] = displaymodel.IsNullOrWhiteSpace() ? "0" : displaymodel;
            ViewData["tabid"]        = tabid;
            ViewData["query"]        = "flowid=" + flowid + "&stepid=" + Request.Querys("stepid") + "&groupid=" + groupid + "&taskid=" + taskid + "&appid=" + appid + "&tabid=" + tabid + "&iframeid=" + Request.Querys("iframeid") + "&ismobile=" + ismobile;
            ViewData["flowid"]       = flowid;
            ViewData["ismobile"]     = ismobile;
            //判断如果有动态步骤,流程图要从rf_flowdynamic表中取
            var dynamicSteps = Config.EnableDynamicStep ? flowTasks.Where(p => p.BeforeStepId.IsNotEmptyGuid()).OrderByDescending(p => p.Sort).ToList() : new List <Model.FlowTask>();

            if (dynamicSteps.Count > 0)
            {
                ViewData["stepid"]  = dynamicSteps.First().BeforeStepId.ToString();
                ViewData["groupid"] = dynamicSteps.First().GroupId.ToString();
            }
            else
            {
                ViewData["stepid"]  = string.Empty;
                ViewData["groupid"] = string.Empty;
            }
            return(View());
        }
        public string QueryInstance()
        {
            string appid     = Request.Querys("appid");
            string tabid     = Request.Querys("tabid");
            string FlowID    = Request.Forms("FlowID");
            string Title     = Request.Forms("Title");
            string ReceiveID = Request.Forms("ReceiveID");
            string Date1     = Request.Forms("Date1");
            string Date2     = Request.Forms("Date2");
            string sidx      = Request.Forms("sidx");
            string sord      = Request.Forms("sord");
            string order     = (sidx.IsNullOrEmpty() ? "ReceiveTime" : sidx) + " " + (sord.IsNullOrEmpty() ? "DESC" : sord);
            int    size      = Tools.GetPageSize();
            int    number    = Tools.GetPageNumber();

            Business.FlowTask flowTask = new Business.FlowTask();
            Guid userId = new Business.User().GetUserId(ReceiveID);

            if (FlowID.IsNullOrWhiteSpace())
            {
                FlowID = new Business.Flow().GetManageInstanceFlowIds(Current.UserId).JoinSqlIn();
            }
            DataTable dataTable = flowTask.GetInstanceList(size, number, FlowID, Title, userId.IsEmptyGuid() ? "" : userId.ToString(), Date1, Date2, order, out int count);

            Newtonsoft.Json.Linq.JArray jArray = new Newtonsoft.Json.Linq.JArray();
            foreach (DataRow dr in dataTable.Rows)
            {
                var            groupTasks = flowTask.GetListByGroupId(dr["GroupId"].ToString().ToGuid());
                Model.FlowTask taskModel  = null;
                if (!Title.IsNullOrWhiteSpace())
                {
                    taskModel = groupTasks.Where(p => p.Title.ContainsIgnoreCase(Title)).OrderByDescending(p => p.Sort).ThenBy(p => p.Status).First();
                }
                if (null == taskModel)
                {
                    taskModel = groupTasks.OrderByDescending(p => p.Sort).ThenBy(p => p.Status).First();
                }
                int    openModel = 0, width = 0, height = 0;
                string opation = "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"manage('" + taskModel.Id.ToString() + "', '" + taskModel.GroupId.ToString() + "');\"><i class=\"fa fa-check-square-o\"></i>管理</a>";
                //if (taskModel.ExecuteType.In(-1, 0, 1))
                //{
                opation += "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"delete1('" + taskModel.Id.ToString() + "', '" + taskModel.GroupId.ToString() + "');\"><i class=\"fa fa-trash-o\"></i>删除</a>";
                //}

                string status    = flowTask.GetExecuteTypeTitle(taskModel.ExecuteType);
                string taskTitle = "<a href=\"javascript:void(0);\" class=\"list\" onclick=\"openTask('" + Url.Content("~/RoadFlowCore/FlowRun/Index") + "?" + string.Format("flowid={0}&stepid={1}&instanceid={2}&taskid={3}&groupid={4}&appid={5}&display=1",
                                                                                                                                                                             taskModel.FlowId.ToString(), taskModel.StepId.ToString(), taskModel.InstanceId, taskModel.Id.ToString(), taskModel.GroupId.ToString(), appid
                                                                                                                                                                             ) + "','" + taskModel.Title.TrimAll() + "','" + taskModel.Id.ToString() + "'," + openModel + "," + width + "," + height + ");return false;\">" + taskModel.Title + "</a>";
                Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject
                {
                    { "id", taskModel.Id.ToString() },
                    { "Title", taskTitle },
                    { "FlowName", taskModel.FlowName },
                    { "StepName", taskModel.StepName },
                    { "ReceiveName", taskModel.ReceiveName },
                    { "ReceiveTime", taskModel.ReceiveTime.ToDateTimeString() },
                    { "StatusTitle", status },
                    { "Opation", opation }
                };
                jArray.Add(jObject);
            }
            return("{\"userdata\":{\"total\":" + count + ",\"pagesize\":" + size + ",\"pagenumber\":" + number + "},\"rows\":" + jArray.ToString() + "}");
        }