Sie sind auf Seite 1von 9

Form general

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Btncharger_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Btncharger.Click
ChaineSql = "select NumLivre,NomLivre from LIVRE"
'ChaineSql = "insert into LIVRE values(1,'livre1',1) "
ObjCmd.CommandText = ChaineSql
ObjCmd.Connection = MaConnexion
Mareq.SelectCommand = ObjCmd
Try
MaConnexion.Open()
ObjCmd.ExecuteNonQuery()
Mareq.Fill(DataSetLivre, "Liste des livres")
Catch ex As Exception
MsgBox(ex.Message)
End
End Try
MaConnexion.Close()
ResReq = DataSetLivre.Tables("Liste des livres")
AfficheLivre()
End Sub
Private Sub AfficheLivre()

Unenreg = ResReq.Rows(IndiceLivre)
TextBox1.Text = Unenreg(0)
TextBox2.Text = Unenreg(1)

End Sub
Private Sub btnquitter_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnquitter.Click
Dim i As Integer
i = MsgBox("êtes vous sûre de fermer?", MsgBoxStyle.Question +
MsgBoxStyle.YesNo)
If i = vbYes Then
Application.Exit() 'end
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("c le dernier")
Else
IndiceLivre = IndiceLivre + 1
If (ResReq.Rows(IndiceLivre).RowState = DataRowState.Deleted) Then
Me.TextBox1.Text = "*******"
Me.TextBox2.Text = "*******"
Else
AfficheLivre()
End If
End If
End Sub

Private Sub btnprecedent_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnprecedent.Click
If IndiceLivre = 0 Then
MsgBox("c le premier")
Else
IndiceLivre = IndiceLivre - 1
If (ResReq.Rows(IndiceLivre).RowState = DataRowState.Deleted) Then
Me.TextBox1.Text = "*******"
Me.TextBox2.Text = "*******"

Else
AfficheLivre()

End If
End If
End Sub

Private Sub BtnPremier_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BtnPremier.Click
IndiceLivre = 0
If (ResReq.Rows(IndiceLivre).RowState = DataRowState.Deleted) Then
Me.TextBox1.Text = "*******"
Me.TextBox2.Text = "*******"
Else
AfficheLivre()
End If
End Sub

Private Sub btndernier_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btndernier.Click
IndiceLivre = ResReq.Rows.Count - 1
If (ResReq.Rows(IndiceLivre).RowState = DataRowState.Deleted) Then
Me.TextBox1.Text = "*******"
Me.TextBox2.Text = "*******"
Else
AfficheLivre()
End If
End Sub

Private Sub btnAjouter_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnAjouter.Click
Dim NouveauLivre As DataRow
NouveauLivre = ResReq.NewRow
NouveauLivre(0) = ResReq.Rows.Count + 1
NouveauLivre(1) = Me.TextBox2.Text

ResReq.Rows.Add(NouveauLivre)
End Sub

Private Sub btnNouveau_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNouveau.Click
Me.TextBox1.Text = ResReq.Rows.Count + 1
Me.TextBox2.Text = ""
End Sub

Private Sub btnModifier_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnModifier.Click
Unenreg = ResReq.Rows(IndiceLivre)
Unenreg.BeginEdit()
Unenreg(1) = Me.TextBox2.Text
Unenreg.EndEdit()
End Sub

Private Sub btnValider_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnValider.Click
ocb = New OleDb.OleDbCommandBuilder(Mareq)
Try
MaConnexion.Open()
Mareq.Update(DataSetLivre, "Liste des livres")
' Mareq.Fill(DataSetLivre, "Liste des livres")

'DataSetLivre.Clear()
' ResReq = DataSetLivre.Tables("Liste des livres")
MaConnexion.Close()
MsgBox(" Validation est bien effectues")
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Private Sub btnAnnuler_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnAnnuler.Click
Dim res As String = MsgBox("voulez vous annuler les modifications effectués",
MsgBoxStyle.YesNo, "Gestion biblio")
If vbYes Then
ResReq.RejectChanges()
End If
MsgBox(" Annulation est bien effectues ")
End Sub

Private Sub Supprimer_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Supprimer.Click
Dim sauvindice As Integer
ResReq.Rows(IndiceLivre).Delete()
sauvindice = IndiceLivre

