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
| Private Sub enregistrer_test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enregistrer_test.Click
'les reponses justes du test
Dim repTest As String = ""
'récuperer l`ensemble des réponses
If CheckBox1.Checked = True Then
repTest = repTest + "A "
End If
If CheckBox2.Checked = True Then
repTest = repTest + "B "
End If
If CheckBox3.Checked = True Then
repTest = repTest + "C "
End If
If CheckBox4.Checked = True Then
repTest = repTest + "D"
End If
If TextBox1.Text.Length = 0 Then
MsgBox("veuillez sélectionner une image")
ElseIf repTest.Length = 0 Then
MsgBox("veuillez cocher les réponses que vous jugez justes pour le test")
ElseIf TextBox2.Text.Length = 0 Then
MsgBox("veuillez sélectionner une audio")
Else 'les tests ne sont pas terminés
nomImage = calculerNom()
'OpenFileDialog1.FileName = nomImage
nomAudio = calculerNom()
'declarattion des 2 path pour le transfert de l`image
Dim imageToCopy As String
Dim newImage As String
'declaration des 2 path pour le transfert de l`audio
Dim audioToCopy As String
Dim newAudio As String
'initialisation des 2 path pour le transfert de l`image
imageToCopy = TextBox1.Text
nomImage = nomImage + extensionImageFile.ToString
nomImage = Trim(nomImage)
newImage = "D:\code_de_la_route\images\" + nomImage.ToString
'initialisation des 2 path pour le transfert de l'audio
audioToCopy = TextBox2.Text
nomAudio = nomAudio + extensionAudioFile.ToString
nomAudio = Trim(nomAudio)
newAudio = "D:\code_de_la_route\audios\" + nomAudio.ToString
Try
'enregistrer l`image dans le dossier correspondant
System.IO.File.Copy(imageToCopy, newImage)
'enregistrer l`audio dans le dossier correspondant
System.IO.File.Copy(audioToCopy, newAudio)
'preparer les requetes
Dim sqlQRY1 As String = "INSERT INTO AUDIO Values ('" + nomAudio + "')"
Dim sqlQRY2 As String = "INSERT INTO [IMAGE] Values ('" + nomImage + "')"
Dim sqlQRY3 As String = "INSERT INTO [TEST](Int_Exa,Rep_Correctes,Nom_Aud,Nom_Img) Values ('" + nomExamen + "','" + repTest + "','" + nomAudio + "','" + nomImage + "')"
'ouvrir la connexion
myConnexion.Open()
'MsgBox(nomImage)
'creation des commandes
Dim cmd1 As OleDbCommand = New OleDbCommand(sqlQRY1, myConnexion)
Dim cmd2 As OleDbCommand = New OleDbCommand(sqlQRY2, myConnexion)
Dim cmd3 As OleDbCommand = New OleDbCommand(sqlQRY3, myConnexion)
'exécution des requetes
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
cmd3.ExecuteNonQuery()
MsgBox("Test ajouté avec succés.", MsgBoxStyle.Information)
extensionImageFile = Nothing
'fermer la connexion
myConnexion.Close()
TextBox1.Text = ""
TextBox2.Text = ""
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
PictureBox1.Image = Nothing
PictureBox1.BackgroundImage = Nothing
nbTest = nbTest - 1
Catch ex As Exception
MsgBox("Operation suspendue, merci de cliquer de nouveau sur le bouton 'Enregistrer le Test' !!")
MsgBox(nomImage)
MsgBox(nomImage.Length)
Finally
myConnexion.Close()
End Try
'tester s'il reste encore des tests a configurer
If nbTest > 0 Then
Label7.Text = nbTest.ToString + " tests restants"
Else
'si les tests sont terminés
'on quitte
Me.Hide()
MenuForm.Show()
MenuForm.TopMost = True
End If
End If
End Sub |
Partager