Esempio n. 1
0
        public ActionResult GetOnlinePage(string pagination, string sdate, string edate)
        {
            if (string.IsNullOrWhiteSpace(sdate))
            {
                sdate = DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (string.IsNullOrWhiteSpace(edate))
            {
                edate = DateTime.Now.ToString("yyyy-MM-dd");
            }
            Pagination      paginationobj = pagination.ToObject <Pagination>();
            T_Online_taurus model         = new T_Online_taurus();

            model.pageIndex  = paginationobj.page;
            model.pageSize   = paginationobj.rows;
            model.totalCount = paginationobj.total;
            model.startDate  = sdate + " 00:00:00";
            model.endDate    = edate + " 23:59:59";


            List <T_Online_taurus> list = _onlie.GetPageList(model);
            var jsonData = new
            {
                rows    = list,
                total   = list.Count > 0 ? list[0].total : 0,
                page    = paginationobj.page,//list[0].pageIndex,
                records = list.Count > 0 ? list[0].totalCount : 0
            };

            return(Success(jsonData));
        }
Esempio n. 2
0
        /// <summary>
        /// 获取时间段的数据
        /// </summary>
        /// <returns></returns>
        public List <T_Online_taurus> GetPageList(T_Online_taurus model)
        {
            using (IDbConnection conn = DapperAdapter.MySQLOpenConnection(ConfigurationHelper.MySQLConnectionStr))
            {
                DynamicParameters param = new DynamicParameters();
                StringBuilder     sb    = new StringBuilder();
                sb.Append("select * from t_online_taurus WHERE onlineCount>0 and updateTime>=@startDate and updateTime<=@endDate ");
                param.Add("@startDate", model.startDate);
                param.Add("@endDate", model.endDate);
                sb.Append(" order by updateTime desc");

                //获取总记录数
                string sqlCount = sb.ToString().Replace("select * ", "select count(1) totalCount ");

                //分页
                if (model.pageIndex >= 0 && model.pageSize > 0)
                {
                    sb.Append(" limit " + ((model.pageIndex - 1) * model.pageSize) + "," + model.pageSize);
                }
                //分页记录列表
                var list = conn.Query <T_Online_taurus>(sb.ToString(), param).ToList();
                if (list != null && list.Count() > 0)
                {
                    //总记录数列表
                    dynamic identity = conn.Query(sqlCount, param).Single();
                    list[0].totalCount = Convert.ToInt64(identity.totalCount);
                    list[0].pageIndex  = model.pageIndex;
                    list[0].pageSize   = model.pageSize;
                }
                return(list);
            }
        }