UsernameTextBox.Enabled = False
Me.Cursor = Cursors.WaitCursor
Try
Dim usernamecmd As New SqlCommand("select id , user_name,Employee_Name from users_TB where user_name = '" & UsernameTextBox.Text _
& "' and Record_Status = 'Activated'", con)
Me.Cursor = Cursors.WaitCursor
con.Open()
Dim usernamedr As SqlDataReader = usernamecmd.ExecuteReader
usernamedr.Read()
If Not (usernamedr.HasRows) Then
UsernameTextBox.Enabled = True
Me.Cursor = Cursors.Default
MessageBox.Show("اسم المستخدم غير صحيح او غير مفعل", "تسجيل الدخول", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading)
Me.UsernameTextBox.Text = ""
Me.PasswordTextBox.Text = ""
Me.UsernameTextBox.Focus()
Else
userid = usernamedr.Item(0)
EmployeeName = usernamedr.Item(2)
'للتأكد من ان المستخدم الحالي غير مستخدم من قبل موظف اخر في الشركة
Dim userstatussstring As String = "SELECT TOP 1 [user_Status] FROM [Users_Access_TB] " _
& " where user_id = " & userid & " order by id desc"
Dim userstatuscmd As New SqlCommand(userstatussstring, con)
usernamedr.Close()
If userstatuscmd.ExecuteScalar = True Then
Me.UsernameTextBox.Enabled = True
Me.UsernameTextBox.Focus()
MessageBox.Show("المستخدم " & Me.UsernameTextBox.Text & " متواجد فعلاً في النظام", "تسجيل دخول", MessageBoxButtons.OK _
, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading)
Me.UsernameTextBox.Text = ""
Me.PasswordTextBox.Text = ""
Me.Cursor = Cursors.Default
usernamedr.Close()
con.Close()
Exit Sub
End If
If usernamedr.IsClosed = False Then usernamedr.Close()
Dim passwordcmd As New SqlCommand("select user_password from users_TB where id = " & userid, con)
Dim passworddr As SqlDataReader = passwordcmd.ExecuteReader
passworddr.Read()
If PasswordTextBox.Text = passworddr.Item(0) Then
UsernameTextBox.Enabled = True
Me.Cursor = Cursors.Default
passworddr.Close()
con.Close()
MsgBox("مرحباً بك " & EmployeeName, MsgBoxStyle.Information, "تسجيل الدخول")
Me.UsernameTextBox.Text = ""
MainFrm.Show()
useraccesssub(Me.Name, Me, con, userid)
Me.Hide()
Else
UsernameTextBox.Enabled = True
Me.Cursor = Cursors.Default
Me.PasswordTextBox.Focus()
MessageBox.Show("كلمة المرور غير صحيحة", "تسجيل الدخول", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading)
Me.PasswordTextBox.Text = ""
passworddr.Close()
If con.State = ConnectionState.Open Then con.Close()
Exit Sub
End If
If passworddr.IsClosed = False Then passworddr.Close()
End If
If usernamedr.IsClosed = False Then usernamedr.Close()
If con.State = ConnectionState.Open Then con.Close()
Catch ex As Exception
UsernameTextBox.Enabled = True
Me.Cursor = Cursors.Default
If con.State = ConnectionState.Open Then con.Close()
If ex.Message.ToString = "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)" Then
MessageBox.Show("لا يوجد اتصال مع قاعدة البيانات .. يرجى الاتصال بمدير النظام.", "تسجيل دخول", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading)
Exit Sub
End If
MsgBox(ex.Message, MsgBoxStyle.Critical, msgboxtitle)
End Try