📄 default.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
namespace SkyShark
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebLogonForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Web.UI.WebControls.Label lblMessage;
protected SkyShark.DataSet1 dataSet11;
protected System.Web.UI.WebControls.TextBox txtPassword;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dataSet11 = new SkyShark.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT Username, Password, Role, PasswordChanged FROM dtUsers WHERE (Username = @" +
"UserName)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.VarChar, 15, "Username"));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=NPANDEY-D185;initial catalog=Skyshark;integrated security=SSPI;persis" +
"t security info=True;workstation id=NPANDEY-D185;packet size=4096";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO dtUsers(Username, Password, Role, PasswordChanged) VALUES (@Username," +
" @Password, @Role, @PasswordChanged); SELECT Username, Password, Role, PasswordC" +
"hanged FROM dtUsers WHERE (Username = @Username)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Username", System.Data.SqlDbType.VarChar, 15, "Username"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", System.Data.SqlDbType.VarChar, 15, "Password"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Role", System.Data.SqlDbType.VarChar, 10, "Role"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PasswordChanged", System.Data.SqlDbType.Bit, 1, "PasswordChanged"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE dtUsers SET Username = @Username, Password = @Password, Role = @Role, Pass" +
"wordChanged = @PasswordChanged WHERE (Username = @Original_Username); SELECT Use" +
"rname, Password, Role, PasswordChanged FROM dtUsers WHERE (Username = @Username)" +
"";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Username", System.Data.SqlDbType.VarChar, 15, "Username"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", System.Data.SqlDbType.VarChar, 15, "Password"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Role", System.Data.SqlDbType.VarChar, 10, "Role"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PasswordChanged", System.Data.SqlDbType.Bit, 1, "PasswordChanged"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Username", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Username", System.Data.DataRowVersion.Original, null));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM dtUsers WHERE (Username = @Original_Username)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Username", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Username", System.Data.DataRowVersion.Original, null));
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "dtUsers", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("Username", "Username"),
new System.Data.Common.DataColumnMapping("Password", "Password"),
new System.Data.Common.DataColumnMapping("Role", "Role"),
new System.Data.Common.DataColumnMapping("PasswordChanged", "PasswordChanged")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("en-US");
this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
if (Page.IsValid==true)
{
string username, password;
int datarows;
username=txtUserName.Text.Trim();
password=txtPassword.Text.Trim();
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand.Parameters["@UserName"].Value=username;
datarows=sqlDataAdapter1.Fill(dataSet11,"UserDetails");
sqlConnection1.Close();
if (datarows==0)
lblMessage.Text="Incorrect user name";
else
{
if (dataSet11.Tables["UserDetails"].Rows[0][1].ToString().Trim()==password)
{
string Role;
Role=dataSet11.Tables["UserDetails"].Rows[0][2].ToString().Trim();
Session["usrName"]=username;
Session["usrRole"]=Role;
if (Role=="Disabled")
{
lblMessage.Text="Your account has been disabled. Please contact the network administrator.";
return;
}
FormsAuthentication.GetAuthCookie(username,true);
switch(Role)
{
case "Admin":
Response.Redirect(".\\NA\\ManageUsers.aspx");
break;
case "BM":
Response.Redirect(".\\BM\\AddFl.aspx");
break;
case "LOB":
Response.Redirect(".\\LOB\\CreateRes.aspx");
break;
}
}
else
lblMessage.Text="Incorrect password";
}
dataSet11.Clear();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -