📄 talk.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 gllbysj
{
/// <summary>
/// talk 的摘要说明。
/// </summary>
public class talk : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.LinkButton Linkbutton8;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.TextBox tb2;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.LinkButton LinkButton5;
protected System.Web.UI.WebControls.LinkButton LinkButton4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label13;
protected System.Web.UI.WebControls.Label Label14;
protected System.Web.UI.WebControls.Label Label15;
protected System.Web.UI.WebControls.Label Label2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
string vname=Session["vname"].ToString();
string vid=Session["vid"].ToString();
//Response.Write(vid);
SqlConnection con=db.createcon();
con.Open();
SqlCommand cmm=new SqlCommand("select image,descr from mess where id='"+vid+"'",con);
SqlDataReader sdr=cmm.ExecuteReader();
sdr.Read();
string s="upimage/"+sdr["image"].ToString();
this.Image1.ImageUrl=s;
this.Label6.Text=vname;
this.Label12.Text=" "+sdr["descr"].ToString();
con.Close();
if(Session["name"]!=null)
{
this.Label11.Text=Session["name"].ToString();
}
this.bind();
}
}
public void bind()
{
int aa=Convert.ToInt32(this.Label14.Text);
string vvname=Session["vname"].ToString();
SqlConnection con=db.createcon();
con.Open();
//string s="火花";
string str="select * from talks where vname='"+vvname+"' order by times DESC";
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand(str,con);
//SqlCommand cmm=new SqlCommand();
//SqlDataAdapter sda=new SqlDataAdapter();
//sda.SelectCommand=new SqlCommand("select * from talks where vname='火花',con");
DataSet ds=new DataSet();
sda.Fill(ds);
System.Web.UI.WebControls.PagedDataSource ps=new PagedDataSource();
ps.DataSource=ds.Tables[0].DefaultView;
ps.AllowPaging=true;
ps.PageSize=10;
ps.CurrentPageIndex=aa-1;
int aaa=ps.PageCount;
this.Label15.Text="共"+aaa+"页";
this.LinkButton4.Visible=true;
this.LinkButton5.Visible=true;
if(aa==1)
{
this.LinkButton4.Visible=false;
}
if(aa==ps.PageCount)
{
this.LinkButton5.Visible=false;
}
this.DataList1.DataSource=ps;
this.DataList1.DataBind();
this.Label2.Text="共有"+ds.Tables[0].Rows.Count.ToString()+"个评论";
con.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataList1.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_ItemCommand);
this.LinkButton4.Click += new System.EventHandler(this.LinkButton4_Click);
this.LinkButton5.Click += new System.EventHandler(this.LinkButton5_Click);
this.Linkbutton8.Click += new System.EventHandler(this.Linkbutton8_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void pl()
{
if(Session["name"]!=null)
{
string vname=Session["vname"].ToString();
string name=Session["name"].ToString();
string time1=Convert.ToString(System.DateTime.Now);
string add=Request.UserHostAddress.ToString();
string tb1=this.tb2.Text;
SqlConnection con=db.createcon();
con.Open();
SqlCommand cmm=new SqlCommand("insert into talks(vname,autor,times,msg,address) values('"+vname+"','"+name+"','"+time1+"','"+tb1+"','"+add+"')",con);
cmm.ExecuteNonQuery();
con.Close();
this.jia();
}
else
{
Response.Write("<script language=javascript>alert('请返回主页先登陆!')</script>");
}
}
public void jia()
{
SqlConnection con=db.createcon();
con.Open();
string id=Session["vid"].ToString();
SqlCommand cm=new SqlCommand("select talk from mess where id='"+id+"' ",con);
SqlDataReader sdr=cm.ExecuteReader();
sdr.Read();
int a=Convert.ToInt32(sdr["talk"].ToString());
a++;
con.Close();
SqlConnection cn=db.createcon();
cn.Open();
SqlCommand cmm=new SqlCommand("update mess set talk='"+a+"' where id='"+id+"'",cn);
cmm.ExecuteNonQuery();
cn.Close();
}
private void DataList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void Linkbutton8_Click(object sender, System.EventArgs e)
{
this.pl();
this.bind();
this.tb2.Text="";
}
private void LinkButton4_Click(object sender, System.EventArgs e)
{
this.Label14.Text=Convert.ToString(Convert.ToInt32(this.Label14.Text)-1);
this.bind();
}
private void LinkButton5_Click(object sender, System.EventArgs e)
{
this.Label14.Text=Convert.ToString(Convert.ToInt32(this.Label14.Text)+1);
this.bind();
}
public void del()
{
Label id=new Label();
id=(Label)(this.DataList1.Items[0].Controls[0].FindControl("Label7"));
string id1=id.Text+"数";
Response.Write(id1);
}
private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if(e.CommandName=="del")
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -