 |
|
ช่วยดู Code Login ให้หน่อยค่ะ ล็อคอินไม่ได้เลย ขอบคุณมากค่ะ |
|
 |
|
|
 |
 |
|
อันนี้โค้ด WebService ค่ะ
Code (VB.NET)
Public Function CustomerLogIn(ByVal Username As String, ByVal Password As String) As Boolean
Sql = "Select * From TblPersonel Where Username= " + "'" + Username + "'" + " And Password= " + "'" + Password + "'"
'//กำหนด Sqlสำหรับอ่านข้อมูล
Ad = New SqlDataAdapter(Sql, Conn) '///ประมวลผลคำสั่งอ่านข้อมูล
Ad.Fill(Ds, "Table1") '///นำข้อมูลที่อ่านข้อมูลได้ไปให้กับDsแบบดาต้าเซต
DView = Ds.Tables("Table1").DefaultView '///นำข้อมูลในDsแบบดาต้าเซตไปให้ดาต้าวิว
If DView.Count > 0 Then '////ถ้า DView.Count มีค่ามากกว่า 0 แสดงว่ามีข้อมูลรหัสนั้นๆ แล้ว
Dim DRowView As DataRowView '////กำหนดตัวแปรแบบบ DataRowview เพื่ออ่านข้อมูลที่ละรายการ
For Each DRowView In DView '////วนรอบอ่านข้อมูลจาก Dview ทีละรายการไปให้ DataRowview ถ้าอ่านไม่ได้ออกจากลูป
Session.Contents("Username") = DRowView.Item("Username")
Session.Contents("Password") = DRowView.Item("Password")
'//สร้างตัวแปรแบบ Session พร้อมนำค่าที่อ่านให้ค่ากับSession
Session.Contents("Id") = DRowView.Item("Pe_Id").ToString '//สร้างตัวแปรแบบ Session พร้อมนำค่าที่อ่านให้ค่ากับSession
Session.Contents("Name") = DRowView.Item("Pe_name").ToString
Session.Contents("Position") = DRowView.Item("Pe_Position").ToString
Session.Contents("pKind") = DRowView.Item("Kind").ToString
Session.Contents("pFlag") = DRowView.Item("Flag").ToString
Return True '///ส่ง true ค่ากลับให้กับฟั่งชั่น เพื่อส่งไปยังโปรแกรมที่เรียกใช้
Next
Else
Return False '///ส่งFalseค่ากลับให้กับฟั่งชั่น เพื่อส่งไปยังโปรแกรมที่เรียกใช้
End If
End Function
|
 |
 |
 |
 |
Date :
2010-08-23 02:59:47 |
By :
HaZePinK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Sql
ลอง Debug ค่านี้ดูครับว่าได้อะไร
|
 |
 |
 |
 |
Date :
2010-08-23 06:15:21 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ Username กับ password ที่ผู้ใช้กรอกผ่านtextbox
|
 |
 |
 |
 |
Date :
2010-08-23 12:17:42 |
By :
HaZePinK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังล็อคอินไม่ได้เลยค่ะ
Sql ตัวนี้เราก็เคยเขียนกับโปรเจคอื่น ก็ใช้ล็อคอินได้อ่ะค่ะ
|
 |
 |
 |
 |
Date :
2010-08-23 14:06:45 |
By :
HaZePinK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim Username As String = Request.Form("TxtUsername")
Dim Password As String = Request.Form("TxtPWD")
ทำไมไม่อ้างอิงจาก property ของ control ล่ะ
|
 |
 |
 |
 |
Date :
2010-08-23 14:41:48 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ login ได้แล้วค่ะ
แต่มีปัญหาอยู่ที่ว่าใช้ materpage
แล้วล็อคอิน
แต่พอเรากด menu ไป หน้าอื่นที่มีใช้ masterpage เดียวกัน
ค่าล็อคอินมันจะหายไป
มันจะให้ใส่ Username Password ใหม่อีกรอบ
ไม่ทราบว่าต้องทำยังไงคะ
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2010-08-23 15:59:14 |
By :
HaZePinK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก็บ state ไว้ใน session หรือเปล่า
|
 |
 |
 |
 |
Date :
2010-08-23 16:51:59 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BtnLogOut.Attributes.Add("OnClick", "javascript:if(confirm('คุณต้องการออกจากระบบ หรือไม่?')==false)return false;")
'Response.Redirect("Welcome.aspx")
Service.TestSession() '//เรียกใช้โปรแกรม TestSession เพื่อตรวจสอบตัวแปรSessionของ Username ที่ล็อกอิน
End Sub
Protected Sub BtnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnLogin.Click
'Dim Username As String = Request.Form("TxtUsername")
'Dim Password As String = Request.Form("TxtPWD")
Dim Username As String = TxtUsername.Text
Dim Password As String = TxtPWD.Text
'Dim Kind As String = "SELECT * FROM TblPersonel WHERE Kind = '" & strPeID & "' "
Dim Service As New WebService1 ''//กำหนดตัวแปรประเภท Service1
LMsg.Visible = True
If Service.CustomerLogIn(Username, Password) Then ''//เรียกใช้โปรแกรมย่อยชื่อCustomerLogIn พร้อมส่งรายการกิจกรรมในวงเล็บ
'LMsg.Text = "เพิ่มข้อมูลการ Login ใน logFile"
'Service.AddLogFile("Admin LogIn", "-", "-")
BtnLogin.Visible = False
BtnLogOut.Visible = True
TreeView1.Visible = True
Panel.Visible = False
LMsg.Visible = True
LMsg.Text = Session.Contents("Name")
Else
MsgBox("ไม่สามารถ LogIn ได้ กรุณาใส่ Username และ Password ใหม่")
clear()
End If
End Sub
Protected Sub clear()
TxtUsername.Text = ""
TxtPWD.Text = ""
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TreeView1.SelectedNodeChanged
End Sub
Protected Sub BtnLogOut_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnLogOut.Click
Session.Abandon()
Response.Redirect("Homepage.aspx")
End Sub
|
 |
 |
 |
 |
Date :
2010-08-23 17:02:52 |
By :
HaZePinK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รอ ร๊อ รอ
เศร้าทำยังไงก็ไม่ได้
|
 |
 |
 |
 |
Date :
2010-08-23 18:32:58 |
By :
HaZePinK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|