62,268
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Data;
using System.Configuration;
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.Collections;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();
OleDbConnection myConnection = new OleDbConnection(strConn);
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("select * from UserInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection);
OleDbDataReader oddr = myCommand.ExecuteReader();
if (RadioButton1.Checked)
{
if (oddr.HasRows)
{
oddr.Close();
myConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('登录成功!')", true);
//HttpCookie cookies = new HttpCookie("MyCookie");
//cookies["name"] = txtName.Text.ToString();
//cookies.Expires = DateTime.Now.AddMinutes(20);
//Response.Cookies.Add(cookies);
Session["UserName"] = txtName.Text.ToString();
Response.Redirect("Login.aspx");
}
if ((txtName.Text == "") || (txtPwd.Text == ""))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名和密码不能为空!')", true);
return;
}
else
{
oddr.Close();
myConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名或密码错误!')", true);
txtName.Text = "";
txtPwd.Text = "";
}
}
}
{
string strConn2 = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();
OleDbConnection myConnection2 = new OleDbConnection(strConn2);
myConnection2.Open();
OleDbCommand myCommand2 = new OleDbCommand("select * from ClientInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection2);
OleDbDataReader oddr2 = myCommand2.ExecuteReader();
if (RadioButton2.Checked)
{
if (oddr2.HasRows)
{
oddr2.Close();
myConnection2.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('登录成功!')", true);
//HttpCookie cookies = new HttpCookie("MyCookie");
//cookies["name"] = txtName.Text.ToString();
//cookies.Expires = DateTime.Now.AddMinutes(20);
//Response.Cookies.Add(cookies);
Session["UserName"] = txtName.Text.ToString();
Response.Redirect("Login2.aspx");
}
if ((txtName.Text == "") || (txtPwd.Text == ""))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名和密码不能为空!')", true);
return;
}
else
{
oddr2.Close();
myConnection2.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名或密码错误!')", true);
txtName.Text = "";
txtPwd.Text = "";
}
}
}
}
}
、