If (IndiceLivre < (ResReq.Rows.Count - 1)) Then


Do
IndiceLivre = IndiceLivre + 1
Loop Until (IndiceLivre > ResReq.Rows.Count - 1) Or
(ResReq.Rows(IndiceLivre).RowState <> DataRowState.Deleted)
If IndiceLivre > ResReq.Rows.Count - 1 Then
IndiceLivre = -1
Do
IndiceLivre = IndiceLivre + 1
Loop Until (IndiceLivre = sauvindice) Or
(ResReq.Rows(IndiceLivre).RowState <> DataRowState.Deleted)

If IndiceLivre = sauvindice Then


MsgBox("Il n'y a plus de livre", MsgBoxStyle.Critical)
TextBox1.Text = "***********"
TextBox2.Text = "************"
Else
AfficheLivre()
End If
Else
AfficheLivre()
End If
Else
IndiceLivre = -1
Do
IndiceLivre = IndiceLivre + 1
Loop Until (IndiceLivre = sauvindice) Or (ResReq.Rows(IndiceLivre).RowState
<> DataRowState.Deleted)

If IndiceLivre = sauvindice Then


MsgBox("Il n'y a plus de livre", MsgBoxStyle.Critical)
TextBox1.Text = "***********"
TextBox2.Text = "************"
Else
AfficheLivre()
End If
End If
End Sub

Private Sub BtnRechercher_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BtnRechercher.Click
If Me.TextBox1.Text = "" Then
MsgBox("veuillez saisir le numero de livre à rechercher", MsgBoxStyle.Critical,
"Attention!")
Else
If existe(Me.TextBox1.Text.Trim) Then
AfficheLivre()
Else
MsgBox("cet enregistrement n'existe pas!", MsgBoxStyle.Critical,
"Information!")
End If
End If
End Sub
Function existe(ByVal x As String) As Boolean
existe = False
For IndiceLivre = 0 To ResReq.Rows.Count - 1
If ResReq.Rows(IndiceLivre).Item(0) = x.Trim Then
existe = True
Exit For
End If
Next
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
comboDatagrid.Show()
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged

End Sub
End Class
Module

Module Module1
Public Const ChaineConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\bdBibliotheque.mdb"
Public MaConnexion As New OleDb.OleDbConnection(ChaineConn)
Public IndiceLivre As Integer
Public Mareq As New OleDb.OleDbDataAdapter
Public ObjCmd As New OleDb.OleDbCommand
Public ChaineSql As String
Public DataSetLivre As New DataSet
Public ResReq As DataTable
Public a As Integer

Public Unenreg As DataRow


Public dav1 As DataView
Public ocb As New OleDb.OleDbCommandBuilder

Public f2 As New comboDatagrid


Public principale As New Form1

Sub main()
IndiceLivre = 0
System.Windows.Forms.Application.Run(principale)
End Sub
End Modul

Code de liste des livres par client

Private Sub comboDatagrid_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Populate()
ComboBox1.DataSource = DataSetLivre.Tables(0)
ComboBox1.DisplayMember = "NomCli"
Me.BindingContext(DataSetLivre.Tables(0)).Position = 0
dav1 = New DataView(DataSetLivre.Tables("LIVRE"))
Dim strFilter = "NumCli=" & _
(ComboBox1.SelectedIndex + 1).ToString
dav1.RowFilter = strFilter
DataGrid1.DataSource = dav1
a=1
End Sub
Sub Populate()
ObjCmd = New OleDbCommand("select * from CLIENT", MaConnexion)
Mareq = New OleDbDataAdapter
Mareq.SelectCommand = ObjCmd
MaConnexion.Open()
DataSetLivre = New DataSet
Mareq.Fill(DataSetLivre, "CLIENT")
ObjCmd.CommandText = "select * from LIVRE"
Mareq.SelectCommand = ObjCmd
Mareq.Fill(DataSetLivre, "LIVRE")
MaConnexion.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If a = 1 Then
Dim strFilter = "Numcli=" & _
(ComboBox1.SelectedIndex + 1)
dav1.RowFilter = strFilter
End If

End Sub
End Class
Interface liste des livres par client

Das könnte Ihnen auch gefallen