bonjour à tous,

projet sous vs2019 winforms ...

j'abandonne ou pas ? apres des dizaines d'heures de recherche, je suis parvenu à réaliser l'exploit de transmettre une variable d'une classe à une autre (string je précise) avec cette petite méthode chinée je ne sais plus ou :
public class Variables
{
private static string name = "";

public static string Name
{
get { return name; }
set { name = value; }

}
}
on voit bien dans cet exemple que l'on peut initialiser puis récupérer la valeur de name (dans une classe héritée je suppose) pour la transmettre ailleurs via la méthode "Variables" grâce au (get return) et enfin récupérée avec un petit "string var = Variables.Name;" dans une autre classe.
je pensais détenir une piste pour réaliser la même chose avec un combobox ^^ mais que nenni

et c'est là qu'est le drame ... jamais en mes débuts (si lointain) je n'aurais imaginé passer autant de temps à chercher une petite chose aussi simple à réalisée (en php faudrait ... quelques secondes ?) bref .... si l'un d'entre vous veut bien se coller un petit pépère qui patauge (quoique + de 30 heures de recherches ça instruit quand même sur ce langage) j'en serais extrêmement ravi et reconnaissant ... dans la mesure du possible

alors oui pour ceux qui veulent plus d'infos sur ce que je veux faire :

l'utilisateur saisie un nombre de match (ici 3) et un nombre de grille (ici 8) (dans form1) pour faire ses paris sur une plateforme bien connue ...

Nom : form1.JPG
Affichages : 245
Taille : 26,6 Ko

ensuite, apres avoir cliqué sur le bouton "générer la grille" la form2 apparait avec les 3 matchs et les 8 grilles !

Nom : form2.JPG
Affichages : 239
Taille : 30,8 Ko

