예제 #1
0
        /// <summary>
        /// 获得所有的部门信息
        /// </summary>
        /// <returns></returns>
        public List <SysDepartEntity> GetList()
        {
            List <SysDepartEntity> listResult = CacheHelper.Get(CacheKey.JOOSHOW_SYSDEPART_CACHE) as List <SysDepartEntity>;

            if (!listResult.IsNullOrEmpty())
            {
                return(listResult);
            }
            SysDepartEntity temp = new SysDepartEntity();

            temp.IncludeID(true)
            .IncludeChildCount(true)
            .IncludeCreateTime(true)
            .IncludeDepartName(true)
            .IncludeDepartNum(true)
            .IncludeDepth(true)
            .IncludeParentNum(true)
            ;
            temp.Where(a => a.IsDelete == (int)EIsDelete.NotDelete);
            listResult = this.SysDepart.GetList(temp);
            if (!listResult.IsNullOrEmpty())
            {
                foreach (SysDepartEntity entity in listResult.Where(itemParent => !string.IsNullOrEmpty(itemParent.ParentNum)))
                {
                    SysDepartEntity tempEntity = listResult.SingleOrDefault(item => item.DepartNum == entity.ParentNum);
                    if (!tempEntity.IsNull())
                    {
                        entity.ParentName = tempEntity.DepartName;
                    }
                }
                CacheHelper.Insert(CacheKey.JOOSHOW_SYSDEPART_CACHE, listResult, null, DateTime.Now.AddHours(5));
            }
            return(listResult);
        }
예제 #2
0
        /// <summary>
        /// 获得所有的部门信息
        /// </summary>
        /// <returns></returns>
        public List <SysDepartEntity> GetList()
        {
            string key = string.Format(CacheKey.JOOSHOW_SYSDEPART_CACHE, this.CompanyID);
            List <SysDepartEntity> listResult = CacheHelper.Get(key) as List <SysDepartEntity>;

            if (!listResult.IsNullOrEmpty())
            {
                return(listResult);
            }
            SysDepartEntity temp = new SysDepartEntity();

            temp.IncludeAll();
            temp.Where(a => a.IsDelete == (int)EIsDelete.NotDelete)
            .And(item => item.CompanyID == this.CompanyID);
            listResult = this.SysDepart.GetList(temp);
            if (!listResult.IsNullOrEmpty())
            {
                foreach (SysDepartEntity item in listResult)
                {
                    int depth = listResult.Where(a => a.Left <= item.Left && a.Right >= item.Right).Count();
                    item.Depth = depth;
                }
                foreach (SysDepartEntity entity in listResult.Where(itemParent => !string.IsNullOrEmpty(itemParent.ParentNum)))
                {
                    SysDepartEntity tempEntity = listResult.SingleOrDefault(item => item.SnNum == entity.ParentNum);
                    if (!tempEntity.IsNull())
                    {
                        entity.ParentName = tempEntity.DepartName;
                    }
                }
                CacheHelper.Insert(key, listResult, null, DateTime.Now.AddDays(1));
            }
            return(listResult);
        }
예제 #3
0
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="list"></param>
        /// <param name="CompanyID"></param>
        /// <returns></returns>
        public int Delete(IEnumerable <string> list)
        {
            string key = string.Format(CacheKey.JOOSHOW_SYSDEPART_CACHE, this.CompanyID);

            using (TransactionScope ts = new TransactionScope())
            {
                int line = 0;

                List <SysDepartEntity> listSource = GetList();
                listSource = listSource.IsNull() ? new List <SysDepartEntity>() : listSource;

                foreach (string item in list)
                {
                    SysDepartEntity parent     = listSource.FirstOrDefault(a => a.SnNum == item);
                    int             rightValue = parent.Right;
                    int             leftValue  = parent.Left;

                    SysDepartEntity delDepart = new SysDepartEntity();
                    delDepart.IsDelete = (int)EIsDelete.Deleted;
                    delDepart.IncludeIsDelete(true);
                    delDepart.Where(a => a.Left >= leftValue)
                    .And(a => a.Right <= rightValue)
                    .And(a => a.CompanyID == this.CompanyID)
                    ;
                    line += this.SysDepart.Update(delDepart);

                    List <SysDepartEntity> listNodes = listSource.Where(a => a.Left > leftValue).ToList();
                    if (!listNodes.IsNullOrEmpty())
                    {
                        foreach (SysDepartEntity depart in listNodes)
                        {
                            depart.Left = depart.Left - (rightValue - leftValue + 1);
                            depart.IncludeLeft(true);
                            depart.Where(a => a.SnNum == depart.SnNum).And(a => a.CompanyID == this.CompanyID);
                            line += this.SysDepart.Update(depart);
                        }
                    }

                    listNodes = listSource.Where(a => a.Right > rightValue).ToList();
                    if (!listNodes.IsNullOrEmpty())
                    {
                        foreach (SysDepartEntity depart in listNodes)
                        {
                            depart.Right = depart.Right - (rightValue - leftValue + 1);
                            depart.IncludeRight(true);
                            depart.Where(a => a.SnNum == depart.SnNum).And(a => a.CompanyID == this.CompanyID);
                            line += this.SysDepart.Update(depart);
                        }
                    }
                }
                ts.Complete();
                if (line > 0)
                {
                    CacheHelper.Remove(key);
                }
                return(line);
            }
        }
예제 #4
0
        /// <summary>
        /// 根据主键编号修改部门信息(修改部门名和部门级别)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UpdateDepartByID(SysDepartEntity entity)
        {
            entity.IncludeDepartName(true)
            .IncludeParentNum(true);
            entity.Where <SysDepartEntity>("ID", ECondition.Eth);
            int line = this.SysDepart.Update(entity);

            if (line > 0)
            {
                CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE);
            }
            return(line);
        }
예제 #5
0
        /// <summary>
        /// 修改部门信息(修改部门名称)
        /// 根据主键和父类编号修改部门信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UpdateDepart(SysDepartEntity entity)
        {
            entity.ThrowIfNull("修改部门信息对象为空");
            entity.IncludeDepartName(true)
            ;
            //entity.Where<SysDepartEntity>("ID", ECondition.Eth)
            //    .And<SysDepartEntity>("ParentNum", ECondition.Eth);
            entity.Where(a => a.DepartNum == entity.DepartNum);
            int line = this.SysDepart.Update(entity);

            if (line > 0)
            {
                CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE);
            }
            return(line);
        }
예제 #6
0
        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(SysDepartEntity entity)
        {
            string key = string.Format(CacheKey.JOOSHOW_SYSDEPART_CACHE, this.CompanyID);

            entity.Include(a => new { a.DepartName });

            int line = 0;

            entity.Where(a => a.SnNum == entity.SnNum)
            .And(item => item.CompanyID == this.CompanyID);
            line = this.SysDepart.Update(entity);
            if (line > 0)
            {
                CacheHelper.Remove(key);
            }
            return(line);
        }
예제 #7
0
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteDepart(int id)
        {
            int             line   = 0;
            SysDepartEntity entity = GetDepartEntity(id);

            if (entity.IsNotNull())
            {
                entity.IncludeIsDelete(true);
                entity.IsDelete = (int)EIsDelete.Deleted;
                entity.Where(a => a.ID == id);
                line = this.SysDepart.Update(entity);
                if (line > 0)
                {
                    CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE);
                }
            }
            return(line);
        }