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
| Module ModulePrincip
Public IndiceLivre As Integer ' permettra de gerer les deplacements
Dim Principal As New FrmPrincip()
Sub Main()
IndiceLivre = 0
System.Windows.Forms.Application.Run(Principal) ' Principal est le forms
End Sub
End Module
Imports System
Imports System.Data.OleDb
Imports System.IO
Public Class FrmPrincip
Inherits System.Windows.Forms.Form
'
'La connexion
'
Const ChaineConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\BdBibliotheque.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
Public MaConnex As New OleDb.OleDbConnection(ChaineConn)
Dim DataSetLivre As New DataSet()
Dim ResReq As DataTable
Dim UnEnreg As DataRow
Dim MaReqt As New OleDb.OleDbDataAdapter()
Private Sub FrmPrincip_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ObjCmd As New OleDb.OleDbCommand()
Dim ChaineSql As String
ChaineSql = "SELECT CodMedia, Titre FROM Media"
Try
MaConnex.Open()
ObjCmd.CommandText = ChaineSql
' la propriete commandtext contient la chaine sql
ObjCmd.Connection = MaConnex
MaReqt.SelectCommand = ObjCmd
Catch ex As Exception
MsgBox("Connexion Impossible")
End Try
End Sub
Private Sub BtnCharger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCharger.Click
Try
MaReqt.Fill(DataSetLivre, "Liste des livres")
Catch ex As Exception
MsgBox("Erreur lors du chargement des données", MsgBoxStyle.Critical)
End Try 'Inutile d'aller plus loin !
MaConnex.Close()
ResReq = DataSetLivre.Tables("Liste des livres")
AfficheLivre()
' Utilisation d'une procedure d'affichage
BtnSuivant.Enabled = True
' les boutons de parcours sont utilisables
BtnPrecedent.Enabled = True
End Sub
Private Sub BtnQuitter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuitter.Click
End
End Sub
Private Sub BtnPrecedent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrecedent.Click
If IndiceLivre = 0 Then
MsgBox("il n'y a plus de livre à visualiser")
Else
IndiceLivre = IndiceLivre - 1
AfficheLivre()
End If
End Sub
Private Sub BtnSuivant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSuivant.Click
If IndiceLivre = ResReq.Rows.Count - 1 Then
MsgBox("Il n'y a plus de livre à visualiser")
Else
IndiceLivre = IndiceLivre + 1
AfficheLivre()
End If
End Sub
Private Sub AfficheLivre()
Try
UnEnreg = ResReq.Rows(IndiceLivre)
TxtCodeLivre.Text = UnEnreg("CodeMedia")
TxtTitreLivre.Text = UnEnreg(1)
Catch ex As Exception
MsgBox("Erreur de referencement d'objet, l'application ne peut tourner", MsgBoxStyle.Critical)
End Try
End Sub
End Class |
Partager