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 UserLogin : System.Web.UI.UserControl
{
SqlHelper data = new SqlHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["UserId"] == null)
{
Login1.Visible = false;
Login2.Visible = true;
}
else
{
Label1.Text = Session["UserName"].ToString();
Login1.Visible = true;
Login2.Visible = false;
}
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("UserStReg.aspx");
}
protected void Button4_Click(object sender, EventArgs e)
{
Session.Abandon();
Session.Clear();
Session["UserId"] = null;
Session["UserName"] = null;
Response.Redirect("Default.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["Roule"].ToString()== "買家")
{
Response.Redirect("UserHome.aspx");
}
else
{
Response.Redirect("MaiJia/Default.aspx");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "買家")
{
if (TxtUserName.Text == "" && TxtPassword.Text == "")
{
Alert.AlertAndRedirect("沒有輸入賬號和密碼!", "UserLogin.aspx");
}
else
{
SqlDataReader dr;
dr = data.GetDataReader("select * from Users where UserName='" + TxtUserName.Text.Trim() + "'and pwd='" + TxtPassword.Text.Trim() + "'");
if (dr.Read())
{
Session["UserId"] = dr["id"].ToString();
Session["UserName"] = dr["UserName"].ToString();
Session["XingMing"] = dr["XingMing"].ToString();
Session["Roule"] = "買家";
Response.Redirect("UserLogin.aspx");
}
else
{
Alert.AlertAndRedirect("賬號或者密碼不對請重新登陸!", "UserLogin.aspx");
}
}
}
else
{
if (TxtUserName.Text == "" && TxtPassword.Text == "")
{
Alert.AlertAndRedirect("沒有輸入賬號和密碼!", "UserLogin.aspx");
}
else
{
SqlDataReader dr;
dr = data.GetDataReader("select * from ShangJia where LoginName='" + TxtUserName.Text.Trim() + "'and LoginPwd='" + TxtPassword.Text.Trim() + "'");
if (dr.Read())
{
Session["UserId"] = dr["id"].ToString();
Session["UserName"] = dr["LoginName"].ToString();
Session["XingMing"] = dr["name"].ToString();
Session["Roule"] = "賣家";
Response.Redirect("UserLogin.aspx");
}
else
{
Alert.AlertAndRedirect("賬號或者密碼不對請重新登陸!", "UserLogin.aspx");
}
}
}
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("FindPwd.aspx");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/44641.html
標籤:ASP.NET
下一篇:想請問下關于多執行緒的問題
