// 删除一条新闻 或 将其置顶 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); }
//应该完成了 执行操作 protected void btExecute_Click(object sender, EventArgs e) { BLL.CMS_Article bArt = new BLL.CMS_Article(); string oper = ddlOper.SelectedValue; string idlist = Request.Form["ArticleId"] ?? ""; // 若空传null 不空自己 作用: 获取选中的Id,例如3,4 相当于教程中的ids if (oper == "del") { //判断权限 DoSetting("批量删除"); //批量删除文章 bArt.DeleteList(idlist); } else if (oper == "move") { //判断权限 DoSetting("批量移动"); //批量移动到栏目 bArt.MoveList(idlist, Convert.ToInt16(ddlColumnId.SelectedValue)); } Flush(strWhere); }
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"); }
// 更新列表 注意显示优先级 先排onTop desc 再按时间PostDate desc public void Flush(string strWhere) { if (strWhere == null) { strWhere = ""; } // 添加新闻后返回的页面 if (Session["pageIndex"] != null) { AspNetPager1.CurrentPageIndex = Convert.ToInt32(Session["pageIndex"]); } int ReCount = 0; DataSet ds; BLL.CMS_Article bAtc = new BLL.CMS_Article(); ds = bAtc.GetPageListWithColumn("onTop desc,PostDate desc", strWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, ref ReCount); AspNetPager1.RecordCount = ReCount; GVinfo.DataSource = ds; GVinfo.DataBind(); }