Ejemplo n.º 1
0
 public ActionResult RoleList(int pageIndex, int pageSize, string roleName)
 {
     SysRoleProvider provider = new SysRoleProvider();
     List<SysRoleEntity> list = provider.GetList();
     List<SysRoleEntity> listResult = new List<SysRoleEntity>();
     List<SysRoleEntity> returnList = new List<SysRoleEntity>();
     if (!list.IsNullOrEmpty())
     {
         listResult = list.Where(a => a.RoleNum.Contains(roleName) || a.RoleName.Contains(roleName)).ToList();
         returnList = listResult.Skip((pageIndex - 1) * pageSize).Take(pageSize).OrderByDescending(a => a.ID).ToList();
     }
     this.ReturnJson.AddProperty("Data", ConvertJson.ListToJson<SysRoleEntity>(returnList, "List"));
     this.ReturnJson.AddProperty("RowCount", listResult.Count);
     return Content(this.ReturnJson.ToString());
 }
Ejemplo n.º 2
0
        public ActionResult ToExcel()
        {
            PageInfo pageInfo = new Git.Framework.DataTypes.PageInfo() { PageIndex = 1, PageSize = Int32.MaxValue };
            string roleName = WebUtil.GetFormValue<string>("roleName", string.Empty);
            SysRoleProvider provider = new SysRoleProvider();
            SysRoleEntity entity = new SysRoleEntity();
            List<SysRoleEntity> list = provider.GetList();
            List<SysRoleEntity> listResult = new List<SysRoleEntity>();
            if (!list.IsNullOrEmpty())
            {
                listResult = list.Where(a => a.RoleNum.Contains(roleName) || a.RoleName.Contains(roleName)).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("创建时间"));
                dt.Columns.Add(new DataColumn("备注"));
                int count = 1;
                foreach (SysRoleEntity t in listResult)
                {
                    DataRow row = dt.NewRow();
                    row[0] = count;
                    row[1] = t.RoleNum;
                    row[2] = t.RoleName;
                    row[3] = t.CreateTime;
                    row[4] = t.Remark;
                    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());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获得角色的下拉列表
 /// </summary>
 /// <param name="roleNum">角色编号</param>
 /// <returns></returns>
 public static string GetRoleList(string roleNum)
 {
     SysRoleProvider provider = new SysRoleProvider();
     List<SysRoleEntity> list = provider.GetList();
     StringBuilder sb = new StringBuilder();
     string roleTemplate = "<option value='{0}' {1}>{2}</option>";
     sb.AppendFormat(roleTemplate, "", "", "请选择角色");
     if (!list.IsNullOrEmpty())
     {
         foreach (SysRoleEntity role in list)
         {
             sb.AppendFormat(roleTemplate, role.RoleNum, role.RoleNum == roleNum ? "selected='selected'" : string.Empty, role.RoleName);
         }
     }
     return sb.ToString();
 }