예제 #1
0
        public static string GetList(string key, int PageIndex, int PageSize)
        {
            try
            {
                key       = key.Filter();
                PageIndex = Convert.ToInt32(PageIndex.ToString().Filter());
                DataTable     dt          = new DataTable();
                List <object> listReturn  = new List <object>();
                string        strSql      = string.Empty;
                string        strSqlCount = string.Empty;
                string        strWhere    = "1=1 ";

                if (!string.IsNullOrEmpty(key))
                {
                    strWhere += " and notice_title like '%" + key + "%'";
                }
                BLL_NoticeBoard bll = new BLL_NoticeBoard();
                dt = bll.GetListByPage(strWhere, "create_time desc", ((PageIndex - 1) * PageSize + 1), (PageIndex * PageSize)).Tables[0];
                int rCount = bll.GetRecordCount(strWhere);
                int inum   = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    inum++;
                    listReturn.Add(new
                    {
                        inum           = (i + 1),
                        notice_id      = dt.Rows[i]["notice_id"].ToString(),
                        notice_title   = dt.Rows[i]["notice_title"].ToString(),
                        notice_content = pfunction.GetSubstring(dt.Rows[i]["notice_content"].ToString(), 200, true),
                        create_time    = pfunction.ConvertToLongDateTime(dt.Rows[i]["create_time"].ToString(), "yyyy-MM-dd HH:mm:ss"),
                        start_time     = pfunction.ConvertToLongDateTime(dt.Rows[i]["start_time"].ToString(), "yyyy-MM-dd HH:mm"),
                        end_time       = pfunction.ConvertToLongDateTime(dt.Rows[i]["end_time"].ToString(), "yyyy-MM-dd HH:mm"),
                    });
                }

                if (inum > 0)
                {
                    return(JsonConvert.SerializeObject(new
                    {
                        err = "null",
                        PageIndex = PageIndex,
                        PageSize = PageSize,
                        TotalCount = rCount,
                        list = listReturn
                    }));
                }
                else
                {
                    return(JsonConvert.SerializeObject(new
                    {
                        err = "暂无数据"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new
                {
                    err = "error"//ex.Message.ToString()
                }));
            }
        }