Exemplo n.º 1
0
        /// <summary>
        /// 审批设置
        /// </summary>
        public bool ApprovalSet(long resId, string toResIds, long userId, int typeId)
        {
            sys_resource_approver_dal    sraDal  = new sys_resource_approver_dal();
            List <sys_resource_approver> appList = GetApprover(resId, typeId);

            if (appList != null && appList.Count > 0)
            {
                if (!string.IsNullOrEmpty(toResIds))
                {
                    var toResArr = toResIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var toResId in toResArr)
                    {
                        long thisToResId = 0;
                        int  tier        = 1;
                        if (typeId == (int)DicEnum.APPROVE_TYPE.EXPENSE_APPROVE)
                        {
                            long.TryParse(toResId, out thisToResId);
                        }
                        else if (typeId == (int)DicEnum.APPROVE_TYPE.TIMESHEET_APPROVE)
                        {
                            var toResIdArr = toResId.Split('-');
                            if (toResIdArr != null && toResIdArr.Count() == 2)
                            {
                                long.TryParse(toResIdArr[0], out thisToResId);
                                int.TryParse(toResIdArr[1], out tier);
                            }
                        }
                        if (thisToResId == 0)
                        {
                            continue;
                        }
                        sys_resource_approver thisApproval = appList.FirstOrDefault(_ => _.approver_resource_id == resId && _.resource_id == thisToResId);
                        if (thisApproval != null)
                        {
                            if (thisApproval.tier != tier)
                            {
                                thisApproval.tier = tier;
                                EditApproval(thisApproval, userId);
                            }
                            appList.Remove(thisApproval);
                            continue;
                        }
                        thisApproval = new sys_resource_approver()
                        {
                            id = sraDal.GetNextIdCom(),
                            approver_resource_id = resId,
                            resource_id          = thisToResId,
                            approve_type_id      = typeId,
                            tier = tier,
                        };
                        sraDal.Insert(thisApproval);
                        OperLogBLL.OperLogAdd <sys_resource_approver>(thisApproval, thisApproval.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                    }
                }
                if (appList.Count > 0)
                {
                    appList.ForEach(_ => {
                        sraDal.Delete(_);
                        OperLogBLL.OperLogDelete <sys_resource_approver>(_, _.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                    });
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(toResIds))
                {
                    var toResArr = toResIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var toResId in toResArr)
                    {
                        long thisToResId = 0;
                        int  tier        = 1;
                        if (typeId == (int)DicEnum.APPROVE_TYPE.EXPENSE_APPROVE)
                        {
                            long.TryParse(toResId, out thisToResId);
                        }
                        else if (typeId == (int)DicEnum.APPROVE_TYPE.TIMESHEET_APPROVE)
                        {
                            var toResIdArr = toResId.Split('-');
                            if (toResIdArr != null && toResIdArr.Count() == 2)
                            {
                                long.TryParse(toResIdArr[0], out thisToResId);
                                int.TryParse(toResIdArr[1], out tier);
                            }
                        }
                        if (thisToResId == 0)
                        {
                            continue;
                        }
                        sys_resource_approver thisApproval = sraDal.GetApproverByRes(resId, thisToResId, typeId);
                        if (thisApproval != null)
                        {
                            continue;
                        }
                        thisApproval = new sys_resource_approver()
                        {
                            id = sraDal.GetNextIdCom(),
                            approver_resource_id = resId,
                            resource_id          = thisToResId,
                            approve_type_id      = typeId,
                            tier = tier,
                        };
                        sraDal.Insert(thisApproval);
                        OperLogBLL.OperLogAdd <sys_resource_approver>(thisApproval, thisApproval.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                    }
                }
            }

            return(true);
        }