root / GES_PAC / Model / Journee.cs @ 6f451cc1
Historique | Voir | Annoter | Télécharger (3,058 ko)
1 |
using SQLite; |
---|---|
2 |
using System.ComponentModel.DataAnnotations.Schema; |
3 |
|
4 |
namespace GES_PAC.Model |
5 |
{ |
6 |
public class Journee |
7 |
{ |
8 |
#region Propriétés |
9 |
[PrimaryKey, AutoIncrement] |
10 |
public int Id { get; set; } |
11 |
public int PersonneId { get; set; } |
12 |
[ForeignKey("PersonneId")] |
13 |
public Personne Responsable { get; set; } |
14 |
public int LieuId { get; set; } |
15 |
[ForeignKey("LieuId")] |
16 |
public Lieu Lieu { get; set; } |
17 |
public DateTime Date { get; set; } |
18 |
public string Regime { get; set; } |
19 |
public List<Serie> Series { get; set; } = []; |
20 |
public List<Calibration> Calibrations { get; set; } = []; |
21 |
#endregion |
22 |
|
23 |
#region Constructeurs |
24 |
public Journee(){} |
25 |
public Journee(DateTime Date, Personne Responsable, Lieu Lieu, string Regime) |
26 |
{ |
27 |
this.Responsable = Responsable; |
28 |
this.Lieu = Lieu; |
29 |
this.Date = Date; |
30 |
this.Regime = Regime; |
31 |
Series = []; |
32 |
Calibrations = []; |
33 |
} |
34 |
#endregion |
35 |
|
36 |
#region Méthodes |
37 |
|
38 |
public void AddSet(Serie set) |
39 |
{ |
40 |
set.Journee = this; |
41 |
Series.Add(set); |
42 |
} |
43 |
public List<TypeCalibration> GetMissingCalibrationByPhase(PhaseCalibration phase) |
44 |
{ |
45 |
if (phase == null) |
46 |
return TypeCalibration.All; |
47 |
|
48 |
var calibPhase = Calibrations.FirstOrDefault(c => c.Phase == phase); |
49 |
|
50 |
if (calibPhase == null || calibPhase.IsComplete()) |
51 |
return TypeCalibration.All; |
52 |
|
53 |
return TypeCalibration.All.Except(calibPhase.GetTypesDone()).ToList(); |
54 |
} |
55 |
|
56 |
|
57 |
public Serie? GetCurrentSet() |
58 |
{ |
59 |
return Series?.LastOrDefault(); |
60 |
} |
61 |
public bool HasAnySet() |
62 |
{ |
63 |
return Series.Count > 0; |
64 |
} |
65 |
internal int GetSetCount() |
66 |
{ |
67 |
return Series.Count; |
68 |
} |
69 |
internal int GetDayAnimalCount() |
70 |
{ |
71 |
return Series.Sum(s => s.GetAnimalCount()); |
72 |
} |
73 |
|
74 |
internal int GetDayMeasureCount() |
75 |
{ |
76 |
return Series.Sum(s => s.GetMeasureCount()); |
77 |
} |
78 |
|
79 |
internal int GetDayBehaviourCount() |
80 |
{ |
81 |
return Series.Sum(s => s.GetBehaviourCount()); |
82 |
} |
83 |
internal Calibration GetLastCalibration() |
84 |
{ |
85 |
return Calibrations.Last(); |
86 |
} |
87 |
internal Calibration GetDebutCalibration() |
88 |
{ |
89 |
return Calibrations.FirstOrDefault(c => c.Phase?.Value == PhaseCalibration.DEBUT.Value); |
90 |
} |
91 |
internal bool IsCalibrationComplete(PhaseCalibration pc) |
92 |
{ |
93 |
return Calibrations?.FirstOrDefault(c => c.Phase == pc)?.IsComplete() ?? false; |
94 |
} |
95 |
internal bool IsComplete() |
96 |
{ |
97 |
return Calibrations?.FirstOrDefault(c => c.Phase == PhaseCalibration.FIN)?.IsComplete() ?? false; |
98 |
} |
99 |
|
100 |
internal void AddCalibration(Calibration calibration) |
101 |
{ |
102 |
calibration.Journee = this; |
103 |
Calibrations.Add(calibration); |
104 |
} |
105 |
#endregion |
106 |
} |
107 |
} |