예제 #1
0
        /// <summary>
        /// 添加请假单
        /// </summary>
        /// <param name="lvInputDto">请假单对象</param>
        public ReturnInfo AddLeave(LeaveInputDto lvInputDto)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            string        MaxID = _leaveRepository.GetMaxID();
            string        NowID = Helper.GenerateID("Lv", MaxID);

            lvInputDto.L_ID = NowID;
            string ValidateInfo = Helper.ValidateLeaveInputDto(lvInputDto);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                try
                {
                    Leave entity = Mapper.Map <LeaveInputDto, Leave>(lvInputDto);
                    entity.L_CreateDate = DateTime.Now;
                    entity.L_Status     = (int)L_Status.新建;
                    entity.L_UpdateDate = DateTime.Now;
                    if (lvInputDto.L_EndDate != null)
                    {
                        entity.L_EndDate = (DateTime)lvInputDto.L_EndDate;
                    }
                    if (lvInputDto.L_StartDate != null)
                    {
                        entity.L_StartDate = (DateTime)lvInputDto.L_StartDate;
                    }
                    string MaxID2 = _leaveRepository.GetMaxID();
                    string NowID2 = Helper.GenerateID("Lv", MaxID2);
                    entity.L_ID = NowID2;
                    _unitOfWork.RegisterNew(entity);
                    bool result = _unitOfWork.Commit();
                    RInfo.IsSuccess = result;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }
예제 #2
0
        /// <summary>
        /// 请假单验证
        /// </summary>
        /// <param name="entity">请假单对象</param>
        public static string ValidateLeaveInputDto(LeaveInputDto entity)
        {
            //基础验证
            StringBuilder sb = BasicValidate <LeaveInputDto>(entity);

            //额外验证(开始时间不能大于结束时间,审批人在用户表里)
            if (!string.IsNullOrEmpty(entity.L_StartDate.ToString()) && !string.IsNullOrEmpty(entity.L_EndDate.ToString()))
            {
                if (entity.L_StartDate > entity.L_EndDate)
                {
                    sb.Append("开始日期不能大于结束日期!");
                }
            }
            if (entity.L_LDay <= 0)
            {
                sb.Append("请假天数必须为正!");
            }
            if (!Regex.IsMatch(entity.L_LDay.ToString(), @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1})?$"))
            {
                sb.Append("请假天数格式错误,至多2位小数!");
            }
            if (!string.IsNullOrEmpty(entity.L_CheckUsers))
            {
                string[] CheckUsers = entity.L_CheckUsers.Split(',');
                if (CheckUsers.Length > 0)
                {
                    foreach (string s in CheckUsers)
                    {
                        if (!userRepository.IsExists(s))
                        {
                            sb.Append("审批人" + s + "不在用户表中!");
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(entity.L_CCTo))
            {
                string[] CCTo = entity.L_CCTo.Split(',');
                if (CCTo.Length > 0)
                {
                    foreach (string s in CCTo)
                    {
                        if (!userRepository.IsExists(s))
                        {
                            sb.Append("抄送人" + s + "不在用户表中!");
                        }
                    }
                }
            }

            return(sb.ToString());
        }
예제 #3
0
        public async Task Update(LeaveInputDto input)
        {
            var userId = ((UserIdentity)User.Identity).UserId;

            var data = await db.Leaves.SingleOrDefaultAsync(m => m.Id == input.LeaveId && !m.IsDelete);

            if (data == null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "请假记录不存在"
                    }))
                });
            }

            var leave = await db.Leaves.SingleOrDefaultAsync(m => m.UserId == userId && m.StartTime <= input.StartTime && m.EndTime >= input.EndTime && !m.IsDelete);

            if (leave != null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "已提交请假申请"
                    }))
                });
            }

            data.Desc      = input.Desc;
            data.EndTime   = input.EndTime;
            data.StartTime = input.StartTime;

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "更新失败"
                    }))
                });
            }
        }
