You are on page 1of 23

‫أكواد الوجهة االولى‬

Function username_and_password_from_sheet()
If TextBox1 = "" And TextBox2 = "" Then
MsgBox "‫"الرجاء ادخال البيانات المطلوبة‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox2 = "" Then
MsgBox "‫"الرجاء ادخال الكلمة المرور‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox1 = "" Then
MsgBox "‫"الرجاء ادخال اسم المستخدم‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox1 <> "" And TextBox2 <> "" Then
Dim rng1 As Range
Dim strUserName As String
Dim strPassword As String
strUserName = TextBox1.Value
strPassword = TextBox2.Value
Set rng1 = Sheets("Sheet4").Range("A:B").Find(strUserName, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
If rng1.Offset(0, 1).Value = strPassword Then
MsgBox ("‫ & " " & " مرحبًا بك في البرنامج يا‬TextBox1.Value), vbDefaultButton1, "‫"مرحبـــــــا‬
Call copy_from_form
UserForm8.La14.Caption = TextBox1
Call hide_form_and_show_another_form
End If
End If
End If
End If
End If
End If
End Function
Function hide_form_and_show_another_form()
Me.hide
UserForm8.Show
End Function
Function save_and_close_workbook()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Function
Function copy_from_form()
Dim lastRow As Long
lastRow = ActiveWorkbook.Sheets("Sheet3").Range("A1000000").End(xlUp).Row
lastRow = lastRow + 1
With ActiveWorkbook.Sheets("Sheet3")
.Range("A" & lastRow).Value = TextBox1.Value
.Range("B" & lastRow).Value = Date
.Range("C" & lastRow).Value = Time
' Call insert_option_to_database
End With
'Call reset_all_controls
'Call show_data_in_listbox
End Function
Private Sub CommandButton1_Click()
Call username_and_password_from_sheet
End Sub
Private Sub CommandButton2_Click()
Dim answer As Integer
answer = MsgBox("‫"هل تريد الخروج من البرنامج‬, vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
MsgBox "‫"شكرا الستخدامك البرنامج‬, vbInformation, "‫"شكر خاص‬
Call save_and_close_workbook
Else
End If
End Sub

Private Sub CommandButton3_Click()


Me.hide
UserForm3.Show
End Sub

Private Sub CommandButton8_Click()


Me.hide
UserForm4.Show
End Sub
Private Sub CommandButton9_Click()
Me.hide
UserForm2.Show
End Sub
Private Sub Image2_Click()
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub
'‫تشغيل الساعة في الشاشة‬
Private Sub UserForm_Activate()
L1.Caption = Format(Date, "dd / mm / yyyy")
Do
L2.Caption = Time
DoEvents
Loop
End Sub

‫أكواد الواجهة الثانبة‬

Function copy_from_form_without_repeat()
If TextBox1.Value = "" Or TextBox2.Value = "" Then
MsgBox "‫"برجاء ادخال البيانات التمام العملية بنجاح‬, vbExclamation, "‫"أضافة مستخدم‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("Sheet4").Activate
Set rng1 = Sheets("Sheet4").Range("A:B").Find(str_search, , xlValues, xlWhole)
If rng1 Is Nothing Then
Dim lastRow As Long
lastRow = ActiveWorkbook.Sheets("Sheet4").Range("a1000000").End(xlUp).Row
lastRow = lastRow + 1
MsgBox "‫"تم أضافة يبانات المستخدم‬, vbInformation, "alarm"
With ActiveWorkbook.Sheets("Sheet4")
.Range("a" & lastRow).Value = TextBox1.Value
.Range("b" & lastRow).Value = TextBox2.Value
End With
Else
MsgBox str_search & " Not Found"
End If
End If
End Function
Function search_from_form()
If TextBox1.Value = "" Then
MsgBox "‫"برجاء ادخال البيانات التمام العملية بنجاح‬, vbExclamation, "‫"بحث عن مستخدم‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("Sheet4").Activate
Set rng1 = Sheets("Sheet4").Range("a:b").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
TextBox1.Value = Sheets("Sheet4").Range("a" & row_number).Value
TextBox2.Value = Sheets("Sheet4").Range("b" & row_number).Value
Else
MsgBox str_search & "Not Found"
End If
End If
End Function
Function delete_from_form_with_confirmation()
If TextBox1.Value = "" Or TextBox2.Value = "" Then
MsgBox "‫"برجاء ادخال البيانات التمام العملية بنجاح‬, vbExclamation, "‫"بحث عن مستخدم‬
Else
Dim answer As Integer
answer = MsgBox("Delete This Row of Data", vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("Sheet4").Activate
Set rng1 = Sheets("Sheet4").Range("a:a").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
ActiveWorkbook.Sheets("Sheet4").Rows(row_number).EntireRow.Delete
Else
End If
End If
End If
End Function
Function reset_all_controls()
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Function
Function save_and_close_workbook()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Function
Private Sub CommandButton2_Click()
Dim answer As Integer
answer = MsgBox("‫"هل تريد الخروج من البرنامج‬, vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
MsgBox "‫"شكرا الستخدامك البرنامج‬, vbInformation, "‫"شكر خاص‬
Call save_and_close_workbook
Else
End If
End Sub
Private Sub CommandButton1_Click()
Call copy_from_form_without_repeat
Call reset_all_controls
End Sub
Private Sub CommandButton4_Click()
Me.hide
UserForm1.Show
End Sub
Private Sub CommandButton5_Click()
Call search_from_form
End Sub
Private Sub CommandButton6_Click()
Call delete_from_form_with_confirmation
Call reset_all_controls
End Sub
Private Sub Image2_Click()
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub
'‫تشغيل الساعة في الشاشة‬
Private Sub UserForm_Activate()
L1.Caption = Format(Date, "dd / mm / yyyy")
Do
L2.Caption = Time
DoEvents
Loop
End Sub

‫أكواد الواحهة الثالثة‬

Function search_from_form()
If TextBox2.Value = "" Or TextBox3.Value = "" Then
CheckBox1.Value = False
MsgBox "‫"برجاء استكمال جميع البيانات لكي تتمكن من نجاح العملية‬, vbExclamation, "‫"البحث عن‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet4").Activate
Set rng1 = Sheets("Sheet4").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
TextBox2.Value = Sheets("Sheet4").Range("A" & row_number).Value
TextBox3.Value = Sheets("Sheet4").Range("B" & row_number).Value
Else
CheckBox1.Value = False
MsgBox str_search & "Not Found"
End If
End If
End Function
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Call search_from_form
End If
End Sub
Private Sub Image2_Click()
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Sub
Private Sub CommandButton4_Click()
Me.hide
UserForm1.Show
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub

‫أكواد الواحهة الرابعة‬

Dim CVB As Integer


Function username_and_password_from_code()
If TextBox1 = "" And TextBox2 = "" Then
MsgBox "‫"الرجاء ادخال البيانات المطلوبة‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox2 = "" Then
MsgBox "‫"الرجاء ادخال الكلمة المرور‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox1 = "" Then
MsgBox "‫"الرجاء ادخال اسم المستخدم‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox1.Value <> "Mina Ashraf" And TextBox2.Value <> "as17#h" Then
MsgBox "‫"الرجاء ادخال اسم المستخدم و الكلمة المرور بطريقة صحيحة‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
Else
If TextBox1.Value = "Mina Ashraf" And TextBox2.Value = "as17#h" Then
MsgBox (TextBox1.Value & " " & "‫)" مرحبًا بك أيها المدير في البرنامجك يا‬, vbDefaultButton1, " ‫رسالة‬
‫"ترحيب‬
UserForm8.La14.Caption = TextBox1
UserForm8.CommandButton4.Enabled = True
UserForm8.CommandButton5.Enabled = True
UserForm8.CommandButton6.Enabled = True
Call copy_from_form
Me.hide
UserForm8.Show

End If
End If
End If
End If
End If
End Function

Function save_and_close_workbook()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Function
Function copy_from_form()
Dim lastRow As Long
lastRow = ActiveWorkbook.Sheets("Sheet3").Range("A1000000").End(xlUp).Row
lastRow = lastRow + 1
With ActiveWorkbook.Sheets("Sheet3")
.Range("A" & lastRow).Value = TextBox1.Value
.Range("B" & lastRow).Value = Date
.Range("C" & lastRow).Value = Time
' Call insert_option_to_database
End With
'Call reset_all_controls
'Call show_data_in_listbox
End Function
Private Sub CommandButton1_Click()
Call username_and_password_from_code
End Sub
Private Sub CommandButton2_Click()
Dim answer As Integer
answer = MsgBox("‫"هل تريد الخروج من البرنامج‬, vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
MsgBox "‫"شكرا الستخدامك البرنامج‬, vbInformation, "‫"شكر خاص‬
Call save_and_close_workbook
Else
End If
End Sub
Private Sub CommandButton3_Click()
Me.hide
UserForm5.Show
End Sub

Private Sub CommandButton4_Click()


Me.hide
UserForm1.Show
End Sub

Private Sub Image2_Click()


Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub
'‫تشغيل الساعة في الشاشة‬
Private Sub UserForm_Activate()
L1.Caption = Format(Date, "dd / mm / yyyy")
Do
L2.Caption = Time
DoEvents
Loop
End Sub

‫أكواد الواجة الخامسة‬

Private Sub CommandButton1_Click()


If TextBox1.Value = "" Or TextBox2.Value = "" Then
MsgBox "‫"برجاء استكمال جميع البيانات لكي تتمكن من نجاح العملية‬, vbExclamation, "‫"نسيت كلمة المرور للمدير‬
Else
If TextBox1.Value = "Mina Ashraf" And TextBox2.Value = "350468" Then
UserForm5.Frame1.Visible = True
Else
MsgBox (" ‫)" اسم المستخدم او كلمة المرور غير صحيحة‬
End If
End If
End Sub

Private Sub CommandButton4_Click()


Me.hide
UserForm4.Show
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub

‫أكواد الواجهة السادسة‬

Private Sub CommandButton4_Click()


Me.hide
UserForm8.Show
End Sub
Private Sub CommandButton5_Click()
ThisWorkbook.SaveCopyAs fileName:=ThisWorkbook.Path & _
"\" & Format(Date, "mm-dd-yy") & " " & _
ThisWorkbook.Name
MsgBox "‫"تم عمل نسخة احتياطية‬, vbInformation, "alarm"
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub

‫أكواد الواجهة السابعة‬

Function username_and_password_from_sheet()
If TextBox1 = "" And TextBox2 = "" Then
MsgBox "‫"برجاء استكمال جميع البيانات لكي تتمكن من مساعدتك‬, vbCritical + vbOKOnly, "‫"التأكد من المستخدم‬
Else
If TextBox1 <> "" And TextBox2 <> "" Then
Dim rng1 As Range
Dim strUserName As String
Dim strPassword As String
strUserName = TextBox1.Value
strPassword = TextBox2.Value
Set rng1 = Sheets("Sheet4").Range("A:B").Find(strUserName, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
If rng1.Offset(0, 1).Value = strPassword Then
MsgBox ("‫ & " " & " مرحبًا بك في البرنامج يا‬TextBox1.Value), vbDefaultButton1, "‫مرحبـــــــا تم التأكد‬
‫"من انك مستخدم‬
CommandButton1.Enabled = False
CommandButton3.Enabled = True
CommandButton5.Enabled = True
Label4.Enabled = True
Label5.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
Else
MsgBox "‫"الرجاء ادخال الكلمة المرور‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
End If
Else
MsgBox "‫"الرجاء ادخال اسم المستخدم‬, vbCritical + vbOKOnly, "‫"محاولة فاشلة‬
End If
End If
End If
End Function
Function edit_from_form()
If TextBox3.Value <> TextBox4.Value Then
MsgBox "‫"الرجاء كلمتا السر الجديدتين مختلفتان‬, vbCritical + vbOKOnly, "‫"عدم تطابق‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("Sheet4").Activate
Set rng1 = Sheets("Sheet4").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
With ActiveWorkbook.Sheets("Sheet4")
.Range("A" & row_number).Value = TextBox1.Value
.Range("B" & row_number).Value = TextBox3.Value
.Range("C" & row_number).Value = TextBox2.Value
.Range("D" & row_number).Value = Date
.Range("E" & row_number).Value = Time
MsgBox "‫"تم تعديل يبانات المستخدم‬, vbInformation, "‫"مرحبا‬
End With
Else
MsgBox str_search & "Not Found"
End If
End If
End Function
Function reset_all_controls()
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Function
Function search_from_form()
Dim rng1 As Range
Dim str_search As String
Dim Password_old As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet4").Activate
Set rng1 = Sheets("Sheet4").Range("a:c").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
If Password_old = "" Then
MsgBox "‫"أنت لم تقوم من قبل بتغير كلمة السر‬, vbCritical + vbOKOnly, "‫"تنبية هام‬
Else
Password_old = Sheets("Sheet4").Range("c" & row_number).Value
MsgBox " ‫كلمة السر القديمة هي‬ " & Password_old, vbInformation, "‫"مرحبا‬
End If
End If
End Function
Private Sub CommandButton1_Click()
Call username_and_password_from_sheet
End Sub
Function save_and_close_workbook()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Function
Private Sub CommandButton2_Click()
Dim answer As Integer
answer = MsgBox("‫"هل تريد الخروج من البرنامج‬, vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
MsgBox "‫"شكرا الستخدامك البرنامج‬, vbInformation, "‫"شكر خاص‬
Call save_and_close_workbook
Else
End If
End Sub
Private Sub CommandButton3_Click()
Call edit_from_form
End Sub
Private Sub CommandButton4_Click()
Me.hide
UserForm8.Show
End Sub
Private Sub CommandButton5_Click()
Call search_from_form
End Sub
Private Sub UserForm_Initialize()
CommandButton3.Enabled = False
CommandButton5.Enabled = False
Label4.Enabled = False
Label5.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub

‫أكواد الواجهة الثامنة‬

Function copy_from_form_without_repeat()
If TextBox3.Value = "" Or TextBox4.Value = "" Then
MsgBox " ‫" المجلد بدون اسم من فضلك اكتب اسم الملف اوال‬, vbExclamation, "‫"لم تتم العملية سابفا‬
Else
Dim LastRowValue As Long
LastRowValue = ActiveWorkbook.Sheets("Sheet1").Range("A1000000").End(xlUp).Value
TextBox2 = LastRowValue + 1
Dim rng1 As Range
Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet1").Activate
Set rng1 = Sheets("Sheet1").Range("A:A").Find(str_search, , xlValues, xlWhole)
If rng1 Is Nothing Then
Dim lastRow As Long
lastRow = ActiveWorkbook.Sheets("Sheet1").Range("A1000000").End(xlUp).Row
lastRow = lastRow + 1
With ActiveWorkbook.Sheets("Sheet1")
.Range("A" & lastRow).Value = TextBox2.Value
.Range("B" & lastRow).Value = TextBox3.Value
.Range("C" & lastRow).Value = ComboBox1.Value
.Range("D" & lastRow).Value = ComboBox2.Value
.Range("E" & lastRow).Value = TextBox6.Value
.Range("F" & lastRow).Value = TextBox4.Value
.Range("G" & lastRow).Value = TextBox5.Value
End With
End If
End If
End Function
Function reset_all_controls()
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
TextBox2.Value = Application.WorksheetFunction.Max(Sheets(1).Range("a2:a100000")) +
1
End Function
Function search_from_form()
If TextBox3.Value = "" Or TextBox4.Value = "" Then
MsgBox " ‫" من فضلك اكتب كود اوال‬, vbExclamation, "‫"لم تتم العملية سابفا‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet1").Activate
Set rng1 = Sheets("Sheet1").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
TextBox2.Value = Sheets("Sheet1").Range("A" & row_number).Value
TextBox3.Value = Sheets("Sheet1").Range("B" & row_number).Value
ComboBox1.Value = Sheets("Sheet1").Range("C" & row_number).Value
ComboBox2.Value = Sheets("Sheet1").Range("D" & row_number).Value
TextBox6.Value = Sheets("Sheet1").Range("E" & row_number).Value
TextBox4.Value = Sheets("Sheet1").Range("F" & row_number).Value
TextBox5.Value = Sheets("Sheet1").Range("G" & row_number).Value
Else
MsgBox str_search & "Not Found"
End If
End If
End Function
Function delete_from_form_with_confirmation()
Dim answer As Integer
answer = MsgBox("Delete This Row of Data", vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
Dim rng1 As Range
Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet1").Activate
Set rng1 = Sheets("Sheet1").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
ActiveWorkbook.Sheets("Sheet1").Rows(row_number).EntireRow.Delete
Else
End If
End If
End Function
Function edit_from_form()
If TextBox3.Value = "" Or TextBox4.Value = "" Then
MsgBox "‫"يرجى ملء جميع الحقول المطلوبة‬, vbExclamation, "‫"خطأ في المدخالت‬
Else
Dim response As VbMsgBoxResult
response = MsgBox("‫"هل تريد تعديل يبانات المستند؟‬, vbQuestion + vbYesNo, "‫)"تأكيد‬
If response = vbNo Then Exit Function
Dim rng1 As Range
Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet1").Activate
Set rng1 = Sheets("Sheet1").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
With ActiveWorkbook.Sheets("Sheet1")
.Range("A" & row_number).Value = TextBox2.Value
.Range("B" & row_number).Value = TextBox3.Value
.Range("C" & row_number).Value = ComboBox1.Value
.Range("D" & row_number).Value = ComboBox2.Value
.Range("E" & row_number).Value = TextBox6.Value
.Range("F" & row_number).Value = TextBox4.Value
.Range("G" & row_number).Value = TextBox5.Value

MsgBox "‫"تم تعديل يبانات المستند‬, vbInformation, "‫"تعديل يبانات‬


End With
Else
MsgBox str_search & "Not Found"
End If
End If
End Function
Function insert_picture_to_database()
On Error Resume Next
If TextBox3.Value = "" Or ComboBox1.Value = "" Or ComboBox2.Value = "" Or
TextBox6.Value = "" Then
MsgBox " ‫" من فضلك اكتب البيانات اوال‬, vbExclamation, "‫"لم تتم العملية سابفا‬
Else
Dim imgSourcePath As String
Dim imgDestination As String
Dim free_image As String
Dim GetImagePath As String
Dim strFolder As String
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "‫"اختر صورة للمستند‬
.AllowMultiSelect = False
.Filters.Add "Images", "*.gif;*.jpg;*.jpeg;*.png;*.GIF;*.JPG;*.JPEG;*.PNG"
If .Show <> 0 Then
GetImagePath = .SelectedItems(1)
End If
End With
imgSourcePath = Trim(GetImagePath)
strFolder = ThisWorkbook.Path & Application.PathSeparator & "Images"
If Dir(strFolder, vbDirectory) = "" Then
MkDir strFolder
End If
imgDestination = ThisWorkbook.Path & "\Images\" & UserForm8.TextBox3 & "." &
Split(imgSourcePath, ".")(UBound(Split(imgSourcePath, ".")))
FileCopy imgSourcePath, imgDestination
UserForm8.Image1.PictureSizeMode = fmPictureSizeModeStretch
UserForm8.Image1.Picture = LoadPicture(imgDestination)
free_image = "\Images\" & UserForm8.TextBox3 & "." & Split(imgSourcePath, ".")
(UBound(Split(imgSourcePath, ".")))
Me.TextBox4 = free_image
End If
End Function
Function replace_picture_in_database()
On Error Resume Next
If TextBox3.Value = "" Or ComboBox1.Value = "" Or ComboBox2.Value = "" Or
TextBox6.Value = "" Then
Else
Dim imgSourcePath As String
Dim imgDestination As String
Dim oldImagePath As String
Dim GetImagePath As String
Dim strFolder As String

' Ask for confirmation to change the image


Dim response As VbMsgBoxResult
response = MsgBox("‫"هل تريد تغيير الصورة؟‬, vbQuestion + vbYesNo, "‫)"تأكيد‬
If response = vbNo Then Exit Function

With Application.FileDialog(msoFileDialogFilePicker)
.Title = "‫"اختر الصورة الذي تريد وضعها مكان القديمة‬
.AllowMultiSelect = False
.Filters.Add "Images",
"*.gif;*.jpg;*.jpeg;*.png;*.GIF;*.JPG;*.JPEG;*.PNG"
If .Show <> 0 Then
GetImagePath = .SelectedItems(1)
End If
End With
imgSourcePath = Trim(GetImagePath)
strFolder = ThisWorkbook.Path & Application.PathSeparator & "Images"
If Dir(strFolder, vbDirectory) = "" Then
MkDir strFolder
End If
imgDestination = ThisWorkbook.Path & "\Images\" & UserForm8.TextBox3 & "."
& Split(imgSourcePath, ".")(UBound(Split(imgSourcePath, ".")))
' Delete old image if it exists
oldImagePath = ThisWorkbook.Path & Me.TextBox4
If Dir(oldImagePath) <> "" Then
Kill oldImagePath
End If
' Copy new image
FileCopy imgSourcePath, imgDestination
UserForm8.Image1.PictureSizeMode = fmPictureSizeModeStretch
UserForm8.Image1.Picture = LoadPicture(imgDestination)
Me.TextBox4 = "\Images\" & UserForm8.TextBox3 & "." & Split(imgSourcePath,
".")(UBound(Split(imgSourcePath, ".")))
MsgBox "‫"تم تعديل يبانات الصورة‬, vbInformation, "alarm"
End If
End Function
Function show_picture_in_image_frame()
On Error Resume Next
Dim MyUrl As String
Dim filepath As String
filepath = ActiveWorkbook.Path
MyUrl = filepath & TextBox4.Value
UserForm8.Image1.Picture = LoadPicture(MyUrl)
End Function
Function reset_picture()
Image1.Picture = Nothing
End Function
Function save_and_close_workbook()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Function
Function extract_data_in_listbox()
Dim row_number As Integer
For row_number = 0 To ListBox1.ListCount
If (ListBox1.Selected(row_number) = True) Then
TextBox2 = ListBox1.List(row_number, 0)
TextBox3 = ListBox1.List(row_number, 1)
ComboBox1 = ListBox1.List(row_number, 2)
ComboBox2 = ListBox1.List(row_number, 3)
TextBox6 = ListBox1.List(row_number, 4)
TextBox4 = ListBox1.List(row_number, 5)
TextBox5 = ListBox1.List(row_number, 6)
End If
Next row_number
End Function
Function show_data_in_listbox()
ListBox1.ColumnCount = 7
ListBox1.ColumnWidths = "50,200,150,150,150,250,250"
Sheets("Sheet1").Activate
Dim lastRow As Long
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.List = Range("A1:G" & lastRow).Value
End Function
Function items_from_code_to_combobox1()
ComboBox1.AddItem "‫"منهج‬
ComboBox1.AddItem "‫"حصص المدرسه‬
ComboBox1.AddItem "‫"مراجعة اخر السنة‬
ComboBox1.AddItem "‫"االمتحان‬
'ComboBox1.AddItem ""
End Function
Function items_from_code_to_combobox2()
ComboBox2.AddItem "‫"ابتدائي‬
ComboBox2.AddItem "‫"اعدادي‬
ComboBox2.AddItem "‫"ثانوي‬
ComboBox2.AddItem "‫"جامعة و فيما فوق‬
'ComboBox2.AddItem ""
End Function

Private Sub CommandButton1_Click()


Call insert_picture_to_database
Call MIna_Ashraf
Call copy_from_form_without_repeat
Call reset_all_controls
Call reset_picture
Call show_data_in_listbox
End Sub

Private Sub CommandButton13_Click()


Shell "wiaacmgr.exe"
End Sub

Private Sub CommandButton14_Click()


Me.hide
UserForm7.Show
End Sub

Private Sub CommandButton15_Click()


Me.hide
UserForm9.Show
End Sub

Private Sub CommandButton2_Click()


Call search_from_form
End Sub

Private Sub CommandButton3_Click()


Call reset_all_controls
Call reset_picture
End Sub

Private Sub CommandButton4_Click()


On Error Resume Next
If TextBox3.Value = "" Or ComboBox1.Value = "" Or ComboBox2.Value = "" Or
TextBox6.Value = "" Then
Else

Dim FolderPath As String


Dim FSO As Object

' ‫عرض مربع حوار الختيار المجلد‬


With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "‫"اختر المجلد الذي تريد حذفه‬
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub ' ‫التأكد من اختيار المجلد‬
FolderPath = .SelectedItems(1)
End With

' ‫تأكد من أن المجلد المحدد موجود قبل حذفه‬


If Dir(FolderPath, vbDirectory) <> "" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
' ‫حذف المجلد‬
FSO.DeleteFolder FolderPath, True
TextBox5.Value = ""

Dim rng1 As Range


Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet1").Activate
Set rng1 = Sheets("Sheet1").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
With ActiveWorkbook.Sheets("Sheet1")
.Range("G" & row_number).Value = TextBox5.Value
End With
Else
MsgBox str_search & "Not Found"
End If
MsgBox "‫تم حذف المجلد بنجاح‬.", vbInformation
Else
MsgBox "‫المجلد غير موجود‬.", vbExclamation
End If
End If

Call delete_from_form_with_confirmation
Call reset_all_controls
Call reset_picture
Call show_data_in_listbox
End Sub

Private Sub CommandButton5_Click()


Call edit_from_form
Call replace_picture_in_database
Call MIna_Ashraf_delete
Call reset_all_controls
Call reset_picture
Call show_data_in_listbox
End Sub

Private Sub CommandButton6_Click()


Me.hide
Application.Visible = True
ThisWorkbook.Sheets("sheet1").Activate
End Sub

Private Sub CommandButton7_Click()


Me.hide
UserForm4.Show
End Sub
Private Sub CommandButton11_Click()
Me.hide
UserForm6.Show
End Sub

Private Sub CommandButton12_Click()


Dim answer As Integer
answer = MsgBox("‫"هل تريد الخروج من البرنامج‬, vbQuestion + vbYesNo + vbDefaultButton2,
"Confirmation")
If answer = vbYes Then
MsgBox "‫"شكرا الستخدامك البرنامج‬, vbInformation, "‫"شكر خاص‬
Call save_and_close_workbook
Else
End If
End Sub
Function MIna_Ashraf()
If TextBox3.Value = "" Or ComboBox1.Value = "" Or ComboBox2.Value = "" Or
TextBox6.Value = "" Then
Else
Dim sourceFilePath As String
Dim destinationFolderName As String
Dim destinationFolderPath As String

' 1- ‫اختيار الملف المنسوخ من الكمبيوتر‬


sourceFilePath = Application.GetOpenFilename

' 2- ‫ احضار اسم المجلد من‬textbox3


destinationFolderName = UserForm8.TextBox3.Value

' 3- ‫إنشاء مجلد باالسم المحدد‬


destinationFolderPath = ThisWorkbook.Path & "\‫& "\جميع ملفات االرشيف‬
destinationFolderName
MkDir destinationFolderPath

' 4- ‫نقل الملف المنسوخ إلى المجلد الجديد‬


FileCopy sourceFilePath, destinationFolderPath & "\" & Mid(sourceFilePath,
InStrRev(sourceFilePath, "\") + 1)
UserForm8.TextBox5.Value = destinationFolderPath & "\" & Mid(sourceFilePath,
InStrRev(sourceFilePath, "\") + 1)

MsgBox "‫"!تم نسخ الملف ووضعه في المجلد بنجاح‬


End If
End Function
Function MIna_Ashraf_delete()
If TextBox3.Value = "" Or ComboBox1.Value = "" Or ComboBox2.Value = "" Or
TextBox6.Value = "" Then
Else
Dim response As VbMsgBoxResult
response = MsgBox("‫"هل تريد تغيير المستند؟‬, vbQuestion + vbYesNo, "‫)"تأكيد‬
If response = vbNo Then Exit Function

Dim sourceFilePath As String


Dim destinationFolderName As String
Dim destinationFolderPath As String
Dim FSO As Object

' 1- ‫استدعاء ملف المستند الجديد‬


sourceFilePath = Application.GetOpenFilename

' 2- ‫ تحديد اسم المجلد الهدف من‬TextBox3


destinationFolderName = UserForm8.TextBox3.Value
' 3- ‫تحديد مسار المجلد الهدف‬
destinationFolderPath = ThisWorkbook.Path & "\‫& "\جميع ملفات االرشيف‬
destinationFolderName

' ‫إنشاء المجلد إذا لم يكن موجوًدا بالفعل‬


If Dir(destinationFolderPath, vbDirectory) = "" Then
MkDir destinationFolderPath
End If

' 4- ‫نسخ المستند إلى المجلد الهدف‬


FileCopy sourceFilePath, destinationFolderPath & "\" & Mid(sourceFilePath,
InStrRev(sourceFilePath, "\") + 1)

' ‫حذف المستند القديم‬


Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(UserForm8.TextBox5.Value) Then
FSO.DeleteFile UserForm8.TextBox5.Value
End If

' ‫ تحديث مسار المستند الجديد في‬TextBox5


UserForm8.TextBox5.Value = destinationFolderPath & "\" &
Mid(sourceFilePath, InStrRev(sourceFilePath, "\") + 1)

Dim rng1 As Range


Dim str_search As String
str_search = TextBox2.Value
ActiveWorkbook.Sheets("Sheet1").Activate
Set rng1 = Sheets("Sheet1").Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
With ActiveWorkbook.Sheets("Sheet1")
.Range("G" & row_number).Value = TextBox5.Value
End With
Else
MsgBox str_search & "Not Found"
End If
MsgBox "‫"!تم استبدال المستند وحذف النسخة القديمة بنجاح‬
End If
End Function
Function filter_data_in_listbox()
Call show_data_in_listbox
Dim i As Integer
Dim ListCount1 As Integer
ListCount1 = ListBox1.ListCount - 1
If TextBox1 <> "" Then
For i = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(i, 1), TextBox1) = 0 Then
ListBox1.RemoveItem (i)
End If
Next i
End If
End Function
Private Sub CommandButton9_Click()
If TextBox5.Value = "" Then
MsgBox " ‫" من فضلك اختار الملف و ابحث اوال‬, vbExclamation, "‫"لم تتم العملية سابفا‬
Else
Dim X1
X1 = TextBox5.Value
On Error GoTo ss
ActiveWorkbook.FollowHyperlink Address:=X1, NewWindow:=True
ss:
End If
End Sub

Private Sub ListBox1_Click()


Call extract_data_in_listbox
End Sub

Private Sub TextBox1_Change()


Call filter_data_in_listbox
End Sub

Private Sub TextBox4_Change()


Call show_picture_in_image_frame
End Sub
Private Sub UserForm_Initialize()
Call show_data_in_listbox
Call show_picture_in_image_frame
Call items_from_code_to_combobox1
Call items_from_code_to_combobox2
TextBox2.Value = Application.WorksheetFunction.Max(Sheets(1).Range("a2:a100000")) +
1
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub

Private Sub UserForm_Activate()


'‫تشغيل الساعة في الشاشة‬
L1.Caption = Format(Date, "dd / mm / yyyy")
Do
L2.Caption = Time
DoEvents
Loop
End Sub

‫أكواد الواجهة التاسعة‬

Private Sub CommandButton1_Click()


If TextBox1.Value = "" Then
MsgBox "‫"برجاء استكمال جميع البيانات لكي تتمكن من البحث عن البيانات‬, vbExclamation, "‫"بحث عن بيانات المشكلة‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("‫)"التعديل‬.Activate
Set rng1 = Sheets("‫)"التعديل‬.Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
TextBox1.Value = Sheets("‫)"التعديل‬.Range("A" & row_number).Value
ComboBox2.Value = Sheets("‫)"التعديل‬.Range("B" & row_number).Value
TextBox2.Value = Sheets("‫)"التعديل‬.Range("C" & row_number).Value
ComboBox1.Value = Sheets("‫)"التعديل‬.Range("D" & row_number).Value
Else
MsgBox str_search & "Not Found"
End If
End If
End Sub

Private Sub CommandButton2_Click()


Me.hide
UserForm8.Show
End Sub
Private Sub CommandButton4_Click()
If TextBox1.Value = "" Or ComboBox2.Value = "" Or TextBox2.Value = "" Or
ComboBox1.Value = "" Then
MsgBox "‫"برجاء استكمال جميع البيانات لكي تتمكن من تعديل بيانات المشكلة‬, vbExclamation, "‫"تعديل بيانات المشكلة‬
Else
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("‫)"التعديل‬.Activate
Set rng1 = Sheets("‫)"التعديل‬.Range("A:A").Find(str_search, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.Select
Dim row_number As Long
row_number = ActiveCell.Row
With ActiveWorkbook.Sheets("‫)"التعديل‬
.Range("A" & row_number).Value = TextBox1.Value
.Range("B" & row_number).Value = ComboBox2.Value
.Range("C" & row_number).Value = TextBox2.Value
.Range("D" & row_number).Value = ComboBox1.Value
Call show_data_in_listbox
MsgBox "‫"تم تعديل يبانات المشكلة‬, vbInformation, "‫"تعديل اليبانات‬
'Call insert_option_to_database
End With
Else
MsgBox str_search & "Not Found"
End If
End If
End Sub
Function copy_from_form_without_repeat()
If TextBox1.Value = "" Or ComboBox2.Value = "" Or TextBox2.Value = "" Or
ComboBox1.Value = "" Then
MsgBox "‫"برجاء استكمال جميع البيانات لكي تتمكن من تسجيل البيانات‬, vbExclamation, "‫"تسجيل بيانات المشكلة‬
Else
Dim LastRowValue As Long
LastRowValue = ActiveWorkbook.Sheets("‫)"التعديل‬.Range("A1000000").End(xlUp).Value
TextBox1 = LastRowValue + 1
Dim rng1 As Range
Dim str_search As String
str_search = TextBox1.Value
ActiveWorkbook.Sheets("‫)"التعديل‬.Activate
Set rng1 = Sheets("‫)"التعديل‬.Range("A:A").Find(str_search, , xlValues, xlWhole)
If rng1 Is Nothing Then
Dim lastRow As Long
lastRow = ActiveWorkbook.Sheets("‫)"التعديل‬.Range("A1000000").End(xlUp).Row
lastRow = lastRow + 1
With ActiveWorkbook.Sheets("‫)"التعديل‬
.Range("A" & lastRow).Value = TextBox1.Value
.Range("B" & lastRow).Value = ComboBox2.Value
.Range("C" & lastRow).Value = TextBox2.Value
.Range("D" & lastRow).Value = ComboBox1.Value
' Call insert_option_to_database
End With
'Call reset_all_controls
show_data_in_listbox
MsgBox "‫"تم أضافة يبانات المشكلة يرجاء االنتظار سيتم الرد عليك‬, vbInformation, "‫"أضافة اليبانات‬
Else
MsgBox str_search & " is Found"
End If
End If
End Function
Private Sub CommandButton5_Click()
Call copy_from_form_without_repeat
End Sub

Private Sub CommandButton6_Click()


Call show_data_in_listbox
Dim ctl As MSForms.Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
End Sub
Function extract_data_in_listbox()
Dim row_number As Integer
For row_number = 0 To ListBox1.ListCount
If (ListBox1.Selected(row_number) = True) Then
TextBox1 = ListBox1.List(row_number, 0)
ComboBox2 = ListBox1.List(row_number, 1)
TextBox2 = ListBox1.List(row_number, 2)
ComboBox1 = ListBox1.List(row_number, 3)
End If
Next row_number
End Function

Private Sub ListBox1_Click()


Call extract_data_in_listbox
End Sub

Private Sub UserForm_Initialize()


Application.Visible = False
Application.ScreenUpdating = False
Call show_data_in_listbox
Call ComboBox_1
End Sub
Function show_data_in_listbox()
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths = "50,200,300,50"
Sheets("‫)"التعديل‬.Activate
Dim lastRow As Long
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.List = Range("A1:D" & lastRow).Value
End Function
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
Application.Quit
ActiveWorkbook.Save
ThisWorkbook.Close Not CBool(ThisWorkbook.Saved)
End Sub
Function ComboBox_1()
ComboBox2.AddItem "‫"صفحة اليوزر و الباسورد‬
ComboBox2.AddItem "‫"صفحة البرنامج الرائيسية‬
ComboBox2.AddItem "‫"صفحة قسم ارسال االقتراحات‬
ComboBox2.AddItem "‫"صفحة قسم الحضور‬
ComboBox2.AddItem "‫"صفحة قسم بيانات الشماس‬
ComboBox2.AddItem "‫"و ال في زر‬

ComboBox1.AddItem "‫"تم حل المشكلة‬


ComboBox1.AddItem "‫"لم يتم حل المشكلة‬
ComboBox1.AddItem "‫"المشكلة زي ما هي‬
ComboBox1.AddItem "‫"اعد فتح البرنامج‬
ComboBox1.AddItem "‫"تحت التنفيز‬

End Function

‫أكواد الواجهة العاشرة‬

Private Sub UserForm_Activate()


Application.Visible = False
Me.Label3.Width = 0
Do While Me.Label3.Width < 520
Sleep (90)
Me.Label3.Width = Me.Label3.Width + 5
DoEvents
Me.Label3.Caption = Format(Me.Label3.Width / 520, "# 0%")
If Me.Label3.Width > 350 Then
Me.LB3.Visible = True
Me.LB2.Visible = False
Me.LB1.Visible = False
ElseIf Me.Label3.Width > 200 Then
Me.LB2.Visible = True
Me.LB1.Visible = False
Me.LB3.Visible = False
ElseIf Me.Label3.Width > 0 Then
Me.LB1.Visible = True
Me.LB2.Visible = False
Me.LB3.Visible = False
End If
Loop
If Me.Label3.Width >= 520 Then
Me.hide
UserForm1.Show
End If
End Sub

Private Sub UserForm_Initialize()


Application.Visible = False
Call RemoveTitleBar(Me)
Application.ScreenUpdating = True
End Sub

You might also like