/// <summary> /// 添加部门 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Add(SysDepartEntity entity) { entity.DepartNum = entity.DepartNum.IsEmpty() ? DateTime.Now.ToString("yyyyMMddHHmmss") + (new Random(DateTime.Now.Millisecond)).Next(1000, 9999) : entity.DepartNum; entity.ChildCount = 0; SysDepartEntity parent = GetSingle(entity.ParentNum); if (parent.IsNotNull()) { entity.Depth = parent.Depth + 1; parent.ChildCount++; parent.IncludeDepth(true) .IncludeChildCount(true) .Where<SysDepartEntity>("DepartNum", ECondition.Eth); this.SysDepart.Update(parent); } entity.IncludeDepartNum(true) .IncludeDepartName(true) .IncludeChildCount(true) .IncludeParentNum(true) .IncludeDepth(true) .IncludeIsDelete(true) .IncludeCreateTime(true) ; int line = this.SysDepart.Add(entity); if (line > 0) { CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE); } return line; }
public static SysDepart_CE ToCE(SysDepartEntity item) { SysDepart_CE target = new SysDepart_CE(); target.ID=item.ID; target.DepartNum=item.DepartNum; target.DepartName=item.DepartName; target.ChildCount=item.ChildCount; target.ParentNum=item.ParentNum; target.Depth=item.Depth; target.IsDelete=item.IsDelete; target.CreateTime=item.CreateTime; return target; }
/// <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; }
/// <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; }
/// <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; }
/// <summary> /// 根据主键编号和父类编号获得部门信息 /// </summary> /// <param name="id"></param> /// <param name="parentID"></param> /// <returns></returns> public SysDepartEntity GetDepartEntity(int id, string ParentNum) { SysDepartEntity entity = new SysDepartEntity() { ID = id, ParentNum = ParentNum }; entity.IncludeID(true) .IncludeDepartNum(true) .IncludeDepartName(true) .IncludeParentNum(true) .IncludeChildCount(true) .IncludeCreateTime(true) .Where<SysDepartEntity>("ID", ECondition.Eth) .And<SysDepartEntity>("ParentNum", ECondition.Eth); List<SysDepartEntity> list = this.SysDepart.GetList(entity); return list.IsNullOrEmpty() ? null : list[0]; }
/// <summary> /// 根据部门编号获得部门信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public SysDepartEntity GetDepartEntity(string DepartNum) { SysDepartEntity entity = new SysDepartEntity() { DepartNum = DepartNum }; entity.IncludeID(true) .IncludeDepartNum(true) .IncludeDepartName(true) .IncludeParentNum(true) .Where<SysDepartEntity>("DepartNum", ECondition.Eth); return this.SysDepart.GetSingle(entity); }
/// <summary> /// 批量删除部门 /// </summary> /// <param name="items"></param> /// <returns></returns> public int DeleteDepart(int[] items) { SysDepartEntity entity = new SysDepartEntity(); int line = this.SysDepart.Delete(items); if (line > 0) { CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE); } return line; }
/// <summary> /// 查询用户管理员分页 /// </summary> /// <param name="entity"></param> /// <param name="pageInfo"></param> /// <returns></returns> public List<AdminEntity> GetList(AdminEntity entity, ref PageInfo pageInfo) { entity.IncludeAll(); entity.OrderBy(a => a.ID, EOrderBy.DESC); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete); SysRoleEntity roleEntity = new SysRoleEntity(); roleEntity.Include("RoleName", "RoleName"); entity.Left<SysRoleEntity>(roleEntity, new Params<string, string>() { Item1 = "RoleNum", Item2 = "RoleNum" }); SysDepartEntity departEntity = new SysDepartEntity(); departEntity.Include("DepartName", "DepartName"); entity.Left<SysDepartEntity>(departEntity, new Params<string, string>() { Item1 = "DepartNum", Item2 = "DepartNum" }); int rowCount = 0; List<AdminEntity> listResult = this.Admin.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount); pageInfo.RowCount = rowCount; return listResult; }
public ActionResult ToExcel() { PageInfo pageInfo = new Git.Framework.DataTypes.PageInfo() { PageIndex = 1, PageSize = Int32.MaxValue }; string departName = WebUtil.GetFormValue<string>("departName", string.Empty); DepartProvider provider = new DepartProvider(); SysDepartEntity entity = new SysDepartEntity(); List<SysDepartEntity> list = provider.GetList(); List<SysDepartEntity> listResult = new List<SysDepartEntity>(); if (!list.IsNullOrEmpty()) { listResult = list.Where(a => a.DepartName.Contains(departName) || a.DepartNum.Contains(departName)).OrderByDescending(a => a.ID).ToList(); } if (!listResult.IsNullOrEmpty()) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("序号")); dt.Columns.Add(new DataColumn("部门编号")); dt.Columns.Add(new DataColumn("部门名")); dt.Columns.Add(new DataColumn("创建时间")); int count = 1; foreach (SysDepartEntity t in listResult) { DataRow row = dt.NewRow(); row[0] = count; row[1] = t.DepartNum; row[2] = t.DepartName; row[3] = t.CreateTime; count++; dt.Rows.Add(row); } string filePath = Server.MapPath("~/UploadFiles/"); if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } string filename = string.Format("部门管理{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmss")); NPOIExcel excel = new NPOIExcel("部门管理", "部门", System.IO.Path.Combine(filePath, filename)); excel.ToExcel(dt); this.ReturnJson.AddProperty("Path", ("/UploadFiles/" + filename).Escape()); } else { this.ReturnJson.AddProperty("d", "无数据导出!"); } return Content(this.ReturnJson.ToString()); }