📄 friend.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class friend : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] == null)
Response.Redirect("index.aspx");
if (!this.Page.IsPostBack)
{
this.msg.Text = "";
this.sellist.DataSource =gettype(0);
this.sellist.DataBind();
this.addlist.DataSource = gettype(1);
this.addlist.DataBind();
//SELECT UserInfo.UserID, UserInfo.Email, UserInfo.Tele, UserInfo.MobilePh, UserInfo.PicName, UserInfo.QQ, UserInfo.StudentID, StudentInfo.Name FROM UserInfo INNER JOIN StudentInfo ON UserInfo.StudentID = StudentInfo.StudentID WHERE (UserInfo.UserID IN (SELECT friend FROM friend WHERE (type = '好友')))
bindfriend();
}
this.serchtext.Attributes.Add("onkeydown", "if(event.keyCode==13){ event.keyCode=9; document.getElementById('serchbtn').click();}");
}
private void bindfriend()
{
string sqlcmd = "SELECT UserInfo.UserID, UserInfo.Email, UserInfo.Tele, UserInfo.MobilePh, UserInfo.PicName, UserInfo.QQ, UserInfo.StudentID, StudentInfo.Name FROM UserInfo INNER JOIN StudentInfo ON UserInfo.StudentID = StudentInfo.StudentID WHERE (UserInfo.UserID IN (select friend from friend where type = '好友'and UserID='" + Session["UserID"].ToString().Trim() + "'))";//"+this.Province.Text.ToString()+" ; //设置SQL命令
this.SqlDataSource1.SelectCommand = sqlcmd;
this.SqlDataSource1.DataBind(); //将SqlDataSource重新绑定
this.GridView1.DataBind(); //对GridView进行绑定
this.sellist.DataSource = gettype(0);
this.sellist.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton lb = ((LinkButton)e.Row.FindControl("EMailLink"));
if (lb == null)
{
return;
}
lb.Enabled = true;
//switch (Convert.ToInt32((e.Row.Cells[4].Text.Trim())))
//{
lb.CommandArgument = e.Row.DataItemIndex.ToString();
//break;
//}
/////MsgBtn ImageButton2
ImageButton ibtn = ((ImageButton)e.Row.FindControl("MsgBtn"));
if (ibtn == null)
{
return;
}
ibtn.Enabled = true;
//switch (Convert.ToInt32((e.Row.Cells[4].Text.Trim())))
//{
// case 1:
ibtn.CommandArgument = e.Row.DataItemIndex.ToString();
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
}
protected void GridView1_SelectedIndexChanged2(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//LinkEmail
switch (e.CommandName)
{
case "GetEmail":
{
// this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
int index = Convert.ToInt32(e.CommandArgument) - this.GridView1.PageIndex * 10;
//获取行的位置
GridViewRow row = GridView1.Rows[index];
//获取选定行的列的位置,比如第三列,付给你自己的变量表达式,这里是全局变量varImpID
// Session["MailTo"] = row.Cells[0].Text;
LinkButton lb = (LinkButton)row.FindControl("EMailLink");
// this.testtext.Text = row.Cells[4].Text;
String StrTemp = lb.Text;
if (StrTemp.Substring(StrTemp.Length - 3, 3) == "---")
{
Session["MailTo"] = null;
// this.testtext.Text = "";
}
else
{
Session["MailTo"] = lb.Text;
// this.testtext.Text = lb.Text;
Response.Redirect("Email.aspx");
}
break;
}
case "SendMsg":
{
int index = Convert.ToInt32(e.CommandArgument) - this.GridView1.PageIndex * 10;
//获取行的位置
GridViewRow row = GridView1.Rows[index];
//获取选定行的列的位置,比如第三列,付给你自己的变量表达式,这里是全局变量varImpID
// Session["MailTo"] = row.Cells[0].Text;
Label lb = (Label)row.FindControl("UserLab");
// this.testtext.Text = row.Cells[4].Text;
String StrTemp = lb.Text;
Session["MsgTo"] = StrTemp;
Response.Redirect("SendMsg.aspx");
///////MsgBtn ImageButton2
//ImageButton ibtn = ((ImageButton)e.Row.FindControl("MsgBtn"));
//if (ibtn == null)
//{
// return;
//}
//ibtn.Enabled = true;
////switch (Convert.ToInt32((e.Row.Cells[4].Text.Trim())))
////{
//// case 1:
//ibtn.CommandArgument = e.Row.DataItemIndex.ToString();
} break;
default: break;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (e.NewPageIndex == -1)
e.NewPageIndex = 0;
GridView1.PageIndex = e.NewPageIndex;
// pageindex = e.NewPageIndex;
GridView1.DataBind();
}
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
this.fcount.Text = e.AffectedRows.ToString();
}
public ArrayList gettype(int sel )
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
conn.Open(); //打开数据库连接
DataSet ds = new DataSet();
SqlDataAdapter command = new SqlDataAdapter("", conn);
command.SelectCommand.CommandText = "select distinct type from friend where UserID='" + Session["UserID"].ToString().Trim() + "'"; ;
command.Fill(ds, "table1");
conn.Close();
ArrayList ClassList = new ArrayList();
if (sel == 1)
ClassList.Add("转移到");
for (int i = 0; i < ds.Tables["table1"].Rows.Count; i++)
{
ClassList.Add(ds.Tables["table1"].Rows[i][0].ToString());
// this.DropDownList2.Items.Add(new ListItem(ds.Tables["table1"].Rows[i][1].ToString(),ds.Tables["table1"].Rows[i][0].ToString()));
}
if(ds.Tables["table1"].Rows.Count==0)
ClassList.Add("好友");
return ClassList;
}
public String IsNull(string str)
{
////////////IsNull(Eval("MobilePh"))!=null
/////////~/PICTURE/passwd.gif
if (str.Trim().Length == 0 || str == "" || str == null)
{
string pic = "passwd.gif";
str = "<img id=\"SelPic\" alt=\"\" src=\"PICTURE/" + pic + "\" style=\"width: 20px; height: 20px\" /> ---";
return str;
}
return str;
}
protected void addlist_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection sqlcon;
sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand sqlcom;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox check = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (check.Checked == true)
{
Label usertext = (Label)GridView1.Rows[i].FindControl("UserLab");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -