ช่วยดูโค้ดให้หน่อยนะค่ะพอดีว่า login ผ่านแล้วแต่มันติดที่ว่าพอเราใส่ชื่อกับรหัสของคนที่ยังไม่ได้สมัครสมาชิกมันจะขึ้นว่าให้ใส่รหัสชื่อและรหัสใหม่
ช่วยดูโค้ดให้หน่อยนะค่ะพอดีว่า login ผ่านแล้วแต่มันติดที่ว่าพอเราใส่ชื่อกับรหัสของคนที่ยังไม่ได้สมัครสมาชิกมันจะขึ้นว่าให้ใส่รหัสชื่อและรหัสใหม่เหมือนตอนที่ยังไม่ได้ใส่อะไรเลยค่ะต้องเพิ่มโค้ดตรงช่วงไหนช่วยดูให้หน่อยนะค่ะ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace singkasetweb2
{
public partial class Site1 : System.Web.UI.MasterPage
{
public string chk;
public string UserID;
public string Position;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session.Clear();
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
if ((txtUsername.Text == "") || (txtPassword.Text == ""))
{
lblStatus.Visible = true;
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "กรุณากรอกชื่อผู้ใช้งานหรือรหัสผ่านให้ครบถ้วน!";
txtUsername.Focus();
}
else
{
#region check Position
string user_login = txtUsername.Text.Trim();
string password_login = txtPassword.Text.Trim();
if (Check_login_Member(user_login, password_login))
{
Session["UserName"] = user_login;
Response.Redirect("~/Member/IndexMem.aspx");
}
else if (Check_login_Employee(user_login, password_login))
{
if (Convert.ToString(Session["Position"]) == "2")
{
Session["UserName"] = user_login;
Response.Redirect("~/Employee/IndexEmp.aspx");
}
else
{
Session["UserName"] = user_login;
Response.Redirect("~/Admin/IndexAdmin.aspx");
}
}
else
{
lblStatus.Visible = true;
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "กรุณากรอกชื่อผู้ใช้งานหรือรหัสผ่านให้ครบถ้วน!";
txtPassword.Focus();
}
#endregion
}
}
private bool Check_login_Member(string user_login, string password_login)
{
bool bReturn = false;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
String connStr = "Data Source=aoo-pc\\aoo;Initial Catalog=SingkarnkasetDB;User ID=sa;Password=12345";
conn.ConnectionString = connStr;
conn.Open();
cmd.Connection = conn;
String sql = "SELECT Mem_ID,Pos_ID FROM Member WHERE Mem_User=@Name and Mem_Pass=@Password";
cmd.CommandText = sql;
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = user_login;
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = password_login;
object result = cmd.ExecuteScalar();
if (result != null)
{
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
UserID = reader["Mem_ID"].ToString();
Position = reader["Pos_ID"].ToString();
Session["UserID"] = UserID;
Session["Position"] = Position;
}
bReturn = true;
}
return bReturn;
}
private bool Check_login_Employee(string user_login, string password_login)
{
bool bReturn = false;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
String connStr = "Data Source=aoo-pc\\aoo;Initial Catalog=SingkarnkasetDB;User ID=sa;Password=12345";
conn.ConnectionString = connStr;
conn.Open();
cmd.Connection = conn;
String sql = "SELECT Emp_ID,Pos_ID FROM Employee WHERE Emp_User=@Name and Emp_Pass=@Password";
cmd.CommandText = sql;
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = user_login;
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = password_login;
object result = cmd.ExecuteScalar();
if (result != null)
{
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
UserID = reader["Emp_ID"].ToString();
Position = reader["Pos_ID"].ToString();
Session["UserID"] = UserID;
Session["Position"] = Position;
}
conn.Close();
bReturn = true;
}
return bReturn;
}
protected void btnClear_Click(object sender, EventArgs e)
{
txtUsername.Text = "";
txtPassword.Text = "";
lblStatus.Text = "";
txtUsername.Focus();
}
}
}
Tag : .NET
Date :
2013-07-29 22:01:00
By :
axiom
View :
713
Reply :
2
ไม่ Debug ดูครับ ว่ามันเข้าเงื่อนไขไหน
Date :
2013-07-30 09:05:04
By :
mr.win
string user_login = txtUsername.Text.Trim();
string password_login = txtPassword.Text.Trim();
if (Check_login_Member(user_login, password_login))
{
Session["UserName"] = user_login;
Response.Redirect("~/Member/IndexMem.aspx");
}
else if (Check_login_Employee(user_login, password_login))
{
if (Convert.ToString(Session["Position"]) == "2")
{
Session["UserName"] = user_login;
Response.Redirect("~/Employee/IndexEmp.aspx");
}
else
{
Session["UserName"] = user_login;
Response.Redirect("~/Admin/IndexAdmin.aspx");
}
}
else
{
lblStatus.Visible = true;
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "กรุณากรอกชื่อผู้ใช้งานหรือรหัสผ่านให้ครบถ้วน!";
txtPassword.Focus();
}
มันน่าจะเข้ามาทำงานในส่วนนี้นะครับ
Date :
2013-07-30 12:51:51
By :
heavencrow
Load balance : Server 04