là, il selectionne dans les deux premiers combobox les équipes (j'ai pas encore mis les labels pour locaux et visiteurs, ..... et dans les suivantes le fameux "1, n, 2"
une fois ses choix réalisés .... je bloque !
je dois enregistrer ses choix dans une base de données sqlite ... qui fonctionne très bien, ça au moins c'est fait, mais je ne trouve pas comment les envoyer via le bouton "sauvegarder" puisque celui-ci est d'une classe différente en l'occurrence "button1_Click"


et enfin, le code de form2
"EDIT DU 22:10 -> mise à jour du code"
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Data.Sqlite;
using System.Collections.Generic;
 
 
namespace unibet
{
 
    public partial class Form2 : Form
    {
 
 
        public class combox
        {
            public static List<ComboBox> combol = null;
            public static List<ComboBox> combov = null;
            public static List<ComboBox> combot = null;
 
 
            public static List<ComboBox> ComboL
            {
 
                get { return combol; }
                set { combol = value; }
 
            }
            public static List<ComboBox> ComboV
            {
 
                get { return combov; }
                set { combov = value; }
 
            }
            public static List<ComboBox> ComboT
            {
 
                get { return combot; }
                set { combot = value; }
 
            }
        }
 
 
        public static int paris;
        public static int matchs;
 
        public Form2()
        {
            InitializeComponent();
        }
 
        public void Form2_Load(object sender, EventArgs e)
        {
                List<ComboBox> tableaux = new List<ComboBox>();
                List<ComboBox> visiteurs = new List<ComboBox>();
                List<ComboBox> locaux = new List<ComboBox>();
                ComboBox tableau = null;
                ComboBox visiteur = null;
                ComboBox local = null;
                //initialisation des localisations
                int haut = 100; 
                //initialisation des boucles
                int i = 0;
            int k = 0;
            int l = 0;
                int m = 0;
                int gauche = 0;
                //dimensions des combo
                int sizeH = 20;
                int sizeG = 100;
                int sizeL = 60;
                //indexation des combo
                int indexmatchs = 0;
                int indexparis = 0;
 
            for (int j = 0; j < Form1.matchs; j++)
                {
                // Remplissage du tableau de textbox
                    local = new ComboBox();
                    locaux.Add(local);
 
                    locaux[indexmatchs].Name = String.Format("ComboBox{0}", l);
                    locaux[indexmatchs].Parent = this;
                    locaux[indexmatchs].Size = new System.Drawing.Size(sizeG, sizeH);
                    locaux[indexmatchs].Location = new Point(gauche + 5, haut);
                    locaux[indexmatchs].Visible = true;
                    locaux[indexmatchs].Items.AddRange(new object[] {"   ?", "Psg", "Lyon", "Marseille","Rennes", "Lens", "Nantes", "Monaco","Bordeaux", "Nice", "Angers", "Nîmes", "Metz","Reims","Strasbourg","Montpellier","Dijon","Brest","Lorient","Lille","Saint Etienne" });
                    locaux[indexmatchs].SelectedIndex = 0;
                    locaux[indexmatchs].SelectedIndexChanged += new System.EventHandler(local_SelectedIndexChanged);
                    locaux[indexmatchs].SelectedItem.ToString();
 
                // Remplissage du tableau de textbox
                    visiteur = new ComboBox();
                    visiteurs.Add(visiteur);
 
                    visiteurs[indexmatchs].Name = String.Format("ComboBox{0}", m);
                    visiteurs[indexmatchs].Parent = this;
                    visiteurs[indexmatchs].Size = new System.Drawing.Size(sizeG, sizeH);
                    visiteurs[indexmatchs].Location = new Point(gauche + sizeG + 10, haut);
                    visiteurs[indexmatchs].Visible = true;
                    visiteurs[indexmatchs].Items.AddRange(new object[] { "   ?","Psg", "Lyon", "Marseille", "Rennes", "Lens", "Nantes", "Monaco", "Bordeaux", "Nice", "Angers", "Nîmes", "Metz", "Reims", "Strasbourg", "Montpellier", "Dijon", "Brest", "Lorient", "Lille", "Saint Etienne" });
                    visiteurs[indexmatchs].SelectedIndex = 0;
                    visiteurs[indexmatchs].SelectedIndexChanged += new System.EventHandler(visiteur_SelectedIndexChanged);
                    visiteurs[indexmatchs].SelectedItem.ToString();
 
                // k pour ajouter une ligne de hauteur 25
                // k = k + 25;
 
                for (i = 0; i < Form1.paris; i++)
                    {
                    tableau = new ComboBox();
                    tableaux.Add(tableau);  
 
                    tableaux[indexparis].Name = String.Format("ComboBox{0}", indexparis);               
                    tableaux[indexparis].Parent = this;
                    tableaux[indexparis].Size = new System.Drawing.Size(sizeL, sizeH);
                    tableaux[indexparis].Location = new Point((250 + i * (sizeL+5)), haut);
                    tableaux[indexparis].Visible = true;
                    tableaux[indexparis].Items.AddRange(new object[] {"?","1", "N", "2" });
                    tableaux[indexparis].SelectedIndex = 0;
                    tableaux[indexparis].SelectedIndexChanged += new System.EventHandler(tableau_SelectedIndexChanged);
                    tableaux[indexparis].SelectedItem.ToString();
 
                    indexparis++;
                    k++;                    
                    }                    
             haut = haut + 25;
             indexmatchs++;
             l++;
             m++;
                //envoi des données au get set
 
 
            }
            combox.ComboL = locaux;
            combox.ComboV = visiteurs;
            combox.ComboT = tableaux;
 
 
            //MessageBox.Show(indexmatchs.ToString());
 
 
        }
 
            public void tableau_SelectedIndexChanged(object sender, System.EventArgs e)
            {
 
 
            ComboBox tableau = (ComboBox)sender;
                //methode pour colorer ...
 
                if (tableau.SelectedIndex == 1)
                {
                    tableau.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
                }
                if (tableau.SelectedIndex == 2)
                {
                    tableau.BackColor = System.Drawing.Color.Yellow;
                }
                if (tableau.SelectedIndex == 3)
                {
                    tableau.BackColor = System.Drawing.Color.Red;
                }
             }
            public void local_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                ComboBox local = (ComboBox)sender;
                //methode pour colorer ...
 
                //if (local.SelectedIndex != 0)
                //{
                    local.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
 
                //}
            local.SelectedItem = local.SelectedItem.ToString();
            //MessageBox.Show(local.SelectedItem.ToString());
        }
            public void visiteur_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                ComboBox visiteur = (ComboBox)sender;
                //methode pour colorer ...
 
                if (visiteur.SelectedIndex != 0)
                {
                    visiteur.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
 
                }
            //MessageBox.Show(visiteur.SelectedItem.ToString());
        }
 
 
 
        public void button1_Click(object sender, EventArgs e)
        {
 
            //connection a sqlite, creation de la base de données unibet, connection a unibet
            // CAS N1
            //string connectionString = @"Data Source=C:\Users\cyril\source\repos\unibet3\unibet.db";
 
            // CAS N2
            string unibet = @"Data Source=unibet.db";
            using (var conn = new SqliteConnection(unibet))
            {
                conn.Open();
                //creation et ou ajout de table + execution
 
                SqliteCommand cmd = new SqliteCommand("create table if not exists grille (dateid  DateTime  , nbmatch, nbpari, local, visiteur, [0], [1], [2],[3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14])", conn);
                cmd.ExecuteNonQuery();
 
 
                //initialisation de la variable date                
                DateTime ladate = DateTime.Now;
                string date = ladate.ToString("dddddddd, dd MMMM yyyy HH: mm:ss");
 
                //mise en forme du texte pour insertion dans la base de données sqlite
                //initialisation du texte via une bouclee pour affecter les valeurs passées en parametre  
                var txt1 = "";
                var text1 = "";
                var txt2 = "";
                var text2 = "";
                int b = 0;
 
                for (int j = 0; j < Form1.paris; j++)
                {
                    txt1 = ("@" + j + ",");
                    txt2 = ("[" + j + "],");
                    text1 = text1 + txt1;
                    text2 = text2 + txt2;
                }
                text1 = text1.Substring(0, text1.Length - 1); // on enlevela derniere virgule
                text1 = text1 + ")"; // on ajoute la fin de parenthese
                text2 = text2.Substring(0, text2.Length - 1);  // on enlevela derniere virgule
 
                //insertion dans la base de données sqlite
                var texte1 = "insert into grille (dateid,nbmatch,nbpari,local,visiteur,";
                var texte2 = ") VALUES (@dateid,@nbmatch,@nbpari,@local,@visiteur,";
                string insertTableValue = texte1 += text2 += texte2 += text1;
 
 
                for (int a = 0; a < Form1.matchs; a++)
                {
                    var command = new SqliteCommand(insertTableValue, conn);
 
                    command.Parameters.AddWithValue("@dateid", date);
                    command.Parameters.AddWithValue("@nbmatch", Form1.matchs);
                    command.Parameters.AddWithValue("@nbpari", Form1.paris);
                    command.Parameters.AddWithValue("@local", combox.ComboL[a].SelectedItem.ToString());
                    command.Parameters.AddWithValue("@visiteur", combox.ComboV[a].SelectedItem.ToString());
 
                    int i = 0;
 
                    for (b = b; b < Form1.paris + (a * Form1.paris); b++)
                    {
                        command.Parameters.AddWithValue("@" + i, combox.ComboT[b].SelectedItem.ToString());
                        i++;
                    }
 
                    command.ExecuteNonQuery();
                }
 
                     conn.Open();
                     SqliteCommand command2 = new SqliteCommand("SELECT dateid, nbmatch,nbpari FROM grille order by rowid desc limit 1", conn);
 
                     using (var reader = command2.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             string taDate = $"{reader["dateid"]}";
                             string nbmatch = $"{reader["nbmatch"]}";
                             string nbpari = $"{reader["nbpari"]}";
 
 
                             MessageBox.Show("grille du : " + taDate + "  " + " nombre de match : " + nbmatch + "  " + "nombre de grille : " + nbpari + "  " + "enregistrée");
 
                         }
                     }
                     command2.ExecuteNonQuery();
 
            }
        }  
 
    }
 
 
}
voilà voilà .... au secours ...