/// <summary> /// 获取酒店新闻详细信息 /// </summary> public static HotelNews GetNewsDetails(string nid, out int preId, out int afterId, string hotelid) { string SqlStr = "SELECT id,hotelid,title,coverImage,addtime,content FROM HotelNews WITH(NOLOCK) WHERE id=@nid"; DataTable DT = HotelCloud.SqlServer.SQLHelper.Get_DataTable(SqlStr, HotelCloud.SqlServer.SQLHelper.GetCon(), new Dictionary <string, HotelCloud.SqlServer.DBParam> { { "nid", new HotelCloud.SqlServer.DBParam { ParamValue = nid.ToString() } }, }); HotelNews model = new HotelNews(); if (DT.Rows.Count > 0) { System.Data.DataRow dr = DT.Rows[0]; model.Id = Convert.ToInt32(dr["id"].ToString()); model.HotelID = Convert.ToInt32(dr["hotelid"].ToString()); model.Title = dr["title"].ToString(); model.AddTime = Convert.ToDateTime(dr["addtime"].ToString()).ToString("yyyy-MM-dd").ToString(); model.Content = dr["content"].ToString(); model.CoverImage = dr["coverImage"].ToString(); } string sql = @"select top 1 id from Hotelnews where hotelid=@hotelid and id<@nid order by id desc "; string pid = HotelCloud.SqlServer.SQLHelper.Get_Value(sql, HotelCloud.SqlServer.SQLHelper.GetCon(), new Dictionary <string, HotelCloud.SqlServer.DBParam> { { "nid", new HotelCloud.SqlServer.DBParam { ParamValue = nid } }, { "hotelid", new HotelCloud.SqlServer.DBParam { ParamValue = hotelid } } }); if (pid.Equals("")) { preId = Convert.ToInt32(nid); } else { preId = Convert.ToInt32(pid); } string nextid = HotelCloud.SqlServer.SQLHelper.Get_Value("select top 1 id from Hotelnews where hotelid=@hotelid and id>@nid order by id asc", HotelCloud.SqlServer.SQLHelper.GetCon(), new Dictionary <string, HotelCloud.SqlServer.DBParam> { { "nid", new HotelCloud.SqlServer.DBParam { ParamValue = nid } }, { "hotelid", new HotelCloud.SqlServer.DBParam { ParamValue = hotelid } } }); if (nextid.Equals("")) { afterId = Convert.ToInt32(nid); } else { afterId = Convert.ToInt32(nextid); } return(model); }
/// <summary> /// 获取酒店新闻记录数 分页数据操作 /// </summary> public static List <HotelNews> PageNewList(int pageSize, int currentPage, string hid, string filedOrder, out int pageNumSum, out int pageCount, int type = 0) { string strWhere = string.Format(" where hotelid={0} and type={1} AND isview=1 ", hid, type); List <HotelNews> list = new List <HotelNews>(); StringBuilder sqlStr = new StringBuilder(); int beginPage = ((currentPage - 1) * pageSize) + 1; int endPage = currentPage * pageSize; try { sqlStr.Append("select id,hotelid,title,addtime,coverImage "); sqlStr.Append("from (select id,hotelid,title,addtime,coverImage,type,row_number() over(order by " + filedOrder + " desc )"); sqlStr.Append(" as pageNum,isview from HotelNews"); if (!string.IsNullOrEmpty(strWhere.ToString().Trim())) { sqlStr.Append(strWhere); } sqlStr.Append(")" + " as newHotelNews"); if (string.IsNullOrEmpty(strWhere.ToString().Trim())) { sqlStr.Append(" where "); } if (!string.IsNullOrEmpty(strWhere.ToString().Trim())) { sqlStr.Append(strWhere + " and "); } sqlStr.Append(" newHotelNews.pageNum between " + beginPage + " and " + endPage + ""); sqlStr.Append(" order by " + filedOrder + " desc "); var dt = HotelCloud.SqlServer.SQLHelper.Get_DataTable(sqlStr.ToString(), HotelCloud.SqlServer.SQLHelper.GetCon(), null); if (dt != null) { foreach (System.Data.DataRow dr in dt.Rows) { HotelNews model = new HotelNews(); model.Id = Convert.ToInt32(Convert.ToDouble(dr["id"].ToString())); model.HotelID = Convert.ToInt32(Convert.ToDouble(dr["hotelid"].ToString())); model.Title = dr["title"].ToString(); model.AddTime = Convert.ToDateTime(dr["addtime"].ToString()).ToString("yy-MM-dd"); model.Content = Convert.ToDateTime(dr["addtime"].ToString()) > DateTime.Now.AddDays(-30) ? "1" : "0"; model.CoverImage = dr["coverImage"].ToString(); list.Add(model); } } pageCount = GetHotelNewsCount(hid); //总记录数 pageNumSum = pageCount % pageSize == 0 ? pageCount / pageSize : (pageCount / pageSize) + 1; //总页数 return(list); } catch (SqlException e) { throw e; } }