/// <summary> /// 得到下一个或上一个实体 /// </summary> /// <param name="Id"></param> /// <returns></returns> public Spread.Model.Protocol GetUpDownModel(int Id, bool UpOrDown) { StringBuilder strSql = new StringBuilder(); if (UpOrDown) { strSql.Append("select top 1 * from [Protocol] WHERE Id > @Id order by Id asc "); } else { strSql.Append("select * from [Protocol] WHERE Id < @Id order by Id desc "); } SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4)}; parameters[0].Value = Id; Spread.Model.Protocol model = new Spread.Model.Protocol(); DataSet ds = DbHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.Author = ds.Tables[0].Rows[0]["Author"].ToString(); model.Form = ds.Tables[0].Rows[0]["Form"].ToString(); if (ds.Tables[0].Rows[0]["ClassId"].ToString() != "") { model.ClassId = int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString()); } model.ImgUrl = ds.Tables[0].Rows[0]["ImgUrl"].ToString(); model.Content = ds.Tables[0].Rows[0]["Content"].ToString(); if (ds.Tables[0].Rows[0]["Click"].ToString() != "") { model.Click = int.Parse(ds.Tables[0].Rows[0]["Click"].ToString()); } if (ds.Tables[0].Rows[0]["IsMsg"].ToString() != "") { model.IsMsg = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsMsg"].ToString()); } if (ds.Tables[0].Rows[0]["IsTop"].ToString() != "") { model.IsTop = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsTop"].ToString()); } if (ds.Tables[0].Rows[0]["IsRed"].ToString() != "") { model.IsRed = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsRed"].ToString()); } if (ds.Tables[0].Rows[0]["IsHot"].ToString() != "") { model.IsHot = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsHot"].ToString()); } if (ds.Tables[0].Rows[0]["IsSlide"].ToString() != "") { model.IsSlide = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsSlide"].ToString()); } if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } return model; } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Spread.Model.Protocol GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Title,Author,Form,ClassId,ImgUrl,Content,Click,IsMsg,IsTop,IsRed,IsHot,IsSlide,AddTime from Protocol "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4)}; parameters[0].Value = Id; Spread.Model.Protocol model = new Spread.Model.Protocol(); DataSet ds = DbHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.Author = ds.Tables[0].Rows[0]["Author"].ToString(); model.Form = ds.Tables[0].Rows[0]["Form"].ToString(); if (ds.Tables[0].Rows[0]["ClassId"].ToString() != "") { model.ClassId = int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString()); } model.ImgUrl = ds.Tables[0].Rows[0]["ImgUrl"].ToString(); model.Content = ds.Tables[0].Rows[0]["Content"].ToString(); if (ds.Tables[0].Rows[0]["Click"].ToString() != "") { model.Click = int.Parse(ds.Tables[0].Rows[0]["Click"].ToString()); } if (ds.Tables[0].Rows[0]["IsMsg"].ToString() != "") { model.IsMsg = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsMsg"].ToString()); } if (ds.Tables[0].Rows[0]["IsTop"].ToString() != "") { model.IsTop = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsTop"].ToString()); } if (ds.Tables[0].Rows[0]["IsRed"].ToString() != "") { model.IsRed = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsRed"].ToString()); } if (ds.Tables[0].Rows[0]["IsHot"].ToString() != "") { model.IsHot = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsHot"].ToString()); } if (ds.Tables[0].Rows[0]["IsSlide"].ToString() != "") { model.IsSlide = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsSlide"].ToString()); } if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } return model; } else { return null; } }