Bonjour,
Je souhaite développer une interface qui permet de gérer des commandes d'un restaurant.
J'ai donc une interface qui permet de prendre et d’enregistrer des commandes, on sélectionne le numéro de table dans un combobox, puis dans différentes datagridview on peut choisir des entrées, plats, desserts, et boissons et leur quantité.
Voici le code :Cette interface fonctionne, ou du moins il me semble que les données sont enregistrer car la une msgbox apparaît avec les différents noms de plats choisi.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
172
173
174
175
176
177 Public Class PrendreCommande 'Définition Dim EntreeList As New List(Of Plat) Dim PlatList As New List(Of Plat) Dim DessertList As New List(Of Plat) Dim BoissonList As New List(Of Plat) Dim colonneQuantE As Integer Dim colonneQuantP As Integer Dim colonneQuantD As Integer Dim colonneQuantB As Integer Private Sub PrendreCommande_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Initialisation des datagridview DataE.Rows.Clear() DataP.Rows.Clear() DataD.Rows.Clear() DataB.Rows.Clear() 'Création des colonnes Dim colonneEntree As New DataGridViewComboBoxColumn() Dim colonnePlat As New DataGridViewComboBoxColumn() Dim colonneDessert As New DataGridViewComboBoxColumn() Dim colonneBoisson As New DataGridViewComboBoxColumn() 'Affectation des colones à la datagrid colonneEntree = DataE.Columns(0) colonnePlat = DataP.Columns(0) colonneDessert = DataD.Columns(0) colonneBoisson = DataB.Columns(0) 'Initialisation des listes de plats EntreeList.Clear() PlatList.Clear() DessertList.Clear() BoissonList.Clear() 'Entrée EntreeList.Add(New Plat("Saumon en croute", 0, 5)) EntreeList.Add(New Plat("Sheperd's pie en verrine", 0, 5)) EntreeList.Add(New Plat("Diccalillu traditionnel", 0, 5)) EntreeList.Add(New Plat("Salade paysanne", 0, 5)) EntreeList.Add(New Plat("Salade Mortuacienne", 0, 5)) EntreeList.Add(New Plat("Terrine maison", 0, 5)) EntreeList.Add(New Plat("Soupe de Légumes", 0, 5)) EntreeList.Add(New Plat("Assiette de charcuterie", 0, 5)) EntreeList.Add(New Plat("Tarte au fromage", 0, 5)) EntreeList.Add(New Plat("Citrons farcis au thon", 0, 5)) EntreeList.Add(New Plat("jambon de Parme", 0, 5)) EntreeList.Add(New Plat("Salade de tomates aux boules de mozzarelle et pesto", 0, 5)) 'Plat PlatList.Add(New Plat("Pates à la carbonara", 1, 10)) PlatList.Add(New Plat("Pizza", 1, 10)) PlatList.Add(New Plat("Carpaccio accompagné de son risotto aux champignons", 1, 10)) PlatList.Add(New Plat("Frite steak haché", 1, 10)) PlatList.Add(New Plat("Pommes de terre frit cordon bleu", 1, 10)) PlatList.Add(New Plat("Pattes nuggets", 1, 10)) PlatList.Add(New Plat("Rushtis de pomme de terre avec de la palette", 1, 10)) PlatList.Add(New Plat("Mont d'or chaud", 1, 10)) PlatList.Add(New Plat("Morbiflette", 1, 10)) PlatList.Add(New Plat("Gigot à la menthe", 1, 10)) PlatList.Add(New Plat("Fish and chip's", 1, 10)) PlatList.Add(New Plat("Agneau au whisky", 1, 10)) 'Dessert DessertList.Add(New Plat("Tiramis", 2, 7)) DessertList.Add(New Plat("Glace à l'italienne", 2, 7)) DessertList.Add(New Plat("Assiette de fromages", 2, 7)) DessertList.Add(New Plat("Boule de glasses aux choix", 2, 7)) DessertList.Add(New Plat("Fondant au chocolat", 2, 7)) DessertList.Add(New Plat("Crème brulée", 2, 7)) DessertList.Add(New Plat("Fondant au chocolat", 2, 7)) DessertList.Add(New Plat("Gelée", 2, 7)) DessertList.Add(New Plat("Gâteau roulé au citron", 2, 7)) DessertList.Add(New Plat("Pudding fondant à la crème et aux noix", 2, 7)) 'Boisson BoissonList.Add(New Plat("Vin", 3, 2)) BoissonList.Add(New Plat("Coca cola", 3, 2)) BoissonList.Add(New Plat("Eau pétillante", 3, 2)) BoissonList.Add(New Plat("Fanta", 3, 2)) BoissonList.Add(New Plat("Oasis", 3, 2)) BoissonList.Add(New Plat("Vittel", 3, 2)) BoissonList.Add(New Plat("Pontarlier", 3, 2)) BoissonList.Add(New Plat("Whisky", 3, 2)) BoissonList.Add(New Plat("Sprit", 3, 2)) BoissonList.Add(New Plat("eau", 3, 2)) For Each myEntree As Plat In EntreeList colonneEntree.Items.Add(myEntree.GetNomPlat) Next For Each myplat As Plat In PlatList colonnePlat.Items.Add(myplat.GetNomPlat) Next For Each myDessert As Plat In DessertList colonneDessert.Items.Add(myDessert.GetNomPlat) Next For Each myBoisson As Plat In BoissonList colonneBoisson.Items.Add(myBoisson.GetNomPlat) Next End Sub 'Pour fermer la fenetre Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub ' Validation des commandes : Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Quand on clique sur valider : 'Création de newCom comme une nouvelle commande Dim newCom As New Commande 'Pour chaque Catégorie (Entrée,Plat,Dessert et Boisson), on créé un nouveau plat 'Il se compose du numéro de la table ' Pour le choix des entrées For i = 0 To DataE.RowCount - 2 Dim choixE As New Plat choixE.SetNomPlat(DataE.Item(0, i).Value) choixE.SetCategorieP("Entrée") choixE.SetQuant(DataE.Item(1, i).Value) If choixE.GetQuant > 0 Then newCom.ajouter_plat(choixE) End If Next 'Pour le choix des plats For i = 0 To DataP.RowCount - 2 Dim choixP As New Plat choixP.SetNomPlat(DataP.Item(0, i).Value) choixP.SetCategorieP("Plat") choixP.SetQuant(DataP.Item(1, i).Value) If choixP.GetQuant > 0 Then newCom.ajouter_plat(choixP) End If Next 'Pour le choix des Desserts For i = 0 To DataD.RowCount - 2 Dim choixD As New Plat choixD.SetNomPlat(DataD.Item(0, i).Value) choixD.SetCategorieP("Dessert") choixD.SetQuant(DataD.Item(1, i).Value) If choixD.GetQuant > 0 Then newCom.ajouter_plat(choixD) End If Next 'Pour le choix des Boissons For i = 0 To DataB.RowCount - 2 Dim choixB As New Plat choixB.SetNomPlat(DataB.Item(0, i).Value) choixB.SetCategorieP("Boisson") choixB.SetQuant(DataB.Item(1, i).Value) If choixB.GetQuant > 0 Then newCom.ajouter_plat(choixB) End If Next 'Pour enregistrer le numéro de la table et donc le numéro de la commande newCom.SetNumeroTable(ComboBox1.SelectedItem) 'Verfication pour l'enregistrement For Each element As Plat In newCom.listeClient MsgBox(element.GetNomPlat) Next 'pour fermer la fenetre une fois la commande validée Me.Close() End Sub End Class
Mon problème réside dans une autre interface :
Dans une autre interface je souhaite visualiser le détails des commandes: On choisi le numéro de table et le nom des plats et leur quantité doivent apparaître dans une datagridview simple.
Voici le code correspondant :
Il n'y a aucune erreur lors de la compilation.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class SuivreCommandeTaT Public totalcommande As Restaurant = New Restaurant() Public numero As Integer = 0 'Pour fermer la fenêtre Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub 'Pour initialiser la fenetre chaque ouverture de la fenetre Private Sub SuivreCommandeTaT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' DataGridView1.Rows.Clear() End Sub Private Sub ValNumTab_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim nb As Integer = ComboBox1.SelectedItem numero = nb DataGridView1.Rows.Clear() For Each element As Commande In totalcommande.listeCommande If nb = element.GetNumeroTable Then For Each elem As Plat In element.GetlisteClient DataGridView1.Rows.Add(elem.GetNomPlat(), elem.GetQuant(), elem.PrixHT.ToString) ', elem.prixtot(), elem.prix_tva(totalcommande.GetTVA()), elem.PrixTTC(totalcommande.GetTVA())}) Next End If Next End Sub End Class
Pour info complémentaire voici les différentes classes que j'ai créée :
la classe commande :
la classe plat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class Commande 'Attribus Public NumeroTable As Integer Public listeClient As List(Of Plat) Private EtatCommande As Boolean 'Etat commande = False, la commande n'a pas encore été réglée 'Etat commande = True, la commande a été réglée 'Méthodes 'Constructeurs Public Sub New(ByVal NumT As Integer, ByVal EtatCom As Boolean, ByVal listeC As List(Of Plat)) NumeroTable = NumT listeClient = listeC EtatCommande = EtatCom End Sub Public Sub New() listeClient = New List(Of Plat) EtatCommande = False End Sub 'Accesseurs 'Numéro table Public Function GetNumeroTable() Return NumeroTable End Function Public Sub SetNumeroTable(ByVal argNumeroTable As Integer) NumeroTable = argNumeroTable End Sub 'Liste Client Public Function GetlisteClient() Return listeClient End Function Public Sub SetlisteClient(ByVal arglisteClient As List(Of Plat)) listeClient = arglisteClient End Sub 'etat de la commande Public Function GetEtatCommande() Return EtatCommande End Function 'Setteur spécial pour gérer l'état de la commande Public Sub SetEtatCommande(ByVal argEtatCommande As String) If argEtatCommande = "payée" Then EtatCommande = True Else EtatCommande = False End If End Sub 'Fonction pour gérer la commande 'ajouter un plat : Public Sub ajouter_plat(ByVal choix As Plat) listeClient.Add(choix) End Sub 'Pour calculer le prix des commandes ' Pour calculer le prix total sans la TVA Public Function PrixtotalHT() 'Creation de la variable SommeHT comme decimale et initialisation à 0 Dim sommeHT As Decimal = 0 For Each element As Plat In listeClient sommeHT = sommeHT + element.PrixHT Next Return sommeHT End Function 'POur calculer le prix total de la TVA Public Function TVAtotale(ByVal tva As Decimal) Dim sommeTVA As Decimal = 0 For Each element As Plat In listeClient sommeTVA = sommeTVA + element.prix_tva(tva) Next Return sommeTVA End Function 'Pour calculer le prix de la commande totale avec la TVA Public Function PrixtotalTTC(ByVal tva As Decimal) Dim sommeTTC As Decimal = 0 For Each element As Plat In listeClient sommeTTC = sommeTTC + element.PrixTTC(tva) Next Return sommeTTC End Function End Class
la classe restaurant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class Plat ' Attributs Public NomPlat As String Public CategorieP As String Public Quantite As Integer Public PrixHT As Integer 'Constructeurs '-> pour rentrer le nom des plats dans l'interface Public Sub New(ByVal NomPC As String, ByVal CatPC As String, ByVal argprix As Integer) NomPlat = NomPC CategorieP = CatPC PrixHT = argprix End Sub '-> pour utiliser la classe Plat dans d'autres classes ou interfaces Public Sub New() End Sub 'Accesseurs 'Prix HT Public Sub SetPrixHt(ByVal argPrixHt As Integer) PrixHT = argPrixHt End Sub Public Function GetPrixHt() Return PrixHT End Function 'Nom du Plat Public Sub SetNomPlat(ByVal argNomPlat As String) NomPlat = argNomPlat End Sub Public Function GetNomPlat() Return NomPlat End Function 'Quantité Public Sub SetQuant(ByVal argQuant As String) Quantite = argQuant End Sub Public Function GetQuant() Return Quantite End Function 'Categorie Public Sub SetCategorieP(ByVal argCategoriePlat As String) CategorieP = argCategoriePlat End Sub Public Function GetCategoriePlat() Return CategorieP End Function 'Calcul du prix total sans tva: Public Function prixtot() Return PrixHT * Quantite End Function 'Calucul de la tva Public Function prix_tva(ByVal tva As Decimal) Return PrixHT * Quantite * tva End Function 'Calcul du prix total avec tva Public Function PrixTTC(ByVal tva As Decimal) Return prixtot() + prix_tva(tva) End Function End Class
Merci pour votre aide !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class Restaurant 'Attributs : Public listeCommande As List(Of Commande) Public Menu As List(Of Plat) Private TVA As Decimal 'Accesseurs : 'Liste des commandes Public Sub New() listeCommande = New List(Of Commande) Menu = New List(Of Plat) TVA = 0.55 End Sub Public Sub SetListeCom(ByVal arg As List(Of Commande)) listeCommande = arg End Sub Public Function GetListeCom() Return listeCommande End Function 'Liste des menus Public Sub SetMenu(ByVal arg As List(Of Plat)) Menu = arg End Sub Public Function GetMenu() Return Menu End Function 'Tva Public Function GetTVA() Return TVA End Function 'Pour ajouter une commande Public Sub AjouterCommande(ByVal arg As Commande) listeCommande.Add(arg) End Sub ' demander a quoi sert cette fonction Public Function GetPrix(ByVal arg As String) For Each element As Plat In Menu If element.GetNomPlat = arg Then Return element.GetPrixHt End If Next Return 0 End Function 'Pour modifier l'état d'une commande Public Sub ModifierEtat(ByVal arg As Integer, ByVal etat As String) Dim nb As Integer For Each element As Commande In listeCommande nb = element.GetNumeroTable() If nb = arg Then element.SetEtatCommande(etat) Exit For End If Next End Sub End Class
Partager