'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