/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CMS_Article GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,ColumnId,Title,Author,PostDate,IsPic,PicUrl,Body,onTop,ReadTimes,titleColor,titleFont from CMS_Article "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Maticsoft.Model.CMS_Article model = new Maticsoft.Model.CMS_Article(); DataSet ds = DbHelperSQL.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()); } if (ds.Tables[0].Rows[0]["ColumnId"].ToString() != "") { model.ColumnId = int.Parse(ds.Tables[0].Rows[0]["ColumnId"].ToString()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.Author = ds.Tables[0].Rows[0]["Author"].ToString(); if (ds.Tables[0].Rows[0]["PostDate"].ToString() != "") { model.PostDate = DateTime.Parse(ds.Tables[0].Rows[0]["PostDate"].ToString()); } if (ds.Tables[0].Rows[0]["IsPic"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsPic"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsPic"].ToString().ToLower() == "true")) { model.IsPic = true; } else { model.IsPic = false; } } model.PicUrl = ds.Tables[0].Rows[0]["PicUrl"].ToString(); model.Body = ds.Tables[0].Rows[0]["Body"].ToString(); if (ds.Tables[0].Rows[0]["ColumnId"].ToString() != "") { model.onTop = int.Parse(ds.Tables[0].Rows[0]["onTop"].ToString()); } model.ReadTimes = int.Parse(ds.Tables[0].Rows[0]["ReadTimes"].ToString()); model.titleColor = ds.Tables[0].Rows[0]["titleColor"].ToString(); model.titleFont = int.Parse(ds.Tables[0].Rows[0]["titleFont"].ToString()); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.CMS_Article model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CMS_Article set "); strSql.Append("ColumnId=@ColumnId,"); strSql.Append("Title=@Title,"); strSql.Append("Author=@Author,"); strSql.Append("PostDate=@PostDate,"); strSql.Append("IsPic=@IsPic,"); strSql.Append("PicUrl=@PicUrl,"); strSql.Append("Body=@Body,"); strSql.Append("onTop=@onTop,"); strSql.Append("ReadTimes=@ReadTimes,"); strSql.Append("titleColor=@titleColor,"); strSql.Append("titleFont=@titleFont"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@ColumnId", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.VarChar, 100), new SqlParameter("@Author", SqlDbType.VarChar, 50), new SqlParameter("@PostDate", SqlDbType.DateTime), new SqlParameter("@IsPic", SqlDbType.Bit, 1), new SqlParameter("@PicUrl", SqlDbType.VarChar, 100), new SqlParameter("@Body", SqlDbType.Text), new SqlParameter("@onTop", SqlDbType.Int, 4), new SqlParameter("@ReadTimes", SqlDbType.Int, 4), new SqlParameter("@titleColor", SqlDbType.VarChar, 50), new SqlParameter("@titleFont", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.ColumnId; parameters[1].Value = model.Title; parameters[2].Value = model.Author; parameters[3].Value = model.PostDate; parameters[4].Value = model.IsPic; parameters[5].Value = model.PicUrl; parameters[6].Value = model.Body; parameters[7].Value = model.onTop; parameters[8].Value = model.ReadTimes; parameters[9].Value = model.titleColor; parameters[10].Value = model.titleFont; parameters[11].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 处理置顶问题 /// </summary> /// <param name="id">欲被置顶新闻Id</param> public void doOnTop(int id) { Maticsoft.Model.CMS_Article atc = new Maticsoft.Model.CMS_Article(); atc = GetModel(id); if (atc.onTop != 0) // 如果有置顶值换为0,即取消置顶 { atc.onTop = 0; } else { atc.onTop = GetMaxTop(); // 若无置顶值,取最大置顶值加1后置顶 } Update(atc); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.CMS_Article model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CMS_Article("); strSql.Append("ColumnId,Title,Author,PostDate,IsPic,PicUrl,Body)"); strSql.Append(" values ("); strSql.Append("@ColumnId,@Title,@Author,@PostDate,@IsPic,@PicUrl,@Body)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ColumnId", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.VarChar, 100), new SqlParameter("@Author", SqlDbType.VarChar, 50), new SqlParameter("@PostDate", SqlDbType.DateTime), new SqlParameter("@IsPic", SqlDbType.Bit, 1), new SqlParameter("@PicUrl", SqlDbType.VarChar, 100), new SqlParameter("@Body", SqlDbType.Text) }; parameters[0].Value = model.ColumnId; parameters[1].Value = model.Title; parameters[2].Value = model.Author; parameters[3].Value = model.PostDate; parameters[4].Value = model.IsPic; parameters[5].Value = model.PicUrl; parameters[6].Value = model.Body; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.CMS_Article model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CMS_Article("); strSql.Append("ColumnId,Title,Author,PostDate,IsPic,PicUrl,Body,onTop,ReadTimes,titleColor,titleFont,ZhuantiId)"); strSql.Append(" values ("); strSql.Append("@ColumnId,@Title,@Author,@PostDate,@IsPic,@PicUrl,@Body,@onTop,@ReadTimes,@titleColor,@titleFont,@ZhuantiId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ColumnId", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.VarChar, 100), new SqlParameter("@Author", SqlDbType.VarChar, 50), new SqlParameter("@PostDate", SqlDbType.DateTime), new SqlParameter("@IsPic", SqlDbType.Bit, 1), new SqlParameter("@PicUrl", SqlDbType.VarChar, 100), new SqlParameter("@Body", SqlDbType.Text), new SqlParameter("@onTop", SqlDbType.Int, 4), new SqlParameter("@ReadTimes", SqlDbType.Int, 4), new SqlParameter("@titleColor", SqlDbType.VarChar, 50), new SqlParameter("@titleFont", SqlDbType.Int, 4), new SqlParameter("@ZhuantiId", SqlDbType.Int, 4) }; parameters[0].Value = model.ColumnId; parameters[1].Value = model.Title; parameters[2].Value = model.Author; parameters[3].Value = model.PostDate; parameters[4].Value = model.IsPic; parameters[5].Value = model.PicUrl; parameters[6].Value = model.Body; parameters[7].Value = model.onTop; parameters[8].Value = model.ReadTimes; parameters[9].Value = model.titleColor; parameters[10].Value = model.titleFont; parameters[11].Value = model.ZhuantiId; //某个栏目下的文章数量从0变动到1,1变动到2,需要更新该栏目的父栏目对应的“新闻栏目列表页” //int rowsCount = 0; //object objrowsCount = DbHelperSQL.GetSingle("select count(*) from CMS_Article where ColumnId=" + ColumnId); //if (objrowsCount != null) //{ // rowsCount = int.Parse(objrowsCount.ToString()); //} //if (rowsCount == 1 || rowsCount == 2) //{ // CreateHtml chColumnList = new CreateHtml("List", thePath); // chColumnList.CreateColumnList(Column.GetParentId(ColumnId)); //} //某个栏目下的文章数量从1变动到2的时候,要增加一个对应的“新闻列表页” //if (rowsCount == 2) //{ // CreateHtml chArticleList = new CreateHtml("List", thePath); // chArticleList.CreateArticleList(ColumnId); //} object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); //每次添加一条新闻的同时生成对应页面 CreateHtml ch = new CreateHtml("ShowArticle", HttpContext.Current.Server.MapPath("/")); ch.CreateShowArticle(int.Parse(obj.ToString())); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }