Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Bidasse Private _Prénom As String, _Patronyme As String, _Salaire As Double Public Property Prénom As String Get Return _Prénom End Get Set(ByVal Vlr As String) _Prénom = Vlr End Set End Property Public Property Patronyme As String Get Return _Patronyme End Get Set(ByVal Vlr As String) _Patronyme = Vlr End Set End Property Public Property Salaire As Double Get Return _Salaire End Get Set(ByVal Vlr As Double) _Salaire = Vlr End Set End Property End Class
Imports System.Collections.Generic Public Class Bidasses Implements IEnumerable Private Col As System.Collections.Generic.List(Of Bidasse) Public Sub New() Col = New System.Collections.Generic.List(Of Bidasse) End Sub Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Return Col.GetEnumerator End Function Public Function Nombre() As Integer Return Col.Count End Function Default Public ReadOnly Property Item(ByVal Rng As Integer) As Bidasse Get Return Col.Item(Rng) End Get End Property Public Sub Ajouter(ByVal Bid As Bidasse) Col.Add(Bid) End Sub Public Sub Retirer(ByVal Rng As Integer) Col.RemoveAt(Rng) End Sub Public Sub Vider() Col.Clear() End Sub Public Function Rang(ByVal Bid As Bidasse) As Integer Return Col.IndexOf(Bid) End Function End Class
Public Class Adjudant Private _Prénom As String, _Patronyme As String, _Salaire As Double, _Bidasses As Bidasses Public Property Prénom As String Get Return _Prénom End Get Set(ByVal Vlr As String) _Prénom = Vlr End Set End Property Public Property Patronyme As String Get Return _Patronyme End Get Set(ByVal Vlr As String) _Patronyme = Vlr End Set End Property Public Property Salaire As Double Get Return _Salaire End Get Set(ByVal Vlr As Double) _Salaire = Vlr End Set End Property Public Property Bidasses As Bidasses Get Return _Bidasses End Get Set(ByVal Vlr As Bidasses) _Bidasses = Vlr End Set End Property End Class
Imports System.Collections.Generic Public Class Adjudants Implements IEnumerable Private Col As System.Collections.Generic.List(Of Adjudant) Public Sub New() Col = New System.Collections.Generic.List(Of Adjudant) End Sub Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Return Col.GetEnumerator End Function Public Function Nombre() As Integer Return Col.Count End Function Default Public ReadOnly Property Item(ByVal Rng As Integer) As Adjudant Get Return Col.Item(Rng) End Get End Property Public Sub Ajouter(ByVal Adj As Adjudant) Col.Add(Adj) End Sub Public Sub Retirer(ByVal Rng As Integer) Col.RemoveAt(Rng) End Sub Public Sub Vider() Col.Clear() End Sub Public Function Rang(ByVal Adj As Adjudant) As Integer Return Col.IndexOf(Adj) End Function End Class
Public Class Capitaine Private _Prénom As String, _Patronyme As String, _Salaire As Double, _Adjudants As Adjudants Public Property Prénom As String Get Return _Prénom End Get Set(ByVal Vlr As String) _Prénom = Vlr End Set End Property Public Property Patronyme As String Get Return _Patronyme End Get Set(ByVal Vlr As String) _Patronyme = Vlr End Set End Property Public Property Salaire As Double Get Return _Salaire End Get Set(ByVal Vlr As Double) _Salaire = Vlr End Set End Property Public Property Adjudants As Adjudants Get Return _Adjudants End Get Set(ByVal Vlr As Adjudants) _Adjudants = Vlr End Set End Property End Class
Imports System.IO Imports System.IO.Path Module Utilitaires Public Function FichierExistant(ByVal Chemin As String) As Boolean Dim Fch As Boolean Fch = File.Exists(Chemin) Return Fch End Function Public Function DossierProjet() As String Dim Dos As String Dos = Application.StartupPath : Dos = GetDirectoryName(Dos) : Dos = GetDirectoryName(Dos) Return Dos End Function End Module
Imports System.IO Imports System.Runtime.Serialization Imports System.Runtime.Serialization.Formatters.Binary Module Sauvegarde <Serializable()> Private Structure sBidasse Dim Prénom As String Dim Patronyme As String Dim Salaire As Double End Structure Private Function ObjBidasse(ByVal sBid As sBidasse) As Bidasse Dim Obj As New Bidasse With Obj .Prénom = sBid.Prénom .Patronyme = sBid.Patronyme .Salaire = sBid.Salaire End With Return Obj End Function Private Function StrBidasse(ByVal Bid As Bidasse) As sBidasse Dim Str As New sBidasse With Str .Prénom = Bid.Prénom .Patronyme = Bid.Patronyme .Salaire = Bid.Salaire End With Return Str End Function <Serializable()> Private Structure sBidasses Dim Lst() As sBidasse End Structure Private Function ObjBidasses(ByVal sBids As sBidasses) As Bidasses Dim Obj As New Bidasses, i As Integer, n As Integer n = sBids.Lst.Length - 1 With Obj For i = 1 To n .Ajouter(ObjBidasse(sBids.Lst(i))) Next End With Return Obj End Function Private Function StrBidasses(ByVal Bids As Bidasses) As sBidasses Dim Str As New sBidasses, i As Integer, n As Integer With Str n = Bids.Nombre : ReDim .Lst(n) For i = 1 To n .Lst(i) = StrBidasse(Bids(i - 1)) Next End With Return Str End Function <Serializable()> Private Structure sAdjudant Dim Prénom As String Dim Patronyme As String Dim Salaire As Double Dim Bidasses As sBidasses End Structure Private Function ObjAdjudant(ByVal sAdj As sAdjudant) As Adjudant Dim Obj As New Adjudant With Obj .Prénom = sAdj.Prénom .Patronyme = sAdj.Patronyme .Salaire = sAdj.Salaire .Bidasses = ObjBidasses(sAdj.Bidasses) End With Return Obj End Function Private Function StrAdjudant(ByVal Adj As Adjudant) As sAdjudant Dim Str As New sAdjudant With Str .Prénom = Adj.Prénom .Patronyme = Adj.Patronyme .Salaire = Adj.Salaire .Bidasses = StrBidasses(Adj.Bidasses) End With Return Str End Function <Serializable()> Private Structure sAdjudants Dim Lst() As sAdjudant End Structure Private Function ObjAdjudants(ByVal sAdjs As sAdjudants) As Adjudants Dim Obj As New Adjudants, i As Integer, n As Integer n = sAdjs.Lst.Length - 1 With Obj For i = 1 To n .Ajouter(ObjAdjudant(sAdjs.Lst(i))) Next End With Return Obj End Function Private Function StrAdjudants(ByVal Adjs As Adjudants) As sAdjudants Dim Str As New sAdjudants, i As Integer, n As Integer With Str n = Adjs.Nombre : ReDim .Lst(n) For i = 1 To n .Lst(i) = StrAdjudant(Adjs(i - 1)) Next End With Return Str End Function <Serializable()> Private Structure sCapitaine Dim Prénom As String Dim Patronyme As String Dim Salaire As Double Dim Adjudants As sAdjudants End Structure Private Function ObjCapitaine(ByVal sCap As sCapitaine) As Capitaine Dim Obj As New Capitaine With Obj .Prénom = sCap.Prénom .Patronyme = sCap.Patronyme .Salaire = sCap.Salaire .Adjudants = ObjAdjudants(sCap.Adjudants) End With Return Obj End Function Private Function StrCapitaine(ByVal Cap As Capitaine) As sCapitaine Dim Str As New sCapitaine With Str .Prénom = Cap.Prénom .Patronyme = Cap.Patronyme .Salaire = Cap.Salaire .Adjudants = StrAdjudants(Cap.Adjudants) End With Return Str End Function Public Sub SauverProgramme() Dim Fch As FileStream = New FileStream(Chm, FileMode.Create) Dim Frm As New BinaryFormatter Dim Typ As sCapitaine Typ = StrCapitaine(aCap) Frm.Serialize(Fch, Typ) Fch.Close() End Sub Public Sub ChargerProgramme() Dim Fch As FileStream = New FileStream(Chm, FileMode.Open) Dim Frm As New BinaryFormatter Dim Typ As sCapitaine Typ = CType(Frm.Deserialize(Fch), sCapitaine) Fch.Close() nCap = ObjCapitaine(Typ) End Sub End Module
Module Globales Public aCap As New Capitaine, nCap As New Capitaine Public Chm As String End Module
Imports System.Environment Public Class Accueil '(formulaire) 'Commandes Private Sub Accueil_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Chm = DossierProjet() & "\ApplicationTypeIO.bin" End Sub Private Sub bCns_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bCns.Click ConstruireProgrammme() bFoc.Focus() End Sub Private Sub bLir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bLir.Click LireProgramme(nCap) : bLir.Enabled = False bFoc.Focus() End Sub Private Sub bChg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bChg.Click If FichierExistant(Chm) Then ChargerProgramme() : bLir.Enabled = True Else MessageBox.Show("Le fichier " & NewLine & " " & Chm & NewLine & "est introuvable.") End If End Sub Private Sub bSav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bSav.Click SauverProgramme() bFoc.Focus() End Sub 'Procédures Private Sub ConstruireProgrammme() Dim Bid As Bidasse, Bids As Bidasses, Adj As Adjudant, Adjs As Adjudants Adjs = New Adjudants Bids = New Bidasses Bid = fBid("Jean", "Govaert", 10) : Bids.Ajouter(Bid) Bid = fBid("Hic", "Babasse", 8) : Bids.Ajouter(Bid) Bid = fBid("Luc", "Leduc", 11) : Bids.Ajouter(Bid) Adj = fAdj("Michel", "Sanier", 100, Bids) : Adjs.Ajouter(Adj) Bids = New Bidasses Bid = fBid("Marc", "Florin", 10) : Bids.Ajouter(Bid) Bid = fBid("Cadet", "Roussel", 9) : Bids.Ajouter(Bid) Bid = fBid("Léa", "Wouha", 8) : Bids.Ajouter(Bid) Adj = fAdj("Bernard", "Baillon", 100, Bids) : Adjs.Ajouter(Adj) aCap = fCap("Fra", "Parsy", 1000, Adjs) bFoc.Focus() End Sub Private Function fBid(ByVal Prn As String, ByVal Ptr As String, ByVal Sal As Double) As Bidasse Dim Bid As New Bidasse With Bid .Prénom = Prn .Patronyme = Ptr .Salaire = Sal End With Return Bid End Function Private Function fAdj(ByVal Prn As String, ByVal Ptr As String, ByVal Sal As Double, ByVal Bids As Bidasses) As Adjudant Dim Adj As New Adjudant With Adj .Prénom = Prn .Patronyme = Ptr .Salaire = Sal .Bidasses = Bids End With Return Adj End Function Private Function fCap(ByVal Prn As String, ByVal Ptr As String, ByVal Sal As Double, ByVal Adjs As Adjudants) As Capitaine Dim Cap As New Capitaine With Cap .Prénom = Prn .Patronyme = Ptr .Salaire = Sal .Adjudants = Adjs End With Return Cap End Function Private Sub LireProgramme(ByVal Cap As Capitaine) Dim Bid As Bidasse, Adj As Adjudant, Txt As String Txt = "" With Cap Txt = Txt & .Prénom & " " & .Patronyme & " gagne " & .Salaire.ToString & "€ par mois" & NewLine End With For Each Adj In Cap.Adjudants With Adj Txt = Txt & " " & .Prénom & " " & .Patronyme & " gagne " & .Salaire.ToString & "€ par mois" & NewLine End With For Each Bid In Adj.Bidasses With Bid Txt = Txt & " " & .Prénom & " " & .Patronyme & " gagne " & .Salaire.ToString & "€ par mois" & NewLine End With Next Next MessageBox.Show(Txt) Clipboard.Clear() Clipboard.SetText(Txt) End Sub End Class