1 Imports System.Data.SqlClient
2
3 Public Class Form_Login
4     Private flag As Boolean = False
'Dung kiem soat timer
5     Public LoginLoaiND As String =
""
6     Public LoginTenND As String =
""
7
8 #Region
"Event form load da hoan tat nhung chua hay"
9     Private Sub Form_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
10         Tao_ket_noi()
11         Kiem_tra_ket_noi()
12         lblChaoMung.Visible = True
13         PictureBox2.Width =
0
14     End Sub
15 #End Region
16
17 #Region
"Kiem tra trang thai ket noi da hoan tat"
18     Private Sub Kiem_tra_ket_noi()
19         Try
20             connect.Open()
21             If connect.State = ConnectionState.Open Then
22                 connect.Close()
23             End If
24         Catch ex As Exception
25             MessageBox.Show(
"Kết nối đến cơ sở dữ liệu không thành công...")
26             Me.Close()
27         End Try
28     End Sub
29 #End Region
30
31 #Region
"Hàm kiêm tra tinh hop le cua ket noi"
32     Function Logged(ByVal U As String, ByVal P As String) As Integer
33         Dim strSQL As String =
"select IdNguoiDung, PassND, IdLoaiND from NguoiDung where IdNguoiDung = '" + U + "' "
34         Dim Command As SqlCommand = New SqlCommand(strSQL, connect)
35         connect.Open()
36         
'dien du lieu nguon vao doi tuong SQLDataReader
37         Dim DataReader As SqlDataReader = Command.ExecuteReader()
38         
'Neu ton tai mau tin
39         If DataReader.Read() Then
40             
'So sanh password
41             If P = DataReader.GetString(
1) Then
42                 
'Nếu username và password đều hợp le
43                 
'Dang nhap thanh cong
44                 Logged =
0
45                 LoginLoaiND = DataReader.GetValue(
2).ToString
46                 LoginTenND = DataReader.GetValue(
0).ToString
47             Else
48                 
'Sai pass và trả về giá trị -1
49                 Logged = -
1
50             End If
51         Else
52             
'Khong tim thay username trong CSDL, trả về -2
53             Logged = -
2
54         End If
55         DataReader.Close()
56         connect.Close()
57     End Function
58 #End Region
59
60 #Region
"Event Login_Click da hoan tat"
61     Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
62         If txtUserName.Text =
"" Then
63             MsgBox(
"Please enter your Username")
64             txtUserName.Focus()
65             Exit Sub
66         End If
67         
'Yeu cau nguoi su dung nhap lai pass
68         If txtPassword.Text =
"" Then
69             MsgBox(
"Please enter your pass")
70             txtPassword.Focus()
71             Exit Sub
72         End If
73         
'Goi ham kiem tra username va pass
74         Dim x As Integer = Logged(txtUserName.Text, txtPassword.Text)
75         If x = -
1 Then
76             MsgBox(
"Bạn nhập sai password")
77             txtPassword.Text =
""
78             txtPassword.Focus()
79         ElseIf x = -
2 Then
80             MsgBox(
"username không tồn tại")
81             txtUserName.Text =
""
82             txtUserName.Focus()
83         Else
84             flag = True
85         End If
86         If flag Then
87             TimerClosing.Start()
88             TimerClosing.Interval =
100
89         End If
90     End Sub
91 #End Region
92
93 #Region
"Event Timer_Tick da hoan tat"
94     Private Sub TimerClosing_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerClosing.Tick
95         Me.Opacity -=
0.05
96         If Me.Opacity =
0 Then
97             TimerClosing.Stop()
98             Timer2.Stop()
99             Timer1.Stop()
100             flag = False
101             Me.Visible = False
102             Form_Main.Show()
103             Form_Main.WindowState = FormWindowState.Maximized
104         End If
105     End Sub
106 #End Region
107
108 #Region
"Event FormClosing da hoan tat"
109     Private Sub FormLogin_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
110         If flag Then
111             e.Cancel() = True
112             Me.TimerClosing.Enabled = True
113         End If
114     End Sub
115 #End Region
116
117 #Region
"Su kien Link_Click da hoan tat"
118     Private Sub LinkLabel_Language_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel_Language.LinkClicked
119         If My.Settings.CultureString =
"en-US" Then
120             My.Settings.CultureString =
"vi-VN"
121         Else
122             My.Settings.CultureString =
"en-US"
123         End If
124         My.Settings.Save()
125         Application.Restart()
126     End Sub
127 #End Region
128
129 #Region
"Event exit hoan tat"
130     Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
131         Try
132             Me.Close()
133         Catch ex As Exception
134             MessageBox.Show(
"Lỗi đóng chương trình")
135         End Try
136     End Sub
137 #End Region
138
139    
140     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
141         lblChaoMung.Visible = Not lblChaoMung.Visible
142     End Sub
143
144     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
145         If PictureBox2.Width < PictureBox1.Width Then
146             PictureBox2.Width = PictureBox2.Width + PictureBox1.Width \
20
147         Else
148             PictureBox2.Width =
0
149         End If
150     End Sub
151 End Class



Quản lý phần mềm bán vé xe VB 8.419 lượt xem

Gõ tìm kiếm nhanh...