1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
Private Sub BackgroundWorkerMaJ_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorkerMaJ.DoWork
Dim strCodeSource As String
Dim strTitre As String
Dim intNbrLigne As Integer
Dim intNb1 As Integer
Dim intNb2 As Integer = 1
Dim intNb3 As Integer
Dim intNb4 As Integer = 1
Dim i As Integer
strCodeSource = wbMangaverse.Document.DomDocument.documentElement.innerHTML()
intNbrLigne = (UBound(Split(strCodeSource, vbNewLine)) + 1)
For i = 1 To intNbrLigne
intNb1 = InStr(intNb2, strCodeSource, "<FONT color=#000033>")
If intNb1 = 0 Then
Exit For
End If
intNb1 = InStr(intNb1, strCodeSource, ">")
intNb3 = InStr(intNb1 + 1, strCodeSource, ">")
intNb2 = InStr(intNb1, strCodeSource, "<")
intNb4 = InStr(intNb2 + 1, strCodeSource, "<")
If intNb2 = 0 Or intNb4 = 0 Then
Exit For
End If
If intNb3 > intNb2 And intNb4 > intNb2 And intNb2 <> intNb1 + 1 Then
strTitre = Mid(strCodeSource, intNb1 + 1, intNb2 - intNb1 - 1)
If strTitre.Contains("&") = True Then
strTitre = strTitre.Replace("&", "&")
End If
'on met deux aposthrophe si il y en a déjà un afin d'éviter une erreur dans la requete sql
If strTitre.Contains("'") = True Then
strTitre = strTitre.Replace("'", "''")
End If
dtsTM.Clear()
sqlTM = "SELECT Mangas, COUNT(*) AS NbreM FROM TousMangas Where Mangas= '" & strTitre & "' GROUP BY Mangas;"
cmdTM = New OleDbCommand(sqlTM)
dtaTM = New OleDbDataAdapter(cmdTM)
cmdTM.Connection() = cnx
dtaTM.Fill(dtsTM, "TousMangas")
dttTM = dtsTM.Tables("TousMangas")
'Mangas non présent dans la table TousMangas => on enregistre le titre
If rownumTM > dttTM.Rows.Count - 1 Then
'Création d'une nouvelle ligne
dtrTM = dtsTM.Tables("TousMangas").NewRow
'on remet un aposthrophe si il y en a 2
If strTitre.Contains("''") = True Then
strTitre = strTitre.Replace("''", "'")
End If
dtrTM("Mangas") = strTitre
'ajout de la ligne dans le DataSet
dtsTM.Tables("TousMangas").Rows.Add(dtrTM)
'création et exécution du commandbuilder pour mettre à jour le DataAdapter
cmdbTM = New OleDbCommandBuilder(dtaTM)
'mise à jour des données du DataAdapter à partir du commandbuilder
Try
dtaTM.Update(dtsTM, "TousMangas")
Catch ex As OleDbException
Exit Try
End Try
'on vide le dataset pour le recréer avec les nouvelles données
dtsTM.Clear()
dtaTM.Fill(dtsTM, "TousMangas")
dttTM = dtsTM.Tables("TousMangas")
lstModif.Items.Add(strTitre)
End If
Else
strTitre = Mid(strCodeSource, intNb3 + 1, intNb4 - intNb3 - 1)
If strTitre.Contains("&") = True Then
strTitre = strTitre.Replace("&", "&")
End If
'on met deux aposthrophe si il y en a déjà un afin d'éviter une erreur dans la requete sql
If strTitre.Contains("'") = True Then
strTitre = strTitre.Replace("'", "''")
End If
dtsTM.Clear()
sqlTM = "SELECT Mangas, COUNT(*) AS NbreM FROM TousMangas Where Mangas= '" & strTitre & "' GROUP BY Mangas;"
cmdTM = New OleDbCommand(sqlTM)
dtaTM = New OleDbDataAdapter(cmdTM)
cmdTM.Connection() = cnx
dtaTM.Fill(dtsTM, "TousMangas")
dttTM = dtsTM.Tables("TousMangas")
'Mangas non présent dans la table TousMangas => on enregistre le titre
If rownumTM > dttTM.Rows.Count - 1 Then
'Création d'une nouvelle ligne
dtrTM = dtsTM.Tables("TousMangas").NewRow
'on remet un aposthrophe si il y en a 2
If strTitre.Contains("''") = True Then
strTitre = strTitre.Replace("''", "'")
End If
dtrTM("Mangas") = strTitre
'ajout de la ligne dans le DataSet
dtsTM.Tables("TousMangas").Rows.Add(dtrTM)
'création et exécution du commandbuilder pour mettre à jour le DataAdapter
cmdbTM = New OleDbCommandBuilder(dtaTM)
'mise à jour des données du DataAdapter à partir du commandbuilder
Try
dtaTM.Update(dtsTM, "TousMangas")
Catch ex As OleDbException
Exit Try
End Try
'on vide le dataset pour le recréer avec les nouvelles données
dtsTM.Clear()
dtaTM.Fill(dtsTM, "TousMangas")
dttTM = dtsTM.Tables("TousMangas")
lstModif.Items.Add(strTitre)
End If
End If
Next
End Sub |
Partager