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");
        }
    }
}

这里写图片描述

这里写图片描述

//
//


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");
        }
    }
}

这里写图片描述

这里写图片描述

//
//


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

这里写图片描述

//
//


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;
            }
        }
    }
}

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


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");
        }


    }

}

这里写图片描述

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

//
//


数据库截图

这里写图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值