Statistiques
| Branche: | Révision:

rfid-cb / CodeBarreRFID / DAO / AnimalDAO.cs @ 0f2b4298

Historique | Voir | Annoter | Télécharger (1,452 ko)

1 0f2b4298 ajournaux
using CodeBarreRFID.Model;
2
using CommunityToolkit.Maui.Storage;
3
using Microsoft.Maui.Storage;
4
using System;
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Linq;
8
using System.Security.AccessControl;
9
using System.Text;
10
using System.Threading.Tasks;
11
12
namespace CodeBarreRFID.DAO
13
{
14
    public static class AnimalDAO
15
    {
16
        public static List<Animal> ANIMAUX;
17
        private static string repertoireSav = "/storage/emulated/0/Documents/";
18
        private static string fichierSav = repertoireSav+"animaux.csv";
19
20
        public static void SaveToCSV()
21
        {
22
            if (!Directory.Exists(repertoireSav)) Directory.CreateDirectory(repertoireSav);
23
24
            List<string> lignes = new List<string>();
25
            foreach (Animal item in ANIMAUX)
26
            {
27
                String ligne = item.RFID + ";" + item.CodeBarre;
28
                lignes.Add(ligne);
29
            }
30
31
            File.WriteAllLines(fichierSav, lignes.ToArray());
32
        }
33
34
        public static void LoadFromCSV()
35
        {
36
            Permissions.RequestAsync<Permissions.StorageRead>();
37
            Permissions.RequestAsync<Permissions.StorageWrite>();
38
39
            if (File.Exists(fichierSav))
40
            {
41
                ANIMAUX = File.ReadAllLines(fichierSav).Select(csv => new Animal(csv)).ToList();
42
            }else
43
            {
44
                ANIMAUX = new List<Animal>();
45
            }
46
        }
47
48
    }
49
50
}