示例#1
0
        public HttpResponseMessage GetVisitsPage()
        {
            ReturnHelper rh    = new ReturnHelper(200, null, 0, "");
            string       key   = HttpContext.Current.Request["key"];
            string       limit = HttpContext.Current.Request["limit"];
            string       page  = HttpContext.Current.Request["page"];

            try
            {
                if (string.IsNullOrEmpty(limit) || string.IsNullOrEmpty(page))
                {
                    rh.msg  = "缺少分页参数";
                    rh.code = 300;
                }
                else
                {
                    Visits obj      = new Visits();
                    string strWhere = " 1=1";
                    if (!string.IsNullOrEmpty(key))
                    {
                        strWhere += string.Format(" and (Ip like '%{0}%' or Address like '%{0}%' or Browser like '%{0}%')", key);
                    }
                    int       begin = (Convert.ToInt32(page) - 1) * Convert.ToInt32(limit);
                    int       end   = Convert.ToInt32(page) * Convert.ToInt32(limit);
                    DataTable dt    = obj.GetPage("*", "Visittime desc", strWhere, begin, end);
                    if (dt.Rows.Count > 0)
                    {
                        rh.totals = SqlHelper.Count(string.Format("select * from Visits where {0}", strWhere), SqlHelper.CreateConn());
                        rh.data   = dt;
                        rh.msg    = "获取成功";
                    }
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "处理错误";
            }
            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }