public VoirCompet() { InitializeComponent(); string fichierCompet_individuel = "compet_individuel.txt"; string[] mots; List <Competition_simple> liste_c_i = new List <Competition_simple>(); string[] lignes = File.ReadAllLines(fichierCompet_individuel); for (int i = 0; i < lignes.Length; i++) //Un retour a la ligne est créé tous le temps donc -1 pour pas sortir de la boucle apres { string ligne_num = lignes[i]; mots = ligne_num.Split(','); Competition_simple compet_indiv = new Competition_simple(); compet_indiv.Nom = mots[1]; compet_indiv.Lieu = mots[0]; compet_indiv.Nb_j_min = int.Parse(mots[2]); compet_indiv.Classement_max = double.Parse(mots[3]); String list_eq = mots[4]; String[] j_eq = list_eq.Split('/'); List <Joueur_competition> list_j = new List <Joueur_competition>(); for (int j = 0; j < j_eq.Length; j++) { Joueur_competition joueur_c = new Joueur_competition(j_eq[j]); list_j.Add(joueur_c); } compet_indiv.Liste_equipe = list_j; compet_indiv.Nb_jours = int.Parse(mots[5]); compet_indiv.Nb_match = int.Parse(mots[6]); String cat = mots[7]; String[] cat_l = cat.Split('/'); compet_indiv.Annee_min = int.Parse(cat_l[0]); compet_indiv.Annee_max = int.Parse(cat_l[1]); String[] date = mots[8].Split('/'); int d_j = int.Parse(date[0]); int d_m = int.Parse(date[1]); int d_a = int.Parse(date[2]); compet_indiv.Date = new DateTime(d_a, d_m, d_j); liste_c_i.Add(compet_indiv); } string affichage = ""; liste_c_i.ForEach(x => affichage += x.ToString() + "\n"); //Utilisation de delegate avec le Foreach lise.Text = affichage; }
private List <Competition_simple> CompetSimple() { string fichierCompet_individuel = "compet_individuel.txt"; string[] mots; List <Competition_simple> liste_c_i = new List <Competition_simple>(); string[] lignes = File.ReadAllLines(fichierCompet_individuel); for (int i = 0; i < lignes.Length; i++) //Un retour a la ligne est créé tous le temps donc -1 pour pas sortir de la boucle apres { string ligne_num = lignes[i]; mots = ligne_num.Split(','); Competition_simple compet_indiv = new Competition_simple(); compet_indiv.Nom = mots[1]; compet_indiv.Lieu = mots[0]; compet_indiv.Nb_j_min = int.Parse(mots[2]); compet_indiv.Classement_max = double.Parse(mots[3]); String list_eq = mots[4]; String[] j_eq = list_eq.Split('/'); List <Joueur_competition> list_j = new List <Joueur_competition>(); for (int j = 0; j < j_eq.Length; j++) { Joueur_competition joueur_c = new Joueur_competition(j_eq[j]); list_j.Add(joueur_c); } compet_indiv.Liste_equipe = list_j; compet_indiv.Nb_jours = int.Parse(mots[5]); compet_indiv.Nb_match = int.Parse(mots[6]); String cat = mots[7]; String[] cat_l = cat.Split('/'); compet_indiv.Annee_min = int.Parse(cat_l[0]); compet_indiv.Annee_max = int.Parse(cat_l[1]); String[] date = mots[8].Split('/'); int d_j = int.Parse(date[0]); int d_m = int.Parse(date[1]); int d_a = int.Parse(date[2]); compet_indiv.Date = new DateTime(d_a, d_m, d_j); liste_c_i.Add(compet_indiv); } return(liste_c_i); }
private void Button_Click(object sender, RoutedEventArgs e) { string fichier_compet_simple = "compet_individuel.txt"; StreamWriter lire = null; string l = lieu.Text; string n = nom_compet.Text; int min = int.Parse(nbre_min_joueur.Text); int max = int.Parse(classement_max.Text); string participant = liste_participant_equipe1.Text; string adversaire = liste_participant_equipe2.Text; int jour = int.Parse(nbre_jour.Text); int match = int.Parse(nbre_match.Text); int anne_min = int.Parse(annee_min.Text); int anne_max = int.Parse(annee_max.Text); int jou = int.Parse(jourr.Text); int moi = int.Parse(moiss.Text); int ann = int.Parse(anneee.Text); DateTime date = new DateTime(ann, moi, jou); List <Joueur_competition> list = new List <Joueur_competition>(); string[] list_j = participant.Split('/'); string[] list_ad = adversaire.Split('/'); List <Joueur_competition> list_j_c = Liste_joueur_compet(); List <Joueur_competition> list_adv = new List <Joueur_competition>(); foreach (string nom in list_j) { foreach (Joueur_competition j in list_j_c) { if (nom == j.Nom) { list.Add(j); } } } foreach (string name in list_ad) { Joueur_competition joueur = new Joueur_competition(name); list_adv.Add(joueur); } Equipe_competition eq = new Equipe_competition(list_adv); Competition_simple compet_s = new Competition_simple(match, l, list, jour, n, max, min, anne_min, anne_max, date); lire = new StreamWriter(fichier_compet_simple, true); if (compet_s.Assez_de_joueur()) { compet_s.Creation_List_Match(eq); compet_s.Compatibilite_age(); } //On verifie que les joueurs peuvent bien jouer et doncc on creer la nouvelle liste des joueurs string affichage = ""; foreach (Joueur_competition j in compet_s.Liste_joueur_ok) { affichage += (j.Nom + "/"); } lire.Write("\n" + l + "," + n + "," + min + "," + max + "," + affichage + "," + jour + "," + match + "," + anne_min + "/" + anne_max + "," + jou + "/" + moi + "/" + ann); lire.Close(); Ca_marche a = new Ca_marche(); a.Show(); this.Close(); }