Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.SqlClient
Public Class frmLogin
Dim cn As New SqlConnection
Dim dr As SqlDataReader
Dim User As String
Dim Pass As String
Dim LastID As String = ""
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rloginEmpID = ""
rloginEmpName = ""
'rloginEmpPosition = ""
End Sub
Private Sub connection()
cn = New SqlConnection()
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strCn '' string ที่ใช้ต่อ connection
.Open()
End With
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
If MessageBox.Show("ท่านต้องการออกจากระบบ ใช่หรือไม่", "ยืนยันการออกจากระบบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Try
With cn
If .State = ConnectionState.Open Then Close()
.ConnectionString = strCn
.Open()
.Close()
End With
If txtUserName.Text = "" Then
MessageBox.Show("กรุณาป้อนชื่อเข้าใช้งาน", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtUserName.Focus()
ElseIf txtPassword.Text = "" Then
MessageBox.Show("กรุณาป้อนรหัสผ่าน", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPassword.Focus()
Else
ReadMyData(strCn)
End If
Catch ex As Exception
MessageBox.Show("ชื่อผู้ใช้ หรือ รหัสผ่านที่คุณป้อน ไม่มีในฐานข้อมูล", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtUserName.Focus()
txtUserName.SelectAll()
txtPassword.Text = ""
End Try
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo 0
With cn
If .State = ConnectionState.Open Then Close()
.ConnectionString = strCn
.Open()
End With
Dim sqlLogin As String
sqlLogin = "SELECT * FROM v_Employee WHERE Employee_ID = '" & txtUserName.Text & "' and password= '" & txtPassword.Text & "'"
Dim cm As New SqlCommand(sqlLogin, cn)
dr = cm.ExecuteReader
dr.Read()
User = CStr(dr.Item("Employee_ID"))
Pass = CStr(dr.Item("password"))
sqlLogin = "SELECT t.* FROM Task as t INNER JOIN Position_Task pt ON t.Task_ID=pt.Task_ID WHERE pt.Position_ID=@Position_ID"
cm = New SqlCommand(sqlLogin, cn)
cm.Parameters.Clear()
cm.Parameters.AddWithValue("@Position_ID", rloginEmpPosition)
Dim ds As New DataSet()
Dim adapter As New SqlDataAdapter(cm)
adapter.Fill(ds)[/font] Else
MessageBox.Show("ชื่อผู้ใช้ หรือ รหัสผ่านที่คุณป้อน ไม่มีในฐานข้อมูล", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
sqlLogin = "SELECT t.* FROM Task as t INNER JOIN Position_Task pt ON t.Task_ID=pt.Task_ID WHERE pt.Position_ID=@Position_ID"
cm = New SqlCommand(sqlLogin, cn)
cm.Parameters.Clear()
cm.Parameters.AddWithValue("@Position_ID", rloginEmpPosition)
Dim ds As New DataSet()
Dim adapter As New SqlDataAdapter(cm)
adapter.Fill(ds) Else