-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAL.cs
56 lines (46 loc) · 1.34 KB
/
DAL.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Debogage
{
[Flags] internal enum Statuts { Aucun = 0, Etranger = 1, Boursier = 2, Admis = 4 }
internal static class DAL
{
public static readonly int NbAdmis = 50;
private static readonly string NOM_FICHIER = "Etudiants.csv";
/// <summary>
/// Charge le fichier des étudiants dans une liste et renvoie cette liste
/// </summary>
/// <returns>Liste d'étudiants</returns>
public static List<Etudiant> ChargerDonnées()
{
List<Etudiant> étudiants;
string[] lignes = File.ReadAllLines(NOM_FICHIER);
for (int l = 0; l < lignes.Length; l++)
{
string[] infos = lignes[l].Split(';');
Statuts st = Statuts.Aucun;
if (infos[2] == "O") st |= Statuts.Etranger;
if (infos[3] == "O") st |= Statuts.Boursier;
if (l <= NbAdmis) st |= Statuts.Admis;
Etudiant e = new() {
Nom = infos[0],
Prénom = infos[1],
Moyenne = double.Parse(infos[2]),
Statut = st
};
étudiants.Add(e);
}
return étudiants;
}
}
internal class Etudiant
{
public required string Nom { get; init; }
public required string Prénom { get; init; }
public double Moyenne { get; set; }
public Statuts Statut { get; set; }
}
}