示例#1
0
        public ActionResult List(int id = 1, string processGuid = "", int activityInstanceID = 0)
        {
            if (id == 1)
            {
                ViewBag.Message = "非法链接";
                return View();
            }
            else
            {
                if (string.IsNullOrEmpty(processGuid))
                {
                    WorkFlowManager work = new WorkFlowManager();
                    LeaveEntity entity = work.FindById(id);
                    string s = @"<table class='table table-bordered'>"
                                + "<tr><td>部门经理</td><td>" + entity.DepManagerRemark + "</td></tr>"
                                + "<tr><td>主管总监 </td><td>" + entity.DirectorRemark + "</td></tr>"
                                + "<tr><td>副总经理</td><td>" + entity.DeputyGeneralRemark + "</td></tr>"
                                + "<tr><td>总经理</td><td>" + entity.GeneralManagerRemark + "</td> </tr></table>";
                    ViewBag.Shenpi = s;
                    return View(entity);
                }
                else
                {
                    WorkFlowManager work = new WorkFlowManager();
                    LeaveEntity entity = work.FindById(id);
                    //权限设置
                    IWorkflowService service = new WorkflowService();
                    ProcessEntity processEntity = service.GetProcessById(processGuid);
                    if (processEntity != null)
                    {
                        ActivityInstanceEntity activityInstanceEntity = service.GetActivityInstance(activityInstanceID);
                        string s = "";
                        if (activityInstanceEntity != null)
                        {
                            ActivityEntity activityEntity = service.GetActivityEntity(processGuid, activityInstanceEntity.ActivityGUID);
                            if (activityEntity != null && activityEntity.Roles != null && activityEntity.Roles.Count > 0)
                            {
                                //用户角色列表
                                IList<string> roleUser = UserManager.GetRoles(Convert.ToInt32(User.Identity.GetUserId()));

                                foreach (var role in activityEntity.Roles)
                                {
                                    //为方便起见这里只取第一个角色,开发人员可以自行调整
                                    if (role.RoleCode == roleUser[0].ToString())
                                    {
                                        switch (role.ID)
                                        {
                                            case 2:
                                                //部门经理审批
                                                s = @"<table class='table table-bordered'>" +
                                               "<tr><td>部门经理</td><td><input type='text'class='form-control' name='DepManagerRemark'></td></tr>" +
                                               "<tr><td>主管总监 </td><input type='text' class='form-control' name='DirectorRemark' style='display:none'></td></tr>" +
                                               "<tr><td>副总经理</td><td><input type='text' class='form-control' name='DeputyGeneralRemark' style='display:none'></td></tr>" +
                                               "<tr><td>总经理</td><td><input class='form-control' name='GeneralManagerRemark'  style='display:none' type='text' /> </td> </tr>"
                                                ;
                                                break;
                                            case 3:
                                                //主管总监审批
                                                s = @"<table class='table table-bordered'>" +
                                               "<tr><td>部门经理</td><td>" + entity.DepManagerRemark + "<input type='text'class='form-control'  style='display:none' name='DepManagerRemark' value='" + entity.DepManagerRemark + "'></td></tr>" +
                                               "<tr><td>主管总监 </td><input type='text' class='form-control' name='DirectorRemark' ></td></tr>" +
                                               "<tr><td>副总经理</td><td><input type='text' class='form-control' name='DeputyGeneralRemark' style='display:none'></td></tr>" +
                                               "<tr><td>总经理</td><td><input class='form-control' name='GeneralManagerRemark'  style='display:none' type='text' /> </td> </tr>"
                                                                                   ;
                                                break;
                                            case 7:
                                                //副总经理审批
                                                s = @"<table class='table table-bordered'>" +
                                               "<tr><td>部门经理</td><td>" + entity.DepManagerRemark + "<input type='text'class='form-control' style='display:none' name='DepManagerRemark' value='" + entity.DepManagerRemark + "'></td></tr>" +
                                               "<tr><td>主管总监 </td><td>" + entity.DirectorRemark + "<input type='text' class='form-control' name='DirectorRemark' value='" + entity.DirectorRemark + "' ></td></tr>" +
                                               "<tr><td>副总经理</td><td><input type='text' class='form-control' name='DeputyGeneralRemark' style='display:none'></td></tr>" +
                                               "<tr><td>总经理</td><td><input class='form-control' name='GeneralManagerRemark'  style='display:none' type='text' /> </td> </tr>";
                                                break;
                                            case 8:
                                                //总经理审批
                                                s = @"<table class='table table-bordered'>" +
  "<tr><td>部门经理</td><td>" + entity.DepManagerRemark + "<input type='text'class='form-control' style='display:none' name='DepManagerRemark' value='" + entity.DepManagerRemark + "'></td></tr>" +
  "<tr><td>主管总监 </td><td>" + entity.DirectorRemark + "<input type='text' class='form-control' name='DirectorRemark' value='" + entity.DirectorRemark + "' ></td></tr>" +
  "<tr><td>副总经理</td><td><input type='text' class='form-control' name='DeputyGeneralRemark' style='display:none' value='" + entity.DeputyGeneralRemark + "'></td></tr>" +
  "<tr><td>总经理</td><td><input class='form-control' name='GeneralManagerRemark' type='text' /> </td> </tr>"
                                      ;
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                        //获取当前角色      
                        ViewBag.Shenpi = "<form action='' id='Remark'>" + s + "</table></form><button class='btn btn-primary' id='agree'>同意</button><button class='btn btn-primary' id='return'>退回</button>";
                        ViewBag.processGUID = processGuid;
                        ViewBag.days = entity.Days;
                        return View(entity);
                    }
                }
            }
            //表示出现错误
            return View();
        }
示例#2
0
        public async Task<ActionResult> Add(LeaveViewModel leave)
        {
            string processGUID = leave.ProcessGUID;
            //验证不通过,重新填写表单
            if (!ModelState.IsValid)
            {
                return View();
            }
            IWorkflowService service = new WorkflowService();
            //流程开始第一步
            ActivityEntity firstActivity = service.GetFirstActivity(leave.ProcessGUID);

            //该处较上一版本有变化,上一版本为GUID类型
            string firstActivityGUID = firstActivity.ActivityGUID;
            IList<NodeView> nextActivity = service.GetNextActivity(leave.ProcessGUID, firstActivityGUID, GetCondition("days-" + leave.Days));
            //表示有下一位审批者
            if (nextActivity.Count() > 0)
            {
                //下一步角色ID审批者
                string outerId = nextActivity[0].Roles[0].ID.ToString();
                //这里只取第一个审批者,WebDemo 是弹窗形式选择
                //审批用户id
                IEnumerable<int> userId = RoleManager.FindById(Convert.ToInt32(outerId)).Users.Select(t => t.UserId);
                ApplicationUser user = await UserManager.FindByIdAsync(Convert.ToInt32(userId.ToList()[0]));
                //提交请假信息
                LeaveEntity leaveE = new LeaveEntity()
                {
                    FromDate = leave.BeginTime,
                    ToDate = leave.EndTime,
                    Days = leave.Days,
                    LeaveType = leave.LeaveType,
                    CurrentActivityText = "",
                    Status = 0,
                    CreatedUserID = Convert.ToInt32(User.Identity.GetUserId()),
                    CreatedUserName = User.Identity.Name,
                    CreatedDate = DateTime.Now
                };
                HrsLeaveResult result = new WorkFlowManager().Insert(leaveE);
                if (result.Successed)
                {
                    WfAppRunner initiator = new WfAppRunner();
                    initiator.AppName = "请假流程";
                    initiator.AppInstanceID = result.ResultIdentities.ToString();
                    initiator.ProcessGUID = processGUID;
                    initiator.UserID = User.Identity.GetUserId();
                    initiator.UserName = User.Identity.Name;
                    initiator.Conditions = GetCondition(string.Format("days-{0}", leave.Days));
                    WfExecutedResult startedResult = service.StartProcess(initiator);
                    if (startedResult.Status != WfExecutedStatus.Success)
                    {
                        //给出提示
                    }
                    //送往下一步
                    PerformerList pList = new PerformerList();
                    //这里使用真实姓名代替
                    pList.Add(new Performer(user.Id.ToString(), user.RealName));
                    initiator.NextActivityPerformers = new Dictionary<String, PerformerList>();
                    initiator.NextActivityPerformers.Add(nextActivity[0].ActivityGUID, pList);
                    WfExecutedResult runAppResult = service.RunProcessApp(initiator);
                    if (runAppResult.Status != WfExecutedStatus.Success)
                    {
                        this.Content("<script>alert('" + runAppResult.Message + "');</script>");
                    }
                    //保存业务数据
                    BizAppFlowEntity AppFlowEntity = new BizAppFlowEntity();
                    AppFlowEntity.AppName = "流程发起";
                    AppFlowEntity.AppInstanceID = result.ResultIdentities.ToString();
                    AppFlowEntity.ActivityName = "流程发起";
                    AppFlowEntity.Remark = string.Format("申请人:{0}-{1}", User.Identity.GetUserId(), User.Identity.Name);
                    AppFlowEntity.ChangedTime = DateTime.Now;
                    AppFlowEntity.ChangedUserID = User.Identity.GetUserId();
                    AppFlowEntity.ChangedUserName = User.Identity.Name;
                    HrsLeaveResult resultBiz = new WorkFlowManager().Insert(AppFlowEntity);
                    if (resultBiz.Successed)
                    {
                        //给出前台提示
                        this.Content("", "<script>alert('流程发起成功');</script>");
                    }
                }
            }
            else
            {
                //显示前台错误,人事人员审批失败
                ModelState.AddModelError("Human", "该用户暂时不可提交审批,未查询到该用户的下一位审批者");
                return View();
            }
            return RedirectToAction("MySlickflow", "Slickflow");
        }
 /// <summary>
 /// 我发起的流程
 /// </summary>
 /// <returns></returns>
 public ActionResult MySlickflow()
 {
     WorkFlowManager work = new WorkFlowManager();
     IEnumerable<ProcessInstance> processInstance = work.GetProcessInstance(User.Identity.GetUserId());
     return View(processInstance);
 }