Beispiel #1
0
    protected void rptFriends_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        myClass myclass = new myClass();

        int id = Convert.ToInt32(Session["id"].ToString());

        if (e.CommandName == "Add")
        {
            int _id = Convert.ToInt32(e.CommandArgument.ToString());

            string sql1  = "select * from Friends where  me='" + id + "' and friends = '" + _id + "'";
            int    count = myclass.JudgeAcc(sql1);

            if (count > 0)
            {
                Response.Write("<script>alert('好友已存在!')</script>");
            }
            else
            {
                string name  = myclass.RerdName(id);
                string _name = myclass.RerdName(_id);

                string sql  = "insert into Friends (me,friends,myname,friendname) values('" + id + "','" + _id + "','" + name + "','" + _name + "')";
                string _sql = "insert into Friends (me,friends,myname,friendname) values('" + _id + "','" + id + "','" + _name + "','" + name + "')";

                int flag  = myclass.DataSQL(sql);
                int _flag = myclass.DataSQL(_sql);


                if (flag == 1 && _flag == 1)
                {
                    Response.Write("<script>alert('添加成功!')</script>");
                }
                else
                {
                    Response.Write("<script>alert('添加失败!')</script>");
                }
            }
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        myClass myclass = new myClass();

        string id  = userid.Text;
        string pwd = userpwd.Text;

        if (id.Length == 0 || pwd.Length == 0 || id.Length >= 12)
        {
            Response.Write("<script>alert('请正确输入用户信息!')</script>");
        }
        else
        {
            pwd = MD5(pwd);
            string sql   = "select * from UserList where id='" + id + "'and pwd='" + pwd + "'";
            int    count = myclass.JudgeAcc(sql);

            if (Session["CheckCode"] != null)
            {
                string checkcode = Session["CheckCode"].ToString();
                if (TextBox1.Text != checkcode)
                {
                    Response.Write("<script>alert('验证码错误!')</script>");
                }
                else if (count <= 0)
                {
                    Response.Write("<script>alert('登陆错误!')</script>");
                }
                else
                {
                    Response.Write("<script>alert('登陆成功!');location='Home.aspx'</script>");
                    Session["id"] = id;
                }
            }
        }
    }
    protected void btnRegister_Click1(object sender, EventArgs e)
    {
        myClass myclass = new myClass();

        string pwd       = NewPwd.Text;
        string repwd     = reNewPwd.Text;
        string email     = Email.Text;
        string phone     = Phone.Text;
        string name      = Name.Text;
        string sculpture = "Album/picture/timg.jpg";
        string sex       = rdlSex.SelectedValue;

        //string province =
        if (pwd.Length == 0 || repwd.Length == 0 || email.Length == 0 || phone.Length == 0 || name.Length == 0 || sex.Length == 0)
        {
            Response.Write("<script>alert('输入不能为空!')</script>");
        }
        else
        {
            string sql1   = "select * from UserList where phone='" + phone + "'";
            string sql2   = "select * from UserList where email='" + email + "'";
            string sql4   = "select * from UserList where phone='" + phone + "'";
            int    count1 = (myclass.JudgeIor(sql1)).Rows.Count;
            int    count2 = (myclass.JudgeIor(sql2)).Rows.Count;


            if (Session["CheckCode"] != null)
            {
                string checkcode = Session["CheckCode"].ToString();
                if (TextBox1.Text != checkcode)
                {
                    Response.Write("<script>alert('验证码错误!')</script>");
                }
                else if (String.Compare(pwd, repwd) != 0)
                {
                    Response.Write("<script>alert('前面密码两次错误!')</script>");
                }
                else if (count1 > 0)
                {
                    Response.Write("<script>alert('手机号码已被绑定!')</script>");
                }
                else if (count2 > 0)
                {
                    Response.Write("<script>alert('邮箱已被验证!')</script>");
                }
                else
                {
                    pwd = MD5(pwd);

                    int count = 1, rad = 0;

                    while (count > 0)
                    {
                        Int32  x      = 1000000;
                        Random Random = new System.Random();
                        rad = Random.Next(x, x * 10);

                        string sql = "select * from UserList where id = '" + rad + "'";

                        count = myclass.JudgeAcc(sql);
                    }


                    string sql3 = "insert into UserList (id,name,pwd,email,phone,sculpture,sex) values('" + rad + "','" + name + "','" + pwd + "','" + email + "','" + phone + "','" + sculpture + "','" + sex + "')";

                    int flag = myclass.DataSQL(sql3);
                    if (flag != 1)
                    {
                        Response.Write("<script>alert('注册失败!')</script>");
                    }
                    else
                    {
                        DataTable dt = new DataTable();

                        dt = myclass.JudgeIor(sql4);

                        string id  = dt.Rows[0][0].ToString();
                        string sql = "insert into LogClass (classfyname,logowner) values('默认分类','" + id + "')";
                        myclass.DataSQL(sql);
                        Session["id"]   = id;
                        Session["name"] = name;

                        Response.Write("<script>alert('注册成功!');location='Register/RegisterSuccess.aspx'</script>");
                    }
                }
            }
        }
    }