예제 #4
0
        /// <summary>
        /// 更新请假单
        /// </summary>
        /// <param name="entity">请假单对象</param>
        public ReturnInfo UpdateLeave(LeaveInputDto entity)
        {
            ReturnInfo    RInfo        = new ReturnInfo();
            StringBuilder sb           = new StringBuilder();
            string        ValidateInfo = Helper.ValidateLeaveInputDto(entity);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                Leave lv = _leaveRepository.GetByID(entity.L_ID).FirstOrDefault();
                if (lv != null)
                {
                    Leave lv2 = _leaveRepository.GetByID(entity.L_ID).AsNoTracking().FirstOrDefault();
                    if (lv2.L_Status >= (int)L_Status.已审批)
                    {
                        RInfo.IsSuccess = false;
                        RInfo.ErrorInfo = "只有新建和已拒绝的才能修改!";
                        return(RInfo);
                    }
                    else
                    {
                        try
                        {
                            #region 如果字段非空或0,则更新对应字段
                            if (entity.L_CCTo != null)
                            {
                                lv.L_CCTo = entity.L_CCTo;
                            }
                            if (entity.L_CheckUsers != null)
                            {
                                lv.L_CheckUsers = entity.L_CheckUsers;
                            }
                            if (entity.L_EndDate != null)
                            {
                                lv.L_EndDate = (DateTime)entity.L_EndDate;
                            }
                            if (entity.L_Img1 != null)
                            {
                                lv.L_Img1 = entity.L_Img1;
                            }
                            if (entity.L_Img2 != null)
                            {
                                lv.L_Img2 = entity.L_Img2;
                            }
                            if (entity.L_Img3 != null)
                            {
                                lv.L_Img3 = entity.L_Img3;
                            }
                            if (entity.L_Img4 != null)
                            {
                                lv.L_Img4 = entity.L_Img4;
                            }
                            if (entity.L_Img5 != null)
                            {
                                lv.L_Img5 = entity.L_Img5;
                            }
                            if (entity.L_Img6 != null)
                            {
                                lv.L_Img6 = entity.L_Img6;
                            }
                            if (entity.L_Img7 != null)
                            {
                                lv.L_Img7 = entity.L_Img7;
                            }
                            if (entity.L_Img8 != null)
                            {
                                lv.L_Img8 = entity.L_Img8;
                            }
                            if (entity.L_Img9 != null)
                            {
                                lv.L_Img9 = entity.L_Img9;
                            }
                            if (entity.L_LDay > 0)
                            {
                                lv.L_LDay = entity.L_LDay;
                            }
                            if (entity.L_Reason != null)
                            {
                                lv.L_Reason = entity.L_Reason;
                            }
                            if (entity.L_StartDate != null)
                            {
                                lv.L_StartDate = (DateTime)entity.L_StartDate;
                            }
                            lv.L_Status = (int)L_Status.新建;
                            if (entity.L_TypeID != null)
                            {
                                lv.L_TypeID = entity.L_TypeID;
                            }
                            if (entity.L_UpdateUser != null)
                            {
                                lv.L_UpdateUser = entity.L_UpdateUser;
                            }
                            lv.L_UpdateDate   = DateTime.Now;
                            lv.L_CurrantCheck = "";
                            #endregion
                            _unitOfWork.RegisterDirty(lv);
                            bool result = _unitOfWork.Commit();
                            RInfo.IsSuccess = result;
                            RInfo.ErrorInfo = sb.ToString();
                            return(RInfo);
                        }
                        catch (Exception ex)
                        {
                            _unitOfWork.RegisterClean(lv);
                            _unitOfWork.Rollback();
                            sb.Append(ex.Message);
                            RInfo.IsSuccess = false;
                            RInfo.ErrorInfo = sb.ToString();
                            return(RInfo);
                        }
                    }
                }
                else
                {
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = "未找到该请假单!";
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }
예제 #5
0
        /// <summary>
        /// 提交事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (type.Trim().Length <= 0)
                {
                    throw new Exception("请输入请假类别!");
                }
                if (dpkStartDate.Value > dpkEndDate.Value)
                {
                    throw new Exception("开始时间必须小于结束时间!");
                }
                if (txtLday.Text.Trim().Length <= 0)
                {
                    throw new Exception("请输入请假天数!");
                }
                else
                {
                    if (System.Text.RegularExpressions.Regex.IsMatch(txtLday.Text.Trim(), @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$") == false)
                    {
                        throw new Exception("请假天数必须为大于0的数字!");
                    }
                }
                if (txtReason.Text.Trim().Length <= 0)
                {
                    throw new Exception("请输入请假事由!");
                }
                if (listCheckUsers.Count <= 0)
                {
                    throw new Exception("请输入审批人!");
                }

                //赋值请假信息
                LeaveInputDto leave = new LeaveInputDto();
                leave.L_TypeID    = type;
                leave.L_StartDate = dpkStartDate.Value;
                leave.L_EndDate   = dpkEndDate.Value;
                leave.L_LDay      = Convert.ToDecimal(txtLday.Text.Trim());
                leave.L_Reason    = txtReason.Text.Trim();
                if (imgL.ResourceID.Trim().Length > 0)
                {
                    leave.L_Img1 = imgL.ResourceID.Trim();
                }
                else
                {
                    leave.L_Img1 = "";
                }
                if (listCheckUsers.Count > 0)
                {
                    string CheckUsers = "";
                    foreach (string checkuser in listCheckUsers)
                    {
                        if (string.IsNullOrWhiteSpace(CheckUsers) == true)
                        {
                            CheckUsers = checkuser;
                        }
                        else
                        {
                            CheckUsers += "," + checkuser;
                        }
                    }
                    leave.L_CheckUsers = CheckUsers;
                }
                string CCToUsers = "";
                if (listCCToUsers.Count > 0)
                {
                    foreach (string user in listCCToUsers)
                    {
                        if (string.IsNullOrWhiteSpace(CCToUsers) == true)
                        {
                            CCToUsers = user;
                        }
                        else
                        {
                            CCToUsers += "," + user;
                        }
                    }
                }
                leave.L_CCTo = CCToUsers;
                ReturnInfo result;
                if (string.IsNullOrEmpty(LID) == false)
                {
                    leave.L_ID         = LID;
                    leave.L_UpdateUser = Client.Session["U_ID"].ToString();
                    //更新请假信息
                    result = AutofacConfig.leaveService.UpdateLeave(leave);
                }
                else
                {
                    //创建请假
                    leave.L_CreateUser = Client.Session["U_ID"].ToString();
                    result             = AutofacConfig.leaveService.AddLeave(leave);
                }
                //如果返回值true表示请假信息创建或更新成功,否则失败并抛出错误
                if (result.IsSuccess == true)
                {
                    ShowResult = ShowResult.Yes;
                    //if (string.IsNullOrEmpty(LID) == true)
                    //{
                    Close();
                    //}
                    Toast("您的请假条已成功提交!", ToastLength.SHORT);
                }
                else
                {
                    throw new Exception(result.ErrorInfo);
                }
            }
            catch (Exception ex)
            {
                Toast(ex.Message, ToastLength.SHORT);
            }
        }
예제 #6
0
        public async Task Add(LeaveInputDto input)
        {
            var userId = ((UserIdentity)User.Identity).UserId;

            var related = await db.RelatedApprovals.SingleOrDefaultAsync(m => m.RelatedKey == "Leave");

            if (related == null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "请假申请未绑定审批流,添加失败"
                    }))
                });
            }

            var approval = await db.Approvals.Where(m => m.Key == related.ApprovalKey).ToListAsync();

            if (approval == null && approval.Count <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = related.ApprovalKey + "该审批流不存在,添加失败"
                    }))
                });
            }

            var data = await db.Leaves.SingleOrDefaultAsync(m => m.UserId == userId && m.StartTime <= input.StartTime && m.EndTime >= input.EndTime && !m.IsDelete);

            if (data != null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "已提交请假申请"
                    }))
                });
            }

            var leave = new Leave()
            {
                Id            = IdentityManager.NewId(),
                ApprovalType  = EApprovalType.UnderReview,
                Desc          = input.Desc,
                UserId        = userId,
                EndTime       = input.EndTime,
                StartTime     = input.StartTime,
                IsDelete      = false,
                LeaveType     = input.LeaveType,
                ApprovalIndex = 0,
                ApprovalKey   = related.ApprovalKey
            };

            db.Leaves.Add(leave);

            var userTypeKey = await db.Approvals.SingleOrDefaultAsync(m => m.Deis == 1 && m.Key == data.ApprovalKey);

            if (userTypeKey != null)
            {
                db.LeaveApprovals.Add(new LeaveApproval
                {
                    Id            = IdentityManager.NewId(),
                    LeaveId       = leave.Id,
                    IsApproval    = false,
                    UserTypeKey   = userTypeKey.UserTypeKey,
                    ApprovalIndex = 1
                });
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = data.ApprovalKey + "审批流异常"
                    }))
                });
            }

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "添加失败"
                    }))
                });
            }
        }
