Dim Conn As New SqlConnection("server=(local); database=dbNoteBook; uid=chineji; password=chineji")
Dim SQL, users, pass As String
Dim loginId As Integer
Dim Ds As New DataSet
Dim Cmd As SqlCommand
Dim Ad As SqlDataAdapter
Dim DView As DataView
Dim logined As Boolean
Public Function UserLogIn(ByVal loginName As String, ByVal loginPass As String) As Boolean
SQL = "Select * From Customer Where cUser='" & loginName & "' And cPass='" & loginPass & "'"
Ad = New SqlDataAdapter(SQL, Conn)
Ad.Fill(Ds, "TableCus")
DView = Ds.Tables("TableCus").DefaultView
If DView.Count > 0 Then
Dim DRowView As DataRowView
For Each DRowView In DView
Session.Contents("UserId") = DRowView.Item("cId")
Session.Contents("Picture") = DRowView.Item("cPic")
Session.Contents("Name") = DRowView.Item("cName")
Session.Contents("UserName") = DRowView.Item("cUser")
Session.Contents("Password") = DRowView.Item("cPass")
'Dim service As New MyService
'service.AddLogFile("Customer LogIn", "-", "-")
Return True
Next
Exit Function
End If
End Function
Public Function CheckLogIn() As Boolean
If Session.Contents("Name") <> "" Then
Return True
Else
Return False
End If
End Function
Protected Sub butLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butLogin.Click
use = Trim(txtUse.Text)
pwd = Trim(txtPass.Text)
If Len(use) <= 0 Then : lblLogin.Text = "Please input username"
ElseIf Len(pwd) <= 0 Then : lblLogin.Text = "Please input password"
Else
logined=UserLogIn(use, pwd)
If logined Then 'ถ้าล็อกอินผ่าน
butLogin.Enabled = False
butLogout.Enabled = True
lblLogin.Text = Session.Contents("Name")
Response.Redirect("Default.aspx")
Else
butLogin.Enabled = True
butLogout.Enabled = False
lblInfo.Text = "ชื่อล็อกอินหรือรหัสผ่านผิด"
End If
End If
End Sub
Protected Sub butUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butUpdate.Click
'สมมติคุณคลิกที่ปุ่มอัพเดทข้อมูล
If CheckLogIn() Then
SQL="Update table set field='' where userId=" & Session.Contents("UserId")
// Quey databese
EndIf
End Sub