?? admin_remark.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.SqlClient;
using System.Configuration;
namespace WebNews
{
/// <summary>
/// admin_remark 的摘要說明。
/// </summary>
public class admin_remark : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label myLabel;
protected System.Web.UI.WebControls.TextBox keyword;
protected System.Web.UI.WebControls.DropDownList search;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Label PageList;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.LinkButton btnFirst;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.LinkButton Linkbutton3;
protected System.Web.UI.WebControls.LinkButton Linkbutton4;
protected System.Web.UI.WebControls.Label lblCurrentIndex;
protected System.Web.UI.WebControls.Label lblPageCount;
protected System.Web.UI.WebControls.DataGrid MyDataGrid;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
if(!Page.IsPostBack)
{
string dr=(string)Session["userclass"];
string a= (string)Session["classname"];
string b=Request["classname"];
if(dr.Trim()=="系統(tǒng)管理員")
{
getRemark();
}
else
{
if((int)Session["remark"]==1 &&a.Trim()==b.Trim())
{
getRemark();
}
else myLabel.Text="你無權管理評論";
}
}
}
private void getRemark() //獲得評論
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//連接字符串
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //創(chuàng)建SqlDataAdapter 類
myCommand.SelectCommand=new SqlCommand("sp_selRemarkByArticleId",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter artid=myCommand.SelectCommand.Parameters.Add("@articleid",SqlDbType.BigInt);
artid.Value=Request["articleid"];
DataSet ds=new DataSet(); //建立并填充數(shù)據(jù)集
myCommand.Fill(ds,"Article");
MyDataGrid.DataSource=ds;
MyDataGrid.DataBind();
lblCurrentIndex.Text="第"+((Int32)MyDataGrid.CurrentPageIndex+1)+"頁";
lblPageCount.Text="/共"+MyDataGrid.PageCount+"頁";
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出錯處理
}
}
private void delRemark(object a)
{
try
{ string conn=ConfigurationSettings.AppSettings["dsn"];
SqlConnection con = new SqlConnection(conn);//連接字符串
con.Open();
SqlCommand cmd=new SqlCommand("sp_delRemarkById",con); //建立命令
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter rid=cmd.Parameters.Add("@id",SqlDbType.BigInt ); //調用并設置存儲過程參數(shù)
rid.Value =a;
int i=cmd.ExecuteNonQuery();
if(i>0)
{
myLabel.Text="刪除成功";
}
con.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出錯處理
}
}
private void searchBody()
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//連接字符串
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //創(chuàng)建SqlDataAdapter 類
myCommand.SelectCommand=new SqlCommand("sp_searchRemarkByBody",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter body=myCommand.SelectCommand.Parameters.Add("@body",SqlDbType.NVarChar ,1000);
body.Value=Request["keyword"] ;
DataSet ds=new DataSet(); //建立并填充數(shù)據(jù)集
myCommand.Fill(ds,"Articl");
MyDataGrid.DataSource=ds; //綁定
MyDataGrid.DataBind();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出錯處理
}
}
private void searchAuthor()
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//連接字符串
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //創(chuàng)建SqlDataAdapter 類
myCommand.SelectCommand=new SqlCommand("sp_searchRemarkByAuthor",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter username=myCommand.SelectCommand.Parameters.Add("@username",SqlDbType.NVarChar ,1000);
username.Value=Request["keyword"] ;
DataSet ds=new DataSet(); //建立并填充數(shù)據(jù)集
myCommand.Fill(ds,"Article");
MyDataGrid.DataSource=ds; //綁定
MyDataGrid.DataBind();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出錯處理
}
}
public void PagerButtonClick(Object sender, EventArgs e)
{
//獲得LinkButton的參數(shù)值
string arg = ((LinkButton)sender).CommandArgument;
switch(arg)
{
case ("next"):
if (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1))
MyDataGrid.CurrentPageIndex ++;
break;
case ("prev"):
if (MyDataGrid.CurrentPageIndex > 0)
MyDataGrid.CurrentPageIndex --;
break;
case ("last"):
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
break;
case("first"):
MyDataGrid.CurrentPageIndex =0;
break;
}
getRemark();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.MyDataGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.MyDataGrid_DeleteCommand);
this.MyDataGrid.SelectedIndexChanged += new System.EventHandler(this.MyDataGrid_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void MyDataGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
object b=this.MyDataGrid.DataKeys[e.Item.ItemIndex];
delRemark(b);
if(MyDataGrid.CurrentPageIndex>0)
{
MyDataGrid.CurrentPageIndex=MyDataGrid.CurrentPageIndex-1;
}
getRemark();
}
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Page.IsValid)
{
if(search.SelectedIndex==0)
{
searchBody();
}
else searchAuthor();
}
}
public void MyDataGrid_SelectedIndexChanged(object sender,System.EventArgs e)
{
getRemark();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -