// 删除一条新闻 或 将其置顶 protected void GVinfo_RowCommand(object sender, GridViewCommandEventArgs e) { int Id = 0; // 保存ID int theRow = 0; // 保存行号 string theCol = ""; // 保存列位置信息 theRow = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; theCol = e.CommandName.ToString(); Id = Convert.ToInt32(GVinfo.DataKeys[theRow].Value); BLL.CMS_Article bAtc = new BLL.CMS_Article(); Model.CMS_Article art = new Model.CMS_Article(); art = bAtc.GetModel(Id); switch (e.CommandName) { case "MyDel": { DoSetting(Convert.ToInt32(art.ColumnId), "删除"); bAtc.Delete(Id); break; } // 删除操作 case "MyUp": { DoSetting(Convert.ToInt32(art.ColumnId), "修改"); bAtc.doOnTop(Id); break; } // 置顶操作 } Flush(strWhere); }
/// <summary> /// 替换文章模板中的标签 /// </summary> /// <param name="tmpBody"></param> /// <param name="id"></param> /// <param name="titleLen"></param> /// <returns></returns> private string ReplaceArticleDetail(string tmpBody, int id, int titleLen) { CMS_Article dart = new CMS_Article(); Model.CMS_Article art = dart.GetModel(id); StringBuilder sb = new StringBuilder(); sb.Append(tmpBody); sb.Replace("{$ArticleId$}", art.Id.ToString()); string titleColor = art.titleColor; int titleFont = art.titleFont; string titleFontStr = ""; string articleTitle = art.Title; if (titleLen != 0) { articleTitle = articleTitle.Remove(titleLen); //articleTitle = Utils.ClipString(articleTitle, titleLen); } switch (titleFont) { case 1: titleFontStr = "font-weight:bold"; break; case 2: titleFontStr = "font-style:italic"; break; case 3: titleFontStr = "font-weight:bold;font-style:italic"; break; default: break; } if (titleColor != "black" || titleFontStr != "") { if (titleColor != "black") { articleTitle = "<span style='color:" + titleColor + ";" + titleFontStr + "'>" + articleTitle + "</span>"; } else { articleTitle = "<span style='" + titleFontStr + "'>" + articleTitle + "</span>"; } } sb.Replace("{$ArticleTitle$}", articleTitle); sb.Replace("{$HeadArticleTitle$}", art.Title); sb.Replace("{$ArticleAuthor$}", art.Author); sb.Replace("{$ArticlePostDate$}", art.PostDate.ToString()); sb.Replace("{$ArticlePicUrl$}", art.PicUrl); sb.Replace("{$ArticleBody$}", art.Body); sb.Replace("{$ArticleReadTimes$}", art.ReadTimes.ToString()); sb.Replace("{$ColumnName$}", art.SearchColumnName(Convert.ToInt32(art.ColumnId))); sb.Replace("{$ArticleLink$}", "Article_" + art.Id + ".html"); sb.Replace("/userfiles", "../../userfiles"); return(sb.ToString()); }
protected void btSave_Click(object sender, EventArgs e) { Model.CMS_Article mArt = new Model.CMS_Article(); BLL.CMS_Article bArt = new BLL.CMS_Article(); mArt = CurrentId > 0 ? bArt.GetModel(CurrentId) : mArt; mArt.Title = tbTitle.Text.Trim(); mArt.titleColor = ddlTitCor.Items[ddlTitCor.SelectedIndex].Value; mArt.titleFont = Convert.ToInt32(ddlTitSty.Items[ddlTitSty.SelectedIndex].Value); mArt.Author = tbAuthor.Text.Trim(); mArt.Body = FCKeditor1.Value; mArt.ColumnId = Validator.StrToId(ddlCol.SelectedValue); mArt.ZhuantiId = 0; DoSetting(Convert.ToInt32(mArt.ColumnId), "新增"); if (FileUpload1.HasFile) { string filePath = Server.MapPath("~\\userfiles\\"); string fileName = FileUpload1.PostedFile.FileName; fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1); FileUpload1.SaveAs(filePath + fileName); mArt.IsPic = true; mArt.PicUrl = filePath + fileName; } else { if (CurrentId == 0) // 防止覆盖修改情况下被覆盖 { mArt.IsPic = false; mArt.PicUrl = ""; } } if (CurrentId == 0) { DoSetting(Convert.ToInt32(mArt.ColumnId), "新增"); mArt.PostDate = DateTime.Now; mArt.onTop = 0; bArt.Add(mArt); } else { DoSetting(Convert.ToInt32(mArt.ColumnId), "修改"); bArt.Update(mArt); } Response.Redirect("News.aspx"); }
/// <summary> /// 批量删除 /// </summary> /// <param name="Idlist">包含的ID</param> public bool DeleteList(string Idlist) { if (Idlist == "") { return(true); } string[] currentId = Idlist.Split(','); Model.CMS_Article mArt = new Model.CMS_Article(); mArt = GetModel(int.Parse(currentId[0])); int?theColumnId = mArt.ColumnId; //在删除新闻的同时删除对应页面 和 文中的图片 foreach (string theId in currentId) { File.Delete(thePath + @"html\ArticleArticle_" + theId + ".html"); // 删除对应页面 Model.CMS_Article atc = GetModel(int.Parse(theId)); if (atc.IsPic == true) { DeletePic(atc.PicUrl); // 删除标题图片 } DeletePics(atc.Body); // 删除内容图片 } //在数据库中删除记录 StringBuilder strSql = new StringBuilder(); strSql.Append("delete CMS_Article "); strSql.AppendFormat(" where Id in ({0},0)", Idlist); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { return(true); } else { return(false); } //某个栏目下的文章数量从2变动到1,1变动到0,需要更新该栏目的父栏目对应的“新闻栏目列表页” //DO SOMETHING //某个栏目下的文章数量从2变动到1的时候,要删除一个对应的“新闻列表页” //DO SOMETHING }
/// <summary> /// 删除一条数据 --经过改造 /// </summary> public bool Delete(int Id) { Model.CMS_Article ac = GetModel(Id); //先删除对应图片 DeletePics(ac.Body); //Body里的 if (ac.IsPic == true) { DeletePic(ac.PicUrl.Substring(ac.PicUrl.LastIndexOf("\\"))); } StringBuilder strSql = new StringBuilder(); strSql.Append("delete from CMS_Article "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; string a = thePath + @"html\ArticleArticle_" + Id + ".html"; //在删除一条新闻的同时删除对应页面 File.Delete(thePath + @"html\ArticleArticle_" + Id + ".html"); //某个栏目下的文章数量从2变动到1,1变动到0,需要更新该栏目的父栏目对应的“新闻栏目列表页” //DO SOMETHING //某个栏目下的文章数量从2变动到1的时候,要删除一个对应的“新闻列表页” //DO SOMETHING int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void ShowEditor() { CMS_Article bArt = new CMS_Article(); CMS_Column bCol = new CMS_Column(); Model.CMS_Article mArt = new Model.CMS_Article(); if (CurrentId > 0)//如果是编辑 { mArt = bArt.GetModel(CurrentId); if (mArt.ColumnId != 0) { DoSetting(Convert.ToInt32(mArt.ColumnId), "修改"); } ddlTitCor.Items.FindByValue(mArt.titleColor).Selected = true; ddlTitSty.Items.FindByValue(mArt.titleFont.ToString()).Selected = true; } //tbAuthor.Text = mArt.Author; tbAuthor.Text = CurrentAdmin.Name; if (mArt.IsPic == true) { //显示图片 Image1.Visible = true; Image1.ImageUrl = "~\\userfiles\\" + mArt.PicUrl.Substring(mArt.PicUrl.LastIndexOf("\\") + 1);; } //tbPicUrl.Text = mArt.PicUrl; tbTitle.Text = mArt.Title; FCKeditor1.Value = mArt.Body; //构造SQL语句查询出没有子栏目并且不是跳转网址的栏目 string strSql = "select * from CMS_Column as a where (Len(GotoUrl)=0 or GotoUrl is NULL) and not EXISTS(select b.Id from CMS_Column as b where b.ParentId=a.Id) order by code"; DataTable dt = bCol.CustomGetList(strSql); //光往栏目下拉列表中加入"无"项 ListItem theLi = new ListItem("无", "0"); ddlCol.Items.Add(theLi); //通过循环将数据库中满足条件的栏目包装成带缩进的样子加入栏目的下拉列表 foreach (DataRow dr in dt.Rows) { ListItem li = new ListItem(); li.Text = GetColumnName(dr["Title"].ToString(), dr["Code"].ToString()); li.Value = dr["Id"].ToString(); //若是编辑则将当前栏目选中 if (li.Value == mArt.ColumnId.ToString()) { li.Selected = true; } ddlCol.Items.Add(li); } /*以下是专题的不过没什么用*/ //在视频的第五单元第四课时里 //根据ListItem选项值修改背景颜色 字体粗细 foreach (ListItem lt in ddlTitCor.Items) { lt.Attributes.CssStyle.Add(HtmlTextWriterStyle.BackgroundColor, lt.Value); } ddlTitSty.Items[0].Attributes.CssStyle.Add(HtmlTextWriterStyle.FontStyle, "bold"); ddlTitSty.Items[1].Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold"); ddlTitSty.Items[2].Attributes.CssStyle.Add(HtmlTextWriterStyle.FontStyle, "italic"); ddlTitSty.Items[3].Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold"); ddlTitSty.Items[3].Attributes.CssStyle.Add(HtmlTextWriterStyle.FontStyle, "italic"); }