private void get_pro_list(HttpContext context) { int page = DTRequest.GetInt("page", 1); int category = DTRequest.GetInt("category", 0); int uid = DTRequest.GetInt("uid", 0); string keywords = DTRequest.GetString("keywords"); string city = DTRequest.GetString("city"); int count = 0; int pageSize = 8; int sum = 0; if (uid == 0) { sum = new BLL.product().GetCount("status=2 and city=" + (city == "未知" ? "city" : "'" + city + "'") + " and category=" + (category == 0 ? "category" : category.ToString())); } else { sum = new BLL.product().GetCount("status=2 and user_id=" + uid); } if ((page - 1) * pageSize >= sum) { //没有更多数据 context.Response.Write("{\"status\":0,\"msg\":\"没有更多数据\"}"); return; } DataSet ds = new DataSet(); if (uid == 0) { ds = new BLL.product().GetList(pageSize, page, "status=2 and city=" + (city == "未知" ? "city" : "'" + city + "'") + " and category=" + (category == 0 ? "category" : category.ToString()) + " and title like '%" + keywords + "%'", "pass_time desc", out count); } else { ds = new BLL.product().GetList(pageSize, page, "status=2 and user_id=" + uid, "pass_time desc", out count); } DataTable dt = ds.Tables[0]; dt.Columns.Add("zan", typeof(int)); dt.Columns.Add("collect", typeof(int)); dt.Columns.Add("view", typeof(int)); foreach (DataRow dr in dt.Rows) { dr["view"] = new BLL.news_view().GetCount("news_id=" + dr["id"].ToString() + " and isPN=1 and type=1"); dr["collect"] = new BLL.news_commend().GetCount("news_id=" + dr["id"].ToString()); dr["zan"] = new BLL.news_view().GetCount("news_id=" + dr["id"].ToString() + " and isPN=1 and type=2"); } string strJson = DTcms.Common.JsonHelper.DataTableToJSON(ds.Tables[0]); context.Response.Write(strJson); }
private void get_news_list(HttpContext context) { int page = DTRequest.GetInt("page", 1); string keywords = DTRequest.GetString("keywords"); int count = 0; int pageSize = 4; int sum = new BLL.news().GetCount(""); if ((page - 1) * pageSize > sum) { //没有更多数据 context.Response.Write("{\"status\":0,\"msg\":\"没有更多数据\"}"); return; } DataSet ds = new BLL.news().GetList(pageSize, page, "title like '%" + keywords + "%'", "sort,time desc", out count); DataTable dt = ds.Tables[0]; dt.Columns.Add("zan", typeof(int)); dt.Columns.Add("collect", typeof(int)); dt.Columns.Add("view", typeof(int)); string[] arr = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { arr[i] = Convert.ToDateTime(dt.Rows[i]["time"].ToString()).ToString("yyyy-MM-dd HH:mm"); } dt.Columns.Remove("time"); dt.Columns.Add("time", typeof(string)); foreach (DataRow dr in dt.Rows) { dr["view"] = new BLL.news_view().GetCount("news_id=" + dr["id"].ToString() + " and isPN=2 and type=1"); dr["collect"] = new BLL.news_commend().GetCount("news_id=" + dr["id"].ToString()); dr["zan"] = new BLL.news_view().GetCount("news_id=" + dr["id"].ToString() + " and isPN=2 and type=2"); dr["time"] = arr[dt.Rows.IndexOf(dr)]; } string strJson = DTcms.Common.JsonHelper.DataTableToJSON(ds.Tables[0]); context.Response.Write(strJson); }
//收藏列表,点赞列表 private void get_user_view_list(HttpContext context) { int uid = DTRequest.GetInt("uid", 0); int isPN = DTRequest.GetInt("isPN", 0); int type = DTRequest.GetInt("type", 0); DataTable dt = new BLL.news_view().GetList(0, "type=" + type + " and isPN=" + isPN + " and user_id=" + uid, "time desc").Tables[0]; dt.Columns.Add("title", typeof(string)); dt.Columns.Add("cont", typeof(string)); dt.Columns.Add("day", typeof(string)); foreach (DataRow dr in dt.Rows) { string title, cont; if (isPN == 1) { Model.product model = new BLL.product().GetModel(Convert.ToInt32(dr["news_id"])); title = model.title; if (model.cont.Length > 60) { cont = model.cont.Substring(0, 60) + "..."; } else { cont = model.cont; } } else { Model.news model = new BLL.news().GetModel(Convert.ToInt32(dr["news_id"])); title = model.title; if (model.zhaiyao.Length > 60) { cont = model.zhaiyao.Substring(0, 60) + "..."; } else { cont = model.zhaiyao; } } dr["title"] = title; dr["cont"] = cont; //时间隔计算 DateTime t1 = DateTime.Now; DateTime t2 = Convert.ToDateTime(dr["time"]); TimeSpan ts = t1.Subtract(t2); if (ts.Days > 3) { dr["day"] = Convert.ToDateTime(dr["time"]).ToString("yyyy-MM-dd"); } else if (ts.Days > 0) { dr["day"] = ts.Days + "天前"; } else if (ts.Hours > 0) { dr["day"] = ts.Hours + "小时前"; } else if (ts.Minutes > 0) { dr["day"] = ts.Minutes + "分钟前"; } else if (ts.Seconds > 0) { dr["day"] = ts.Seconds + "秒前"; } else { dr["day"] = "未知"; } } context.Response.Write(JsonHelper.DataTableToJSON(dt)); }