Beispiel #1
0
        /// <summary>
        /// 编辑员工的密码
        /// </summary>
        public bool ChangeUserPass(sys_user user, long userId)
        {
            var userDal = new sys_user_dal();
            var userOld = userDal.FindById(user.id);

            if (userOld == null)
            {
                return(false);
            }
            if (userOld.password != user.password)
            {
                userDal.Update(user);
                OperLogBLL.OperLogUpdate <sys_user>(user, userOld, user.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "修改员工密码");
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 更新员工信息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userId"></param>
        /// <param name="resourceId"></param>
        /// <returns></returns>
        public ERROR_CODE Update(SysUserAddDto data, long userId, long resourceId)
        {
            // 检查邮箱和手机号是否重复
            sys_resource findRes;

            if (string.IsNullOrEmpty(data.sys_res.mobile_phone))
            {
                findRes = _dal.FindSignleBySql <sys_resource>($"select * from sys_resource where email='{data.sys_res.email}' and id<>{data.sys_res.id} and delete_time=0");
            }
            else
            {
                findRes = _dal.FindSignleBySql <sys_resource>($"select * from sys_resource where (email='{data.sys_res.email}' or mobile_phone='{data.sys_res.mobile_phone}') and id<>{data.sys_res.id} and delete_time=0");
            }
            if (findRes != null)
            {
                return(ERROR_CODE.SYS_NAME_EXIST);
            }

            var resOld = GetResourceById(resourceId);

            data.sys_res.update_user_id = userId;
            data.sys_res.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            var desc = OperLogBLL.CompareValue <sys_resource>(resOld, data.sys_res);

            if (!string.IsNullOrEmpty(desc))
            {
                _dal.Update(data.sys_res);
                OperLogBLL.OperLogUpdate(desc, data.sys_res.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "编辑员工");
            }

            var userDal = new sys_user_dal();
            var userOld = userDal.FindById(resourceId);

            if (userOld.password != data.sys_user.password)
            {
                data.sys_user.password = new Tools.Cryptographys().SHA1Encrypt(data.sys_user.password);
            }
            desc = OperLogBLL.CompareValue <sys_user>(userOld, data.sys_user);
            if (!string.IsNullOrEmpty(desc))
            {
                userDal.Update(data.sys_user);
                OperLogBLL.OperLogUpdate(desc, data.sys_user.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "编辑员工");
            }


            // 员工每天工作时间
            var dal = new sys_resource_availability_dal();
            var ava = dal.FindSignleBySql <sys_resource_availability>($"select * from sys_resource_availability where resource_id={resourceId} and delete_time=0");

            if (ava == null)
            {
                data.availability.id             = dal.GetNextIdCom();
                data.availability.resource_id    = resourceId;
                data.availability.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                data.availability.update_time    = data.availability.create_time;
                data.availability.create_user_id = userId;
                data.availability.update_user_id = userId;
                dal.Insert(data.availability);
            }
            else
            {
                data.availability.id             = ava.id;
                data.availability.resource_id    = resourceId;
                data.availability.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                data.availability.update_user_id = userId;
                data.availability.create_time    = ava.create_time;
                data.availability.create_user_id = ava.create_user_id;
                dal.Update(data.availability);
            }

            // 员工休假-额外时间
            sys_resource_additional_time_dal timeDal = new sys_resource_additional_time_dal();

            if (data.addTime1 != null)
            {
                var time1 = timeDal.FindSignleBySql <sys_resource_additional_time>($"select * from sys_resource_additional_time where resource_id={resourceId} and period_year={data.addTime1.period_year.Value}");
                if (time1 == null)
                {
                    data.addTime1.id          = timeDal.GetNextIdCom();
                    data.addTime1.resource_id = resourceId;
                    timeDal.Insert(data.addTime1);
                }
                else
                {
                    time1.time_vacation = data.addTime1.time_vacation;
                    time1.time_personal = data.addTime1.time_personal;
                    time1.time_sick     = data.addTime1.time_sick;
                    time1.time_float    = data.addTime1.time_float;
                    timeDal.Update(time1);
                }
            }
            if (data.addTime2 != null)
            {
                var time2 = timeDal.FindSignleBySql <sys_resource_additional_time>($"select * from sys_resource_additional_time where resource_id={resourceId} and period_year={data.addTime2.period_year.Value}");
                if (time2 == null)
                {
                    data.addTime2.id          = timeDal.GetNextIdCom();
                    data.addTime2.resource_id = resourceId;
                    timeDal.Insert(data.addTime2);
                }
                else
                {
                    time2.time_vacation = data.addTime2.time_vacation;
                    time2.time_personal = data.addTime2.time_personal;
                    time2.time_sick     = data.addTime2.time_sick;
                    time2.time_float    = data.addTime2.time_float;
                    timeDal.Update(time2);
                }
            }

            return(ERROR_CODE.SUCCESS);
        }