예제 #7
0
        public async Task UpdateLeaveApproval(LeaveInputDto input)
        {
            var userId = ((UserIdentity)User.Identity).UserId;
            var token  = ((UserIdentity)User.Identity).Token;

            var userTypeKeys = token.UserTypeKey;

            var data = await db.Leaves.SingleOrDefaultAsync(m => m.Id == input.LeaveId && !m.IsDelete);

            if (data == null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "请假记录不存在"
                    }))
                });
            }

            if (data.ApprovalType == EApprovalType.Rejected)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "该请假申请已被驳回"
                    }))
                });
            }

            var approval = await db.Approvals.Where(m => m.Key == data.ApprovalKey).ToListAsync();

            if (approval == null && approval.Count <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = data.ApprovalKey + "该审批流不存在,请重新提交申请"
                    }))
                });
            }

            var index = data.ApprovalIndex + 1;

            var maxIndex = approval.Max(m => m.Deis);

            var userApproval = approval.SingleOrDefault(m => m.Deis == index);

            if (userApproval != null)
            {
                if (!userTypeKeys.Contains(userApproval.UserTypeKey))
                {
                    //}
                    //if (userApproval.UserTypeKey != token.UserTypeKey)
                    //{
                    throw new HttpResponseException(new HttpResponseMessage()
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                        {
                            Code = EExceptionType.Implement, Message = data.ApprovalKey + "无权操作"
                        }))
                    });
                }
                else
                {
                    data.ApprovalIndex += 1;

                    data.ApprovalType = EApprovalType.InExecution;

                    //var leaveApproval = await db.LeaveApprovals.SingleOrDefaultAsync(m => m.UserTypeKey == token.UserTypeKey && m.ApprovalIndex == index && m.LeaveId == data.Id);
                    var leaveApproval = await db.LeaveApprovals.SingleOrDefaultAsync(m => userTypeKeys.Contains(m.UserTypeKey) && m.ApprovalIndex == index && m.LeaveId == data.Id);

                    if (leaveApproval == null)
                    {
                        throw new HttpResponseException(new HttpResponseMessage()
                        {
                            Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                            {
                                Code = EExceptionType.Implement, Message = data.ApprovalKey + "审批流程异常"
                            }))
                        });
                    }

                    leaveApproval.IsApproval = true;
                    leaveApproval.UserId     = token.UserId;

                    var userTypeKey = approval.SingleOrDefault(m => m.Deis == index + 1);

                    if (userTypeKey != null)
                    {
                        db.LeaveApprovals.Add(new LeaveApproval
                        {
                            Id            = IdentityManager.NewId(),
                            LeaveId       = data.Id,
                            IsApproval    = false,
                            UserTypeKey   = userTypeKey.UserTypeKey,
                            ApprovalIndex = index + 1
                        });
                    }

                    if (maxIndex == data.ApprovalIndex)
                    {
                        data.ApprovalType = EApprovalType.Reviewed;
                    }
                }
            }
            else if (maxIndex == data.ApprovalIndex && input.ApprovalType == null)
            {
                data.ApprovalType = EApprovalType.Reviewed;
            }
            else
            {
                if (input.ApprovalType == EApprovalType.Rejected)
                {
                    data.ApprovalType = input.ApprovalType;
                }
            }

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "更新失败"
                    }))
                });
            }
        }