保健品销售网站 三层架构/WebUI/login.aspx.cs

(完整代码) 1KB

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business;
using Entity;
public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtUsername.Text = "";
            this.txtPassword.Text = "";
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = this.txtUsername.Text;
        string password = this.txtPassword.Text;
        UsersBusiness ub = new UsersBusiness();
        DataSet ds = ub.getUsersByCond("username", username, "users");//按前两个查询 放到users表里
        DataTable dt = ds.Tables["users"];
        if (dt.Rows.Count == 0)//表里没有数据 用户名不存在
        {
            this.txtUsername.Text = "";
            this.txtPassword.Text = "";
            Response.Write("<script>alert('用户名不存在');</script>");
        }
        else
        {
            if (password == ("" + dt.Rows[0][2]))//如果密码和数据库里的密码一致 登录成功
            {
                string id = "" + dt.Rows[0][0];
                UsersEntity ue = ub.getUsersById(id);
                Session["userid"] = id;
                Session["username"] = ue.Username;
                Session["realname"] = ue.Realname;
                Session["users"] = ue;

                Response.Write("<script>alert('登录成功');location.href='Default.aspx';</script>");
                
            }
            else                       
            {
                this.txtPassword.Text = "";
                Response.Write("<script>alert('密码错误');</script>");
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。