当前位置:   article > 正文

C#之网页开发基础_c#开发网页

c#开发网页

1.注册模块

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService;

namespace webTest
{
    public partial class Register : BaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            registed.Visible = false;
            RegisteInfo.Visible = false;
            RegisteFail.Visible = false;
            RegisteSuccess.Visible = false;
            login.Visible = false;
            if ("" != name.Text && "" != pwd.Text)
            {
                DataSet ds = new DataSet();
                ds = GetList("*", "sys_userinfo", "user_name='" + name.Text + "'");
                if (null != ds)//这儿ds 为什么不是null
                {
                    if (0 != ds.Tables[0].Rows.Count)
                    {
                        //该账号已经被注册过了
                        registed.Visible = true;
                        return;
                    }

                    else
                    {
                        //该账号未被注册,在数据库里插入用户数据
                        string sql;
                        string msg;
                        sql = "insert into sys_userinfo(user_name, user_pwd, user_mbwt1," +
                           "user_mbda1, user_mbwt2, user_mbda2)" +
                           "values('" + name.Text + "', '" + pwd.Text +
                           "', '" + mbquestion1.Text + "','" + mb1_answer.Text +
                           "', '" + mbquestion2.Text + "', '" + mb2_answer.Text + "')";

                        if (false != ExecuteQuery(sql, out msg))
                        {
                            RegisteSuccess.Visible = true;
                            login.Visible = true;
                            //注册成功(sql执行成功),返回登录页面                            
                        }
                        else
                        {
                            RegisteFail.Visible = true;
                            //注册失败(sql执行失败)
                            return;
                        }
                    }
                }

            }

            else
            {
                RegisteInfo.Visible = true;                
                //注册失败,用户信息不完整 
            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("login.aspx");
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86

这里写图片描述

这里写图片描述

//
//


2.登录模块

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService;

namespace webTest
{
    public partial class login :BaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if( "" != name.Text && "" != pwd.Text)
            {
                DataSet ds = new DataSet();
                ds = GetList("*", "sys_userinfo", "user_name='" + name.Text + "'and user_pwd='" + pwd.Text + "'");
                if (null != ds)
                {
                    if (0 != ds.Tables[0].Rows.Count)
                    {
                        //正确
                        Response.Redirect("Succsess.aspx?user_name="+ ds.Tables[0].Rows[0]["user_name"]);
                    }
                    else
                    {
                        Label1.Visible = true;
                        Label1.Text = "用户信息不符";
                        return;
                    }
                }
            }
            else
            {
                Label1.Visible = true;
                return;
            }

        }

        protected void Button2_Click1(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");           
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("zhmm.aspx");
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

这里写图片描述

这里写图片描述

//
//


3.登录成功模块

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService;

namespace webTest
{
    public partial class Succsess : BaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            user.Text = Request.QueryString["user_name"];
        }

        protected void modify_mb_Click(object sender, EventArgs e)
        {
            //跳转到修改密保问题页面
            Response.Redirect("Modify_mb.aspx?user_name=" + user.Text);
        }

        protected void modify_pw_Click(object sender, EventArgs e)
        {
            //跳转到修改密码问题页面
            Response.Redirect("xgmm.aspx?user_name=" + user.Text);
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

这里写图片描述

//
//


4.修改密保模块

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService;

namespace webTest
{
    public partial class Modify_mb : BaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            user_name.Text = Request.QueryString["user_name"];
        }

        protected void TextBox3_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Update_mb_Click(object sender, EventArgs e)
        {
            Label1.Visible = false;
            Label2.Visible = false;
            string sql;
            string msg;

            sql = "update sys_userinfo set user_mbwt1='" +
               mbquestion1.Text + "',user_mbda1='" + mb_answer1.Text +
               "',user_mbwt2= '" + mbquestion2.Text + "',user_mbda2='" + mb_answer2.Text + "'where user_name='" + user_name.Text + "'";

            if (false != ExecuteQuery(sql, out msg))
            {  
                Label1.Visible = true;
                //修改成功(sql执行成功),返回登录页面                            
            }
            else
            {
                Label2.Visible = true;
                //修改失败(sql执行失败)
                return;
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

这里写图片描述
这里写图片描述
//
//


5.修改密码模块

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService;

namespace Webtest
{
    public partial class xgmm : BaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            login2.Visible = false;
            Label3.Visible = false;
            Label2.Visible = false;
            Label5.Visible = false;
            if ("" != ymm.Text)//输入原密码不为空
            {
                DataSet ds = new DataSet();
                Label4.Text = Request.QueryString["user_name"];
                ds = GetList("user_pwd", "sys_userinfo", "user_name ='" + Label4.Text + "'");//取database里的密码



                if ((string)ds.Tables[0].Rows[0]["user_pwd"] != ymm.Text)//原密码输错
                {
                    //贴出错误label_0
                    Label3.Visible = true;
                   // return;
                }

                else//原密码匹配
                {
                    Label3.Visible = false;
                    if (new_pwd1.Text != new_pwd2.Text)//密码确认错误
                    {
                        //贴出错误label_1
                        Label5.Visible = true;
                        return;
                    }

                    //密码匹配正确,往下执行
                    Label5.Visible = false;
                    string sql;
                    string msg;
                    sql = "update sys_userinfo set user_pwd='" + new_pwd2.Text + "'where user_name='" + Label4.Text + "'";


                    if(false!=ExecuteQuery(sql, out msg))
                    {
                        //插入成功
                        //更新数据库里该用户的密码
                        Label2.Visible = true;
                        login2.Visible = true;
                        //贴出任务完成label_2

                    }
                    else
                    {
                        //插入失败
                        //更新数据库里该用户的密码
                        Label2.Visible = false;
                        login2.Visible = false;
                        return;

                    }

                }                    
                }
            }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("login.aspx");
        }


    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

这里写图片描述

然后重新登录
然后重新登录
(旧密码失效)
(旧密码失效)
(登录成功)
(登录成功)

//
//


数据库截图

这里写图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/885638
推荐阅读
相关标签
  

闽ICP备14008679号