📄 admin_checknews.aspx.cs
字号:
using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Data.OleDb;namespace Lb_news{ /// <summary> /// admin_checknews 的摘要说明。 /// </summary> public class admin_checknews : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid LbNews_Check; protected Conn ds2=new Conn(); protected OleDbDataReader rd; protected System.Web.UI.WebControls.TextBox keyword; protected System.Web.UI.WebControls.Button Submit; protected System.Web.UI.WebControls.RequiredFieldValidator required1; protected string strSql; protected DataSet ds; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 ds2.CheckCookies(2); if(!Page.IsPostBack) { Lb_CheckNews("def"); } } private void Lb_CheckNews(string ShowType) { if (ShowType=="def") { strSql="select * from Lb_News where n_check=0 order by n_id desc"; } else { string SeaTitle=Request["keyword"]; strSql="select * from Lb_News where n_title like '%"+SeaTitle+"%' and n_check=0 order by n_date desc"; } try { ds2.DBopen(); ds=ds2.CreateDataSet(strSql,"Lb_News"); LbNews_Check.DataSource = ds; LbNews_Check.DataBind(); } catch(System.Data.OleDb.OleDbException e) { Response.Write (e.ToString()); } finally { ds2.DBclose(); } } public string LbNews_Edit(object a,object b) { string title=a.ToString(); int newid=ds2.ChangeToInt(b.ToString()); string LbNews_Title="<a href=admin_articledit.aspx?nid="+newid+"&type=2>"+title+"</a>"; return LbNews_Title; } public string LbNews_Class(object a) { ds2.DBopen(); int classid=ds2.ChangeToInt(a.ToString()); rd=ds2.ExecuteOleDbDataReader("select * from Lb_Class where C_Id="+classid+""); rd.Read(); string classname=rd["C_Name"].ToString(); rd.Close(); ds2.DBclose(); return classname; } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Submit.Click += new System.EventHandler(this.Submit_Click); this.LbNews_Check.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.LbNews_Check_ItemCommand); this.LbNews_Check.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.LbNews_Check_PageIndexChanged); this.LbNews_Check.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.LbNews_Check_DeleteCommand); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void LbNews_Check_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { LbNews_Check.CurrentPageIndex = e.NewPageIndex; if (Session["seaCheckNews"]==null) { Lb_CheckNews("def"); } else { Lb_CheckNews("search"); } } private void LbNews_Check_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { try { ds2.DBopen(); int id=ds2.ChangeToInt(LbNews_Check.DataKeys[e.Item.ItemIndex].ToString()); string SqlDelNews="delete from Lb_News WHERE n_id = "+id+""; int result=ds2.ExecuteSql(SqlDelNews); if(result>0) { ds2.alert("删除成功","admin_checknews.aspx"); } else { ds2.alert("删除失败","admin_checknews.aspx"); } } catch(System.Data.OleDb.OleDbException ex) { Response.Write (ex.ToString()); } finally { ds2.DBclose(); } } private void LbNews_Check_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if(e.CommandName=="pass") { try { ds2.DBopen(); int id=ds2.ChangeToInt(LbNews_Check.DataKeys[e.Item.ItemIndex].ToString()); string SqlCheck="update Lb_News set n_check=1 WHERE n_id = "+id+""; int result=ds2.ExecuteSql(SqlCheck); if(result>0) { ds2.alert("审核通过","admin_checknews.aspx"); } else { ds2.alert("审核失败","admin_checknews.aspx"); } } catch(System.Data.OleDb.OleDbException ex) { Response.Write (ex.ToString()); } finally { ds2.DBclose(); } } } private void Submit_Click(object sender, System.EventArgs e) { if(Page.IsValid) { Session["seaCheckNews"]="ok"; LbNews_Check.CurrentPageIndex=0; Lb_CheckNews("search"); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -