📄 guanli.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;
namespace free.bbs
{
/// <summary>
/// Summary description for guanli.
/// </summary>
public partial class guanli : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection myconn;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.LinkButton LinkButton3;
protected System.Web.UI.WebControls.LinkButton LinkButton4;
protected System.Data.SqlClient.SqlCommand mycomm;
protected void Page_Load(object sender, System.EventArgs e)
{
myconn=new SqlConnection(Session["str_connection"].ToString());
myconn.Open();
try
{
if(Request.Cookies["free_huiyuan"].Value.ToString()!="free911")
{
try
{
Session["ancestor_id"]=Request.Params["ancestor_id"];
mycomm=new SqlCommand("select neirong from ancestor where ancestor_id="+Request.Params["ancestor_id"]+" and banzhu='"+Request.Cookies["free_huiyuan"].Value.ToString()+"'",myconn);
}
catch
{
Response.Redirect("guanlidenglu.aspx?ancestor_id="+Request.Params["ancestor_id"]+"");
}
SqlDataReader myread;
myread=mycomm.ExecuteReader();
try
{
myread.Read();
Session["leibie"]=myread["neirong"].ToString().Trim();
myread.Close();
}
catch
{
myread.Close();
Response.Redirect("guanlidenglu.aspx?ancestor_id="+Request.Params["ancestor_id"]+"");
}
}
}
catch
{
Response.Redirect("guanlidenglu.aspx?ancestor_id="+Request.Params["ancestor_id"]+"");
}
myconn.Close();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
}
#endregion
private void BindGrid()
{
string sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
switch (d_2.SelectedIndex)
{
case 0:
if(t_1.Text.Trim()=="")
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
else
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where shijian='"+t_1.Text.Trim().ToString()+"' and ancestor_id="+Request.Params["ancestor_id"]+" ";
break;
case 1:
if(t_1.Text.Trim()=="")
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
else
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where shijian>='"+t_1.Text.Trim().ToString()+"'and ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
break;
case 2:
if(t_1.Text.Trim()=="")
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
else
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where shijian<='"+t_1.Text.Trim().ToString()+"' and ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
break;
case 3:
if(t_1.Text.Trim()=="")
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
else
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where shijian>'"+t_1.Text.Trim().ToString()+"' and ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
break;
case 4:
if(t_1.Text.Trim()=="")
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc";
else
sqlstr="select postid, zhuti,attachfile,shijian,attachfileext,lujing from posts where shijian<'"+t_1.Text.Trim().ToString()+"' and ancestor_id="+Request.Params["ancestor_id"]+" order by shijian desc ";
break;
}
myconn.Open();
SqlDataAdapter mydra=new SqlDataAdapter(sqlstr,myconn);
DataSet mydas=new DataSet();
mydra.Fill(mydas,"zhuti");
DataGrid1.DataSource=mydas.Tables["zhuti"].DefaultView;
DataGrid1.DataBind();
myconn.Close();
}
protected void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
protected void Button1_Click(object sender, System.EventArgs e)
{
BindGrid();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//startIndex = e.NewPageIndex * DataGrid1.PageSize;
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string deletecmd="delete from posts where postid=@postid";
SqlCommand mycomm=new SqlCommand(deletecmd,myconn);
mycomm.Parameters.Add(new SqlParameter("@postid",SqlDbType.Int));
mycomm.Parameters["@postid"].Value=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
mycomm.Connection.Open();
mycomm.ExecuteNonQuery();
mycomm.Connection.Close();
BindGrid();
}
protected void LinkButton5_Click(object sender, System.EventArgs e)
{
Response.Redirect("guanli2.aspx?ancestor_id="+Request.Params["ancestor_id"]+"");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -