08-11-18, 09:31 AM
(06-11-18, 07:58 PM)elgokr كتب :فى البداية يجب عليك ان تقوم بعمل التالىفى حدث ComboBox1_SelectedIndexChangedقام باضافة التالى كاول سطرين فى الحدث
كود :
ComboBox2.Items.Clear()
ComboBox2.Text = Nothing
ثانياً الخطاء الذى يحدث معكوالقى يبدو كما ظهر معى هو بسبب مسار الصورة لكل من الخريطة والعلمحيث ان الصورة بقاعدة البيانات عبارة عن مسار فقط
حتى توضح الامر اكثر انظر الى هذا المسار
كود :
E:\MyWorldEncyclopedia\MyWorldEncyclopedia\bin\Debug\Flags\ao.jpg
تفتكر هذا المسار بالصورة موجودة على كل الاجهزة المستخدمة للبرنامج السورسطيب تفتكر كل الاجهزة قد تحتوى على دريف E كا هارد ديسك
اذا كنت ستقوم بتسجيل المسار فيجب ان يكون بهذا الشكل
كود :
Flags\ao.jpg
وعند الاستخدام سيتم استدعاء مسار المجلد وليليه مسار الصورة بقاعدة البيانات
التالى هو تعليقى كسؤالالان انت وضعت الخيارت القارة الثلاثةوقمت بوضع بعض الدور لقارة افريقيا السؤال هنا كيف يتم وضع او عرض اى بيانات
للدولة غير مسجلة لان اذا كان بالكتابة فلا يعمل وكذلك لا يوجد زر والسبب لا يعمر بالكتابة لانك تستخدم حدث
PHP كود :
ComboBox2_SelectedIndexChanged
اى عند تحديد الدولة فكيف احدد دولة غير موجودة فى القائمة ؟؟هذا ما كل ما لحظته سريعاً واحبب ان افيدك به بناءاً على محتوى الموضوع
وسامحنى لم اتمكن من عمل اى تعديل واعادة ارفاق السورس بسبب اختلاف الاصدارالاصدار المرفق هو 9 بينما لدى 14 اذا كان ما لديك 10 كنت ساتمكن من التعديل عليه دون اى تغيير
تحياتى لكوتمنياتى لك التوفيق
مبدأيا : انا اسف علي ردي المتأخر
و انا اولا اريد ان اوضح بضعة نقاط
1- بالنسبة لمسار الصورة ,المفترض انه يضيفه لقاعدة البيانات مثل ما انت قلت لكن يبدو اني في هذا الجزء قمت بعمل خطأ ما لذا علي ما يبدو ساحتاج الي تعديلها و شكرا للفت نظري
2 - في ComboBox1_SelectedIndexChanged
(اي عند اختيار القارة)
يقوم البرنامج بارفاق كل البلدان الموجودة في Setting معين
و عند اختيار بلد معين يتم التأكد اذا ما كانت موجودة ام لا
ففي حالة وجودها تظهر بياناتها من قاعدة البيانات
و في حالة عدم وجودها يقوم البرنامج لعمل Web Scrapping
لصفحة معينه بها تلك البيانات فيعرضها و يضيفها لقاعدة البيانات لتظهر لاحقا بدون انترنت من قاعدة البيانات
PHP كود :
'Calling The Function of Africa Countries
Africa()
'Checking if The Selected Country is in the database
ChekCustomer("Countries", "CtrName", ComboBox2.SelectedItem)
Dim dt As New DataTable
dt = CheckDataBase("db.accdb", "Select * From Countries Where CtrName ='" & ComboBox2.SelectedItem & " ' ")
'If its There
If There = False Then
'And The ComboBox Selected item is not empty
If ComboBox2.SelectedItem <> "" Then
'And There is Internet Connection
If My.Computer.Network.IsAvailable Then
'Set Connection Variables
Dim pos1, pos2 As Long, var As String
Dim request As WebRequest = WebRequest.Create(page)
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim datastream As Stream = response.GetResponseStream
Dim reader As New StreamReader(datastream)
Dim strData As String = reader.ReadToEnd
Dim input As String = strData
'Get Flag And Map links
Dim reMapLink As New System.Text.RegularExpressions.Regex("(\w+).gif")
My.Settings.MapLinkData = (reMapLink.Match(input).Groups(1).Value)
Dim reFlagLink As New System.Text.RegularExpressions.Regex("/r/w480/img/flag/(\w+)")
My.Settings.FlagLinkData = (reFlagLink.Match(input).Groups(1).Value)
'Read Info
For a As Integer = 1 To 6 Step +1
'Land Area
If a = 1 Then
pos1 = InStr(strData, "Land Area")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "km", CompareMethod.Text)
var = strData.Substring(pos1 + 17, pos2 - pos1 - 17)
Label2.Text = var + "2"
End If
'Water Area
If a = 2 Then
pos1 = InStr(strData, "Water Area")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "km", CompareMethod.Text)
var = strData.Substring(pos1 + 18, pos2 - pos1 - 18)
Label3.Text = var + "2"
'No Water Area Countries
If ComboBox2.SelectedItem = "الكونغو" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "الجزائر" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "أنغولا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "الرأس الاخضر" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "جمهورية افريقيا الوسطى" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "جزر القمر" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "ليسوتو" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "ليبيا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "ساو تومي وبرنسيبي" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "سيشيل" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "جنوب السودان" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "السودان" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "غينيا الإستوائية" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "اريتريا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "موريتانيا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "السودان" Then Label3.Text = "None"
End If
'Total Area
If a = 3 Then
pos1 = InStr(strData, "Total Area")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "km", CompareMethod.Text)
var = strData.Substring(pos1 + 18, pos2 - pos1 - 17)
Label4.Text = var + "2"
End If
' Population
If a = 4 Then
pos1 = InStr(strData, "Population")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "(#", CompareMethod.Text)
var = strData.Substring(pos1 + 18, pos2 - pos1 - 19)
'The Same Word On The Same Line
If ComboBox2.SelectedItem = "Botswana" Then
var = strData.Substring(pos2 + 45, pos2 - pos1 - 3797 - 32)
End If
Label5.Text = var
End If
' Population Density
If a = 5 Then
pos1 = InStr(strData, "Population Density")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "/km", CompareMethod.Text)
var = strData.Substring(pos1 + 26, pos2 - pos1 - 24)
Label6.Text = var + "2"
End If
'Currency
If a = 6 Then
pos1 = InStr(strData, "Currency")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, ")", CompareMethod.Text)
var = strData.Substring(pos1 + 16, pos2 - pos1 - 16)
Label7.Text = var
End If
Next
'Getting and Downloading Maps
My.Settings.MapLink = "https://www.worldatlas.com/img/areamap/" + My.Settings.MapLinkData + ".gif"
Dim mapl As String = appPath + "\Maps\" + My.Settings.MapLinkData + ".gif"
My.Settings.MapsPath = mapl
If System.IO.File.Exists(mapl) Then
'The file exists
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Load(mapl)
Else
'the file doesn't exist
My.Computer.Network.DownloadFile(My.Settings.MapLink, mapl)
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Load(mapl)
End If
'Getting and Downloading Flags
Dim flagl As String = appPath + "\Flags\" + My.Settings.FlagLinkData + ".jpg"
My.Settings.FlagsPath = flagl
My.Settings.FlagLink = "https://www.worldatlas.com/r/w480/img/flag/" + My.Settings.FlagLinkData + "-flag.jpg"
If System.IO.File.Exists(flagl) Then
'The file exists
PictureBox2.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox2.Load(flagl)
Else
'the file doesn't exist
My.Computer.Network.DownloadFile(My.Settings.FlagLink, flagl)
PictureBox2.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox2.Load(flagl)
End If
'And Insert Data into DataBase
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb")
Dim cmd As New OleDb.OleDbCommand(String.Format("insert into Countries (CtrName,CtrLndA,CtrWtrA,CtrTArea,CtrPop,CtrPopDen,CtrCur,CtrCont,FlagName,MapName) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", ComboBox2.SelectedItem, Label2.Text, Label3.Text, Label4.Text, Label5.Text, Label6.Text, Label7.Text, ComboBox1.SelectedItem, My.Settings.FlagsPath, My.Settings.MapsPath), con)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Else
'If No Internet Connection
MsgBox(" يجب الاتصال بشبكةالانترنت لتحميل البيانات ")
End If
End If
Else
'If The Data Is in The DataBase
If There = True Then
Label2.Text = dt.Rows(0).Item(2).ToString
Label3.Text = dt.Rows(0).Item(3).ToString
Label4.Text = dt.Rows(0).Item(4).ToString
Label5.Text = dt.Rows(0).Item(5).ToString
Label6.Text = dt.Rows(0).Item(6).ToString
Label7.Text = dt.Rows(0).Item(7).ToString
PictureBox1.Load(dt.Rows(0).Item(9).ToString)
PictureBox2.Load(dt.Rows(0).Item(10).ToString)
Else
MsgBox("خطأ")
End If
End If 'Calling The Function of Africa Countries
Africa()
'Checking if The Selected Country is in the database
ChekCustomer("Countries", "CtrName", ComboBox2.SelectedItem)
Dim dt As New DataTable
dt = CheckDataBase("db.accdb", "Select * From Countries Where CtrName ='" & ComboBox2.SelectedItem & " ' ")
'If its There
If There = False Then
'And The ComboBox Selected item is not empty
If ComboBox2.SelectedItem <> "" Then
'And There is Internet Connection
If My.Computer.Network.IsAvailable Then
'Set Connection Variables
Dim pos1, pos2 As Long, var As String
Dim request As WebRequest = WebRequest.Create(page)
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim datastream As Stream = response.GetResponseStream
Dim reader As New StreamReader(datastream)
Dim strData As String = reader.ReadToEnd
Dim input As String = strData
'Get Flag And Map links
Dim reMapLink As New System.Text.RegularExpressions.Regex("(\w+).gif")
My.Settings.MapLinkData = (reMapLink.Match(input).Groups(1).Value)
Dim reFlagLink As New System.Text.RegularExpressions.Regex("/r/w480/img/flag/(\w+)")
My.Settings.FlagLinkData = (reFlagLink.Match(input).Groups(1).Value)
'Read Info
For a As Integer = 1 To 6 Step +1
'Land Area
If a = 1 Then
pos1 = InStr(strData, "Land Area")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "km", CompareMethod.Text)
var = strData.Substring(pos1 + 17, pos2 - pos1 - 17)
Label2.Text = var + "2"
End If
'Water Area
If a = 2 Then
pos1 = InStr(strData, "Water Area")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "km", CompareMethod.Text)
var = strData.Substring(pos1 + 18, pos2 - pos1 - 18)
Label3.Text = var + "2"
'No Water Area Countries
If ComboBox2.SelectedItem = "الكونغو" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "الجزائر" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "أنغولا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "الرأس الاخضر" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "جمهورية افريقيا الوسطى" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "جزر القمر" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "ليسوتو" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "ليبيا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "ساو تومي وبرنسيبي" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "سيشيل" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "جنوب السودان" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "السودان" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "غينيا الإستوائية" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "اريتريا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "موريتانيا" Then Label3.Text = "None"
If ComboBox2.SelectedItem = "السودان" Then Label3.Text = "None"
End If
'Total Area
If a = 3 Then
pos1 = InStr(strData, "Total Area")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "km", CompareMethod.Text)
var = strData.Substring(pos1 + 18, pos2 - pos1 - 17)
Label4.Text = var + "2"
End If
' Population
If a = 4 Then
pos1 = InStr(strData, "Population")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "(#", CompareMethod.Text)
var = strData.Substring(pos1 + 18, pos2 - pos1 - 19)
'The Same Word On The Same Line
If ComboBox2.SelectedItem = "Botswana" Then
var = strData.Substring(pos2 + 45, pos2 - pos1 - 3797 - 32)
End If
Label5.Text = var
End If
' Population Density
If a = 5 Then
pos1 = InStr(strData, "Population Density")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, "/km", CompareMethod.Text)
var = strData.Substring(pos1 + 26, pos2 - pos1 - 24)
Label6.Text = var + "2"
End If
'Currency
If a = 6 Then
pos1 = InStr(strData, "Currency")
pos1 = InStr(pos1 + 1, strData, "", CompareMethod.Text)
pos2 = InStr(pos1 + 1, strData, ")", CompareMethod.Text)
var = strData.Substring(pos1 + 16, pos2 - pos1 - 16)
Label7.Text = var
End If
Next
'Getting and Downloading Maps
My.Settings.MapLink = "https://www.worldatlas.com/img/areamap/" + My.Settings.MapLinkData + ".gif"
Dim mapl As String = appPath + "\Maps\" + My.Settings.MapLinkData + ".gif"
My.Settings.MapsPath = mapl
If System.IO.File.Exists(mapl) Then
'The file exists
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Load(mapl)
Else
'the file doesn't exist
My.Computer.Network.DownloadFile(My.Settings.MapLink, mapl)
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Load(mapl)
End If
'Getting and Downloading Flags
Dim flagl As String = appPath + "\Flags\" + My.Settings.FlagLinkData + ".jpg"
My.Settings.FlagsPath = flagl
My.Settings.FlagLink = "https://www.worldatlas.com/r/w480/img/flag/" + My.Settings.FlagLinkData + "-flag.jpg"
If System.IO.File.Exists(flagl) Then
'The file exists
PictureBox2.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox2.Load(flagl)
Else
'the file doesn't exist
My.Computer.Network.DownloadFile(My.Settings.FlagLink, flagl)
PictureBox2.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox2.Load(flagl)
End If
'And Insert Data into DataBase
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb")
Dim cmd As New OleDb.OleDbCommand(String.Format("insert into Countries (CtrName,CtrLndA,CtrWtrA,CtrTArea,CtrPop,CtrPopDen,CtrCur,CtrCont,FlagName,MapName) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", ComboBox2.SelectedItem, Label2.Text, Label3.Text, Label4.Text, Label5.Text, Label6.Text, Label7.Text, ComboBox1.SelectedItem, My.Settings.FlagsPath, My.Settings.MapsPath), con)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Else
'If No Internet Connection
MsgBox(" يجب الاتصال بشبكةالانترنت لتحميل البيانات ")
End If
End If
Else
'If The Data Is in The DataBase
If There = True Then
Label2.Text = dt.Rows(0).Item(2).ToString
Label3.Text = dt.Rows(0).Item(3).ToString
Label4.Text = dt.Rows(0).Item(4).ToString
Label5.Text = dt.Rows(0).Item(5).ToString
Label6.Text = dt.Rows(0).Item(6).ToString
Label7.Text = dt.Rows(0).Item(7).ToString
PictureBox1.Load(dt.Rows(0).Item(9).ToString)
PictureBox2.Load(dt.Rows(0).Item(10).ToString)
Else
MsgBox("خطأ")
End If
End If

