login.aspx.cs

来自「仓库管理系统源码」· CS 代码 · 共 64 行

CS
64
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
    private readonly string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["Admin"] = this.TextBox1.Text.Trim();
        }
			
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      //创建连接字符串
			string sqlstr;
            sqlstr = "select Pwd from tb_User where UserName=@adminname";
			SqlConnection scon=new SqlConnection(ConnectionString);
			SqlCommand scm= new SqlCommand(sqlstr,scon);
			scm.Parameters.Add("@adminname",SqlDbType.VarChar,20);
			scm.Parameters["@adminname"].Value=this.TextBox1.Text.Trim();
			scon.Open();
			SqlDataReader reader=scm.ExecuteReader();
			if (reader.Read())
			{
				
				string strPwd=reader[0].ToString();

				reader.Close();
				if(strPwd!=TextBox2.Text.Trim())
				{
					this.LabelMsg.Text="密码错误!";
				}
				else
				{
                    Response.Redirect("ManageList.aspx");
				}
				
			}
			else
			{
				this.LabelMsg.Text="对不起,您没有权限!";
				scon.Close();
			}

		}

    protected void Button2_Click(object sender, EventArgs e)
    {
        this.TextBox1.Text = "";
        this.TextBox2.Text = "";
    }
}

⌨️ 快捷键说明

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