⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goodfriend.aspx.cs

📁 简易BBS源码,包括系统管理、论坛管理、用户可以看懂源码
💻 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.Data.OleDb;
namespace free.bbs
{
	/// <summary>
	/// Summary description for goodfriend.
	/// </summary>
	public partial class goodfriend : System.Web.UI.Page
	{
		int start;
		SqlConnection myconn;
		SqlCommand mycomm;
		protected void DataBind1()
		{			
			
			SqlDataAdapter DR = new SqlDataAdapter("SELECT yonghuming,xingbie,chushengriqi,qq,dianhua,email FROM huiyuan WHERE yonghuming IN (SELECT haoyou FROM friend WHERE yonghuming='"+Request.Cookies["free_huiyuan"].Value+"')",myconn);
			DataSet ds = new DataSet();
			DR.Fill(ds,"haoyou");
			DataGrid1.DataSource=ds.Tables["haoyou"];
			DataGrid1.DataBind();
			
		}
		protected void Page_Load(object sender, System.EventArgs e)
		{
			myconn=new SqlConnection(Session["str_connection"].ToString());
			myconn.Open();
			if(!IsPostBack)
			{
				start=0;
				DataBind1();
				try
				{
					name.Text=Request.Params["friend"].ToString();
				}
				catch
				{
					name.Text="";
				}
			}
			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()
		{    
		}
		#endregion

		public void Page_Changed(object send,DataGridPageChangedEventArgs E)
		{
			start=E.NewPageIndex*DataGrid1.PageSize;
			DataGrid1.CurrentPageIndex=E.NewPageIndex;
			DataBind1();
		}

		protected void Button1_ServerClick(object sender, System.EventArgs e)
		{
			
			if(name.Text!="")
			{
				myconn.Open();
				try
				{
					string sqlsle="select * from huiyuan where yonghuming='"+name.Text.Trim().ToString()+"'";
					mycomm=new SqlCommand(sqlsle,myconn);
					SqlDataReader myread=mycomm.ExecuteReader();
					if(myread.Read())
					{
						myread.Close();
						string sqlins="insert into friend(yonghuming,haoyou) VALUES ('"+Request.Cookies["free_huiyuan"].Value+"','"+name.Text.Trim().ToString()+"')";
						mycomm= new SqlCommand(sqlins,myconn);
						if(mycomm.ExecuteNonQuery()>0)
						{
							Response.Write("<script>alert('恭喜,已加为好友!>')</script>");
							DataBind1();
							myconn.Close();
						}
						else
						{
							myconn.Close();
							Response.Write("<script>alert('对不起,该会员已经在您的好友列表中!>')</script>");
						}
					}
					else
					{
						myread.Close();
						myconn.Close();
						Response.Write("<script>alert('对不起,您输入的不是会员名!>')</script>");
					}
				}
				catch
				{
					myconn.Close();
				}
			}
			else
			{
				Response.Write("<script>alert('会员名不能为空!>')</script>");
			}
		}

		protected void Button2_ServerClick(object sender, System.EventArgs e)
		{
			if(name1.Text=="")
			{
				Response.Write("<script>alert('请先输入好友的用户名>')</script>");
			}
			else
			{
				myconn.Open();
				string sqlsle="select haoyou from friend where yonghuming='"+Request.Cookies["free_huiyuan"].Value.ToString()+"'and haoyou='"+name1.Text.Trim()+"'";
				mycomm=new SqlCommand(sqlsle,myconn);
				SqlDataReader myread1=mycomm.ExecuteReader();
				if(myread1.Read())
				{
					string mysql="delete from friend where yonghuming='"+Request.Cookies["free_huiyuan"].Value.ToString()+"' and haoyou='"+name1.Text.Trim()+"'";
					myread1.Close();
					SqlCommand command=new SqlCommand(mysql,myconn);
					if(command.ExecuteNonQuery()>0)
					{
						myconn.Close();
						DataBind1();
						Response.Write("<script>alert('好友删除成功!>')</script>");
					}
					else
						myconn.Close();
				}
				else
				{
					Response.Write("<script>alert('输入为非好友姓名!>')</script>");
				}
			}
		
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -