12-11-16, 02:29 PM
(آخر تعديل لهذه المشاركة : 12-11-16, 02:33 PM {2} بواسطة ابراهيم النعيمي.)
السلام عليكم
بداية تحتاج ان يكون لديك جدول للمستخدمين يتكو على الاقل من الحقول الرئيسية التالية:
1. ID (معرف)
2. User_Name (اسم المستخدم)
3. User_Password (كلمة المرور)
4. Employee_Name (اسم الموظف)
5. User_Privilege (صلاحية المستخدم (مدير - مستخدم عادي))
6. Record_Status (حالة المستخدم (مفعل - معلق))
سأفترض أن اسم الجدول الذي يحوي الحقول اعلاه اسمه (Users_TB) و أن قاعدة البيانات المستخدمة هي (SQL Server)
سنحتاج الى نافذة تسجيل دخول تتكون من العناصر التالية (TextBox عدد/2 + Label عدد/2 + Button عدد/2) كما موضح ادناه
في حدث (Click) للزر (تسجيل الدخول) ادرج الكود التالي مع تعديل ما يناسبك:
ارجو ان يكون الشرح واضحاً
تحياتي ..
بداية تحتاج ان يكون لديك جدول للمستخدمين يتكو على الاقل من الحقول الرئيسية التالية:
1. ID (معرف)
2. User_Name (اسم المستخدم)
3. User_Password (كلمة المرور)
4. Employee_Name (اسم الموظف)
5. User_Privilege (صلاحية المستخدم (مدير - مستخدم عادي))
6. Record_Status (حالة المستخدم (مفعل - معلق))
سأفترض أن اسم الجدول الذي يحوي الحقول اعلاه اسمه (Users_TB) و أن قاعدة البيانات المستخدمة هي (SQL Server)
سنحتاج الى نافذة تسجيل دخول تتكون من العناصر التالية (TextBox عدد/2 + Label عدد/2 + Button عدد/2) كما موضح ادناه
في حدث (Click) للزر (تسجيل الدخول) ادرج الكود التالي مع تعديل ما يناسبك:
PHP كود :
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
ارجو ان يكون الشرح واضحاً
تحياتي ..
