Esempio n. 1
0
        /// <summary>
        /// 导出excel
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public FileResult ExportExcel(string username = "", string mobile = "")
        {
            StringBuilder strb = new StringBuilder();

            strb.Append(" where 1=1");
            if (username != "")
            {
                strb.Append(" and a.username like '" + username + "%'");
            }

            if (mobile != "")
            {
                strb.Append(" and a.mobile='" + mobile + "'");
            }

            strb.Append("order by a.uid desc");


            DataTable dt = AdminUsers.GetUserList(-1, 1, strb.ToString());

            Dictionary <string, string> listcol = new Dictionary <string, string>()
            {
            };

            listcol["编号"]   = "uid"; listcol["用户名"] = "username"; listcol["手机"] = "mobile"; listcol["姓名"] = "nickname"; listcol["职位"] = "userrank"; listcol["推荐人"] = "recomuser";
            listcol["在用套餐"] = "hassuite"; listcol["剩余分钟数"] = "totalmin"; listcol["有效期"] = "remainmin"; listcol["充值总额"] = "recharge"; listcol["总赠送分钟数"] = "giftmin";
            listcol["收益总额"] = "totalincome"; listcol["注册时间"] = "registertime";
            listcol["访问时间"] = "lastvisittime";

            string html = ExcelHelper.BuildHtml(dt, listcol);


            //第一种:使用FileContentResult
            byte[] fileContents = Encoding.Default.GetBytes(html);
            return(File(fileContents, "application/ms-excel", "用户信息" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"));

            ////第二种:使用FileStreamResult
            //var fileStream = new MemoryStream(fileContents);
            //return File(fileStream, "application/ms-excel", "fileStream.xls");

            ////第三种:使用FilePathResult
            ////服务器上首先必须要有这个Excel文件,然会通过Server.MapPath获取路径返回.
            //var fileName = Server.MapPath("~/Files/fileName.xls");
            //return File(fileName, "application/ms-excel", "fileName.xls");
        }
Esempio n. 2
0
        /// <summary>
        /// 用户列表
        /// </summary>
        public ActionResult List(string userName = "", string mobile = "", int userrid = -1, int pageNumber = 1, int pageSize = 15)
        {
            HashSet <string> actionlist = AdminGroups.GetAdminGroupActionHashSetNoCache(WorkContext.AdminGid);

            ShopUtils.SetAdminRefererCookie(string.Format("{0}?pageNumber={1}&pageSize={2}&userName={3}&mobile={4}&userrid={5}",
                                                          Url.Action("list"), pageNumber, pageSize,
                                                          userName, mobile, userrid));

            StringBuilder strb = new StringBuilder();

            strb.Append(" where 1=1");
            if (userName != "")
            {
                strb.Append(" and a.nickname like '%" + userName + "%'");
            }

            if (mobile != "")
            {
                strb.Append(" and a.mobile='" + mobile + "'");
            }

            strb.Append("order by a.uid desc");


            DataTable dt = AdminUsers.GetUserList(pageSize, pageNumber, strb.ToString());

            if (dt.Columns[0].ColumnName == "error")
            {
                return(PromptView("用户获取失败"));
            }

            UserListModel model = new UserListModel()
            {
                PageModel = new PageModel(pageSize, pageNumber, dt.Rows.Count > 0 ? int.Parse(dt.Rows[0]["TotalCount"].ToString()) : 0),
                UserList  = dt,
                UserName  = userName,
                Mobile    = mobile,
                UserRid   = userrid
            };


            return(View(model));
        }