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

📄 friend.aspx.cs

📁 校友录的总体功能分为三个子功能模块:管理功能模块,用户注册功能模块,用户个性化服务
💻 CS
📖 第 1 页 / 共 2 页
字号:
                string sqlstr = "update friend set type='" + this.addlist.SelectedItem.Text.Trim() + "' where friend='" + usertext.Text.Trim() + "'";

                sqlcom = new SqlCommand(sqlstr, sqlcon);
                sqlcon.Open();
                sqlcom.ExecuteNonQuery();
                sqlcon.Close();
            }
        }
        //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 = '好友')))
        string cmd = " 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  = '" + this.sellist.SelectedItem.Text.Trim() + "'and UserID='" + Session["UserID"].ToString().Trim() + "'))";//"+this.Province.Text.ToString()+" ; //设置SQL命令//"+this.Province.Text.ToString()+" ; //设置SQL命令

        this.SqlDataSource1.SelectCommand = cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定

        //this.sellist.DataSource = gettype(0);
        //this.sellist.DataBind();



        this.msg.Text = "";


        cbox.Checked = false;
   this.addlist.SelectedIndex = 0;

    }
    private void bind()
    {
        string cmd = "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  = '" + this.sellist.SelectedItem.Text.Trim() + "' and UserID='" + Session["UserID"].ToString().Trim() + "'))";//"+this.Province.Text.ToString()+" ; //设置SQL命令//"+this.Province.Text.ToString()+" ; //设置SQL命令

        this.SqlDataSource1.SelectCommand = cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定

        this.sellist.DataSource = gettype(0);
        this.sellist.DataBind();

    }

    protected void additem_Click(object sender, EventArgs e)
    {

        this.msg.Text = "";



        for (int i = 0; i < this.addlist.Items.Count; i++)
        {




            if (this.addlist.Items[i].Text.Trim() != this.typename.Text.Trim())
                 this.addlist.Items.Add(new ListItem(this.typename.Text.Trim(), this.typename.Text.Trim()));
        }

        for (int i = 0; i < this.sellist.Items.Count; i++)
        {


            if (this.sellist.Items[i].Text.Trim() != this.typename.Text.Trim())
            
            this.sellist.Items.Add(new ListItem(this.typename.Text.Trim(), this.typename.Text.Trim()));  
        }


               


    }
    protected void serchbtn_Click(object sender, EventArgs e)
    {
        //conn.Open();
        string cmd = " 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.StudentID IN (select  StudentInfo.StudentID from  StudentInfo  where  StudentInfo.Name  LIKE '" + "%" + this.serchtext.Text.ToString() + "%" + "' ) and UserInfo.UserID in(select friend from friend where friend.UserID='" + Session["UserID"].ToString().Trim() + "'))";//"+this.Province.Text.ToString()+" ; //设置SQL命令/"+this.Province.Text.ToString()+" ; //设置SQL命令

        this.SqlDataSource1.SelectCommand = cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定
       

        this.serchtext.Focus();
        cbox.Checked = false;
        this.msg.Text = "";
    }
    protected void sellist_SelectedIndexChanged(object sender, EventArgs e)
    {

        string cmd = "  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  = '" + this.sellist.SelectedItem.Text.Trim() + "'and UserID='" + Session["UserID"].ToString().Trim() + "'))";//"+this.Province.Text.ToString()+" ; //设置SQL命令

        this.SqlDataSource1.SelectCommand = cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定

        this.msg.Text = "";
        this.typelab.Text = "位" + this.sellist.SelectedItem.Text;
        cbox.Checked = false;


    }
    protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox check = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                check.Checked = true;
            }
            else
            {
               check.Checked = false;
            }
        }
        this.msg.Text = "";
    }
    protected void delitem_Click(object sender, EventArgs e)
    {
        this.msg.Text = "";
        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");
                string sqlstr = "delete from friend where   friend='" + usertext.Text.Trim() + "'  and  UserID='"+Session["UserID"].ToString().Trim()+"'";

                sqlcom = new SqlCommand(sqlstr, sqlcon);
                sqlcon.Open();
                sqlcom.ExecuteNonQuery();
                sqlcon.Close();
            }
        }
        bind();
        cbox.Checked = false;
    }
    protected void addfbtn_Click(object sender, EventArgs e)
    {
     //   Response.Write("<script>window.alter('你没有Email邮箱')</script>");
        this.msg.Text = "";


        if (chk(this.fuserid.Text.Trim()))
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;

            cmd.CommandText = "select * from friend where friend='" + this.fuserid.Text.Trim() + "'and UserID='" + Session["UserID"].ToString().Trim() + "'"; ;
            cmd.Connection.Open();

            SqlDataReader sdr = cmd.ExecuteReader();

            if (sdr.HasRows != true)
            {
                cmd.Connection.Close();

                string sql;
                sql = "insert into friend (UserID,friend,type) values ('" + Session["UserID"].ToString().Trim() + "','" + this.fuserid.Text.Trim() + "','好友')";


                cmd.Connection = conn;

                cmd.CommandText = sql;

                cmd.Connection.Open();

                cmd.ExecuteNonQuery();

                cmd.Connection.Close();
                this.msg.Text = "添加成功!";

            }
            else
            {
                cmd.Connection.Close();

                        conn.Close();
                   this.msg.Text = "您重复添加该好友!";

            }

            
            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();

            this.typelab.Text = "位好友"  ;

        }
        else
        {
           // Response.Write("<script>window.alter('不存在此用户名')</script>");

            this.msg.Text = "不存在该用户名!";

        }

    }
    private bool chk(string user)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

        string cmd = "select * from UserInfo where UserID='" + user + "' "; //设置SQL命令
        conn.Open();
        SqlCommand myCommand = new SqlCommand(cmd, conn);
        SqlDataReader jie = myCommand.ExecuteReader();
        if (jie.Read())
        {
            conn.Close();
            return true;
        }
        else
        {
            conn.Close();
            return false;

        }


      


    }
      
}

⌨️ 快捷键说明

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