/// <summary> /// 获取置顶信息实体 /// </summary> /// <param name="typeId"></param> /// <returns></returns> public Model.WebNews GetTopModel(int typeId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,title,fromName,fromPath,author,type,typeId,seque,userId,roleId,limits,setHome,defined,putDate,editDate,verifyDate,deadline,contents,details,style,contants,visit,videoHtml,videoType,videoId,videoPath,imageUrl,deteState,IsTop,browsecount from WebNews "); strSql.Append(" where typeId=@typeId Order By IsTop DESC,ID DESC"); SqlParameter[] parameters = { new SqlParameter("@typeId", SqlDbType.Int,4) }; parameters[0].Value = typeId; Model.WebNews model = new Model.WebNews(); DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters); if (dt.Rows.Count > 0) { return DataRowToModel(dt.Rows[0]); } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.WebNews DataRowToModel(DataRow row) { string flag = ""; Model.WebNews model = new Model.WebNews(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["fromName"] != null) { model.fromName = row["fromName"].ToString(); } if (row["fromPath"] != null) { model.fromPath = row["fromPath"].ToString(); } if (row["author"] != null) { model.author = row["author"].ToString(); } if (row["type"] != null) { model.type = row["type"].ToString(); } if (row["typeId"] != null && row["typeId"].ToString() != "") { model.typeId = int.Parse(row["typeId"].ToString()); } if (row["seque"] != null && row["seque"].ToString() != "") { model.seque = int.Parse(row["seque"].ToString()); } if (row["userId"] != null && row["userId"].ToString() != "") { model.userId = int.Parse(row["userId"].ToString()); } if (row["roleId"] != null && row["roleId"].ToString() != "") { model.roleId = int.Parse(row["roleId"].ToString()); } if (row["limits"] != null) { model.limits = row["limits"].ToString(); } if (row["setHome"] != null) { model.setHome = row["setHome"].ToString(); } if (row["defined"] != null) { model.defined = row["defined"].ToString(); } if (row["putDate"] != null && row["putDate"].ToString() != "") { model.putDate = DateTime.Parse(row["putDate"].ToString()); } if (row["editDate"] != null && row["editDate"].ToString() != "") { model.editDate = DateTime.Parse(row["editDate"].ToString()); } if (row["verifyDate"] != null && row["verifyDate"].ToString() != "") { model.verifyDate = DateTime.Parse(row["verifyDate"].ToString()); } if (row["deadline"] != null && row["deadline"].ToString() != "") { model.deadline = int.Parse(row["deadline"].ToString()); } if (row["contents"] != null) { model.contents = row["contents"].ToString(); } if (row["details"] != null) { model.details = row["details"].ToString(); } if (row["style"] != null) { model.style = row["style"].ToString(); } if (row["contants"] != null) { model.contants = row["contants"].ToString(); } if (row["visit"] != null && row["visit"].ToString() != "") { model.visit = int.Parse(row["visit"].ToString()); } if (row["videoHtml"] != null) { model.videoHtml = row["videoHtml"].ToString(); } if (row["videoType"] != null) { model.videoType = row["videoType"].ToString(); } if (row["videoId"] != null && row["videoId"].ToString() != "") { model.videoId = int.Parse(row["videoId"].ToString()); } if (row["videoPath"] != null) { model.videoPath = row["videoPath"].ToString(); } if (row["imageUrl"] != null) { model.imageUrl = row["imageUrl"].ToString(); } if (row["deteState"] != null && row["deteState"].ToString() != "") { model.deteState = int.Parse(row["deteState"].ToString()); } if (row["IsTop"] != null && row["IsTop"].ToString() != "") { if ((row["IsTop"].ToString() == "1") || (row["IsTop"].ToString().ToLower() == "true")) { model.IsTop = true; } else { model.IsTop = false; } } if (row["browsecount"] != null && row["browsecount"].ToString() != "") { model.browsecount = int.Parse(row["browsecount"].ToString()); } } try { dataWork dw = new dataWork(); Hashtable ht = new Hashtable(); ht.Add("browsecount", model.browsecount + 1); dw.ExecUpdate(ht, "WebNews", "id=" + model.id); } catch (Exception) { throw; } return model; }