public string QueryDelete()
        {
            string flow_name = Request.Forms("flow_name");
            string typeid    = Request.Forms("typeid");
            string sidx      = Request.Forms("sidx");
            string sord      = Request.Forms("sord");

            int    size   = Tools.GetPageSize();
            int    number = Tools.GetPageNumber();
            string order  = (sidx.IsNullOrEmpty() ? "CreateDate" : sidx) + " " + (sord.IsNullOrEmpty() ? "DESC" : sord);

            Business.Flow flow  = new Business.Flow();
            var           flows = flow.GetPagerList(out int count, size, number, flow.GetManageFlowIds(Current.UserId), flow_name, "", order, 3);

            Newtonsoft.Json.Linq.JArray jArray = new Newtonsoft.Json.Linq.JArray();
            Business.User user = new Business.User();
            foreach (System.Data.DataRow dr in flows.Rows)
            {
                Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject
                {
                    { "id", dr["Id"].ToString() },
                    { "Name", dr["Name"].ToString() },
                    { "CreateDate", dr["CreateDate"].ToString().ToDateTime().ToDateTimeString() },
                    { "CreateUser", user.GetName(dr["CreateUser"].ToString().ToGuid()) },
                    { "Status", flow.GetStatusTitle(dr["Status"].ToString().ToInt()) },
                    { "Note", dr["Note"].ToString() },
                    { "Opation", "<a class=\"list\" href=\"javascript:void(0);\" onclick=\"reply('" + dr["Id"].ToString() + "', '" + dr["Name"].ToString() + "');return false;\"><i class=\"fa fa-reply\"></i>还原</a>" }
                };
                jArray.Add(jObject);
            }
            return("{\"userdata\":{\"total\":" + count + ",\"pagesize\":" + size + ",\"pagenumber\":" + number + "},\"rows\":" + jArray.ToString() + "}");
        }
        public IActionResult GoTo()
        {
            string taskid = Request.Querys("taskid");

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

            if (null == taskModel)
            {
                return(new ContentResult()
                {
                    Content = "未找到当前任务!"
                });
            }
            var flowRunModel = new Business.Flow().GetFlowRunModel(taskModel.FlowId);

            if (null == flowRunModel)
            {
                return(new ContentResult()
                {
                    Content = "未找到当前流程运行时!"
                });
            }
            ViewData["steps"]       = flowRunModel.Steps;
            ViewData["queryString"] = Request.UrlQuery();
            return(View());
        }
 public IActionResult Instance()
 {
     ViewData["appid"]       = Request.Querys("appid");
     ViewData["query"]       = "&appid=" + Request.Querys("appid") + "&tabid=" + Request.Querys("tabid");
     ViewData["flowOptions"] = new Business.Flow().GetManageInstanceOptions(Current.UserId);
     return(View());
 }
 public IActionResult MyStarts()
 {
     ViewData["flowOptions"] = new Business.Flow().GetOptions();
     ViewData["query"]       = "appid=" + Request.Querys("appid") + "&tabid=" + Request.Querys("tabid");
     ViewData["tabId"]       = Request.Querys("tabid");
     return(View());
 }
        public string Save()
        {
            string json = Request.Forms("json");
            string msg  = new Business.Flow().Save(json);

            return("1".Equals(msg) ? "保存成功!" : msg);
        }
        /// <summary>
        /// 安装流程
        /// </summary>
        /// <returns></returns>
        public string Install()
        {
            string json = Request.Forms("json");
            string msg  = new Business.Flow().Install(json);

            return("1".Equals(msg) ? "安装成功!" : msg);
        }
        public IActionResult ImportSave()
        {
            var files = Request.Form.Files;

            if (files.Count == 0)
            {
                ViewData["errmsg"] = "您没有选择要导入的文件!";
                return(View());
            }
            Business.Flow             flow          = new Business.Flow();
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            foreach (var file in files)
            {
                var    stream    = file.OpenReadStream();
                int    count     = (int)stream.Length;
                byte[] b         = new byte[count];
                int    readCount = 0;
                while (readCount < count)
                {
                    readCount += stream.Read(b, readCount, 1024);
                }
                string json = System.Text.Encoding.UTF8.GetString(b);
                string msg  = flow.ImportFlow(json);
                if (!"1".Equals(msg))
                {
                    stringBuilder.Append(msg + ",");
                }
            }
            if (stringBuilder.Length > 0)
            {
                ViewData["errmsg"] = stringBuilder.ToString().TrimEnd(',');
            }
            ViewData["queryString"] = Request.UrlQuery();
            return(View());
        }
        public string GetJSON()
        {
            //如果包含动态步骤则JSON要从rf_flowdynamic表中取
            string dynamicStepId = Request.Querys("dynamicstepid"); //动态步骤步骤id
            string groupId       = Request.Querys("groupid");       //组id

            if (dynamicStepId.IsGuid(out Guid dynamicStepGuid) && groupId.IsGuid(out Guid groupGuid))
            {
                var flowDynamicModel = new Business.FlowDynamic().Get(dynamicStepGuid, groupGuid);
                return(null == flowDynamicModel ? "{}" : flowDynamicModel.FlowJSON);
            }
            //========================================

            string flowId = Request.Querys("flowid");

            if (!flowId.IsGuid(out Guid fId))
            {
                return("{}");
            }
            else
            {
                var flow = new Business.Flow().Get(fId);
                return(null == flow ? "" : flow.DesignerJSON);
            }
        }
        public void Export()
        {
            string json = new Business.Flow().GetExportFlowString(Request.Querys("flowid"));

            byte[] contents = System.Text.Encoding.UTF8.GetBytes(json);
            Response.Headers.Add("Server-FileName", "exportflow.json");
            Response.ContentType = "application/octet-stream";
            Response.Headers.Add("Content-Disposition", "attachment; filename=exportflow.json");
            Response.Headers.Add("Content-Length", contents.Length.ToString());
            Response.Body.Write(contents);
            Response.Body.Flush();
        }
 public IActionResult Set_Step()
 {
     ViewData["stepId"]      = Request.Querys("id");
     ViewData["x"]           = Request.Querys("x");
     ViewData["y"]           = Request.Querys("y");
     ViewData["width"]       = Request.Querys("width");
     ViewData["height"]      = Request.Querys("height");
     ViewData["issubflow"]   = Request.Querys("issubflow");
     ViewData["openerid"]    = Request.Querys("openerid");
     ViewData["formTypes"]   = new Business.Dictionary().GetOptionsByCode("system_applibrarytype", existsFlowType: false);
     ViewData["flowOptions"] = new Business.Flow().GetOptions();
     return(View());
 }
        public string Reply()
        {
            string flowid = Request.Forms("flowid");

            if (!flowid.IsGuid(out Guid fid))
            {
                return("流程ID错误!");
            }
            Business.Flow flow      = new Business.Flow();
            var           flowModel = flow.Get(fid);

            if (null == flowModel)
            {
                return("没有找到要还原的流程!");
            }
            flowModel.Status = 0;
            flow.Update(flowModel);
            return("还原成功!");
        }
        public string UnInstall()
        {
            string[] flowIds        = Request.Forms("flowid").Split(',');
            int      thoroughDelete = Request.Forms("thoroughdelete").ToInt(0);//是否彻底删除
            string   status         = Request.Forms("status");

            Business.Flow flow = new Business.Flow();
            foreach (var flowId in flowIds)
            {
                var flowModel = flow.Get(flowId.ToGuid());
                if (null == flowModel)
                {
                    continue;
                }
                if (0 == thoroughDelete)//作删除标记或卸载标记
                {
                    int status1 = status.ToInt(3);
                    Business.Log.Add(("2".Equals(status) ? "卸载" : "删除") + "了流程-" + flowModel.Name, flowModel.ToString(), Business.Log.Type.流程管理);
                    flowModel.Status = status1;
                    flow.Update(flowModel);
                }
                else//彻底删除
                {
                    flow.Delete(flowModel);
                    //删除应用程序库
                    Business.AppLibrary appLibrary = new Business.AppLibrary();
                    var appModel = appLibrary.GetByCode(flowModel.Id.ToString());
                    if (null != appModel)
                    {
                        new Business.AppLibrary().Delete(appModel.Id);
                    }
                    //删除流程实例
                    new Business.FlowTask().DeleteByFlowId(flowModel.Id);
                    Business.Log.Add("彻底删除了流程-" + flowModel.Name, flowModel.ToString(), Business.Log.Type.流程管理);
                }
                flow.ClearCache(flowModel.Id);
            }
            return("1");
        }
        /// <summary>
        /// 作废任务
        /// </summary>
        /// <returns></returns>
        public string DeleteTask()
        {
            string deltaskid = Request.Querys("deltaskid");

            if (!deltaskid.IsGuid(out Guid taskId))
            {
                return("Id错误!");
            }
            Business.FlowTask flowTask = new Business.FlowTask();
            var taskModel = flowTask.Get(taskId);

            if (null == taskModel)
            {
                return("作废成功!");
            }
            flowTask.DeleteByGroupId(taskModel.GroupId);
            var flowrunModel = new Business.Flow().GetFlowRunModel(taskModel.FlowId);

            if (null == flowrunModel)
            {
                return("作废成功!");
            }
            var stepModel = flowrunModel.Steps.Find(p => p.Id == taskModel.StepId);

            if (null == stepModel)
            {
                return("作废成功!");
            }
            var applibrary = new Business.AppLibrary().Get(stepModel.StepForm.Id);

            if (null != applibrary && applibrary.Code.IsGuid(out Guid formId))
            {
                new Business.Form().DeleteFormData(formId, taskModel.InstanceId);
            }
            return("作废成功!");
        }
        public string SaveAsSave()
        {
            string newFlowName = Request.Forms("newflowname");
            string flowId      = Request.Querys("flowid");

            if (newFlowName.IsNullOrWhiteSpace())
            {
                return("{\"success\":0,\"msg\":\"新的流程名称不能为空!\"}");
            }
            if (!flowId.IsGuid(out Guid flowGuid))
            {
                return("{\"success\":0,\"msg\":\"流程Id错误!\"}");
            }
            string msg = new Business.Flow().SaveAs(flowGuid, newFlowName.Trim());

            if (msg.IsGuid(out Guid newFlowGuid))
            {
                return("{\"success\":1,\"msg\":\"另存成功!\",\"newId\":\"" + msg + "\"}");
            }
            else
            {
                return("{\"success\":0,\"msg\":\"" + msg + "\"}");;
            }
        }
        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() + "}");
        }