Advertisement
Guest User

Persistence.cs

a guest
Mar 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 26.82 KB | None | 0 0
  1. using System.IO;
  2. using System.Linq;
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System;
  7.  
  8. [System.Serializable]
  9. public class Enfant
  10. {
  11.     public Enfant()
  12.     {
  13.         EvaluationsApp1 = new List<EvaluationApp1>();
  14.         EvaluationsApp2 = new List<EvaluationApp2>();
  15.         EvaluationsApp3 = new List<EvaluationApp3>();
  16.         EvaluationsApp4 = new List<EvaluationApp4>();
  17.     }
  18.  
  19.     public int EnfantID;
  20.  
  21.     public string NumeroDossier;
  22.     public string Nom;
  23.     public string Prenom;
  24.     public string Genre;
  25.     public string DateDeNaissance;
  26.     public string ct1;
  27.     public string ct2;
  28.     public string NiveauScolaire;
  29.     public string MoyenneAnneePrecedente;
  30.     public string NivSocioEco;
  31.     public string DiagnostiqueDSMV;
  32.     public string CPM;
  33.     public string TestComprehension;
  34.     public string TestDeFluenceVerbaleSemantique;
  35.     public string NomReferant;
  36.     public string PrenomReferant;
  37.     public string StatusReferant;
  38.     public string situationMatrimoniale;
  39.     public string NombreEnfants;
  40.     public string MaladieAuLongCours;
  41.     public string AntecedentsPsychiatriques;
  42.  
  43.     public List<EvaluationApp1> EvaluationsApp1;
  44.     public List<EvaluationApp2> EvaluationsApp2;
  45.     public List<EvaluationApp3> EvaluationsApp3;
  46.     public List<EvaluationApp4> EvaluationsApp4;
  47. }
  48.  
  49. [System.Serializable]
  50. public class EvaluationApp1
  51. {
  52.     public EvaluationApp1()
  53.     {
  54.         Sessions = new List<Session>();
  55.     }
  56.  
  57.     public string EvaluationID;
  58.     public List<Session> Sessions;
  59.  
  60.     public int GetGlobalScore()
  61.     {
  62.         int result = 0;
  63.  
  64.         foreach (var session in Sessions)
  65.         {
  66.             result += session.ScoreSession;
  67.         }
  68.  
  69.         return result;
  70.     }
  71. }
  72.  
  73. [System.Serializable]
  74. public class EvaluationApp2
  75. {
  76.     public string EvaluationID;
  77.  
  78.     public int Score;
  79.     public int Duree;
  80.     public string NomExaminateur;
  81.     public string DateExamination;
  82.     public string LieuExamination;
  83.  
  84.     public List<TagApp2> Tags = new List<TagApp2>() {
  85.         new TagApp2 () { ID = TagID2.EmpathieAffective, Label = "Empathie Affective", Value = 0 },
  86.         new TagApp2 () { ID = TagID2.EmpathieCognitive, Label = "Empathie Cognitive", Value = 0 },
  87.         new TagApp2 () { ID = TagID2.EmpathieSomatique, Label = "Empathie Somatique", Value = 0 },
  88.         new TagApp2 () { ID = TagID2.ComporetementsEmpathiques, Label = "Comporetements Empathiques", Value = 0 }
  89.     };
  90. }
  91.  
  92. [System.Serializable]
  93. public class EvaluationApp3
  94. {
  95.     public string EvaluationID;
  96.  
  97.     public int Score;
  98.  
  99.     public int NonReponse;
  100.  
  101.     public int Duree;
  102.  
  103.     public int DureeMoyenne;
  104.  
  105.     public bool isVideo;
  106.  
  107.     public string nomExaimnateur;
  108.  
  109.     public string LieuExamination;
  110.  
  111.     public string DateExamination;
  112.  
  113.     public List<TagApp3> Tags = new List<TagApp3>() {
  114.         new TagApp3 () { EmotionID = EmotionTagID.Colère, Label = "Colère", Value = 0, Correct = 0 },
  115.         new TagApp3 () { EmotionID = EmotionTagID.Dégoût, Label = "Dégoût", Value = 0, Correct = 0 },
  116.         new TagApp3 () { EmotionID = EmotionTagID.Joie, Label = "Joie", Value = 0, Correct = 0 },
  117.         new TagApp3 () { EmotionID = EmotionTagID.Peur, Label = "Peur", Value = 0, Correct = 0 },
  118.          new TagApp3 () { EmotionID = EmotionTagID.Surprise, Label = "Surprise", Value = 0, Correct = 0 },
  119.         new TagApp3 () { EmotionID = EmotionTagID.Tristesse, Label = "Tristesse", Value = 0, Correct = 0 },
  120.         new TagApp3 () { EmotionID = EmotionTagID.Neutre, Label = "Neutre", Value = 0, Correct = 0 },
  121.         new TagApp3 () { GenderID = GenderTagID.Masculin, Label = "Masculin", Value = 0, Correct = 0 },
  122.         new TagApp3 () { GenderID = GenderTagID.Féminin, Label = "Féminin", Value = 0, Correct = 0 },
  123.         new TagApp3 () { AgeTagID = AgeTagID.Adolescent, Label = "Adolescent", Value = 0, Correct = 0 },
  124.         new TagApp3 () { AgeTagID = AgeTagID.Enfant, Label = "Enfant", Value = 0, Correct = 0 },
  125.          new TagApp3 () { AgeTagID = AgeTagID.Adulte, Label = "Adulte", Value = 0, Correct = 0 },
  126.         new TagApp3 () { IntensityTagId = IntensityId.Faible, Label = "Faible", Value = 0, Correct = 0 },
  127.         new TagApp3 () { IntensityTagId = IntensityId.Moyenne, Label = "Moyenne", Value = 0, Correct = 0 },
  128.         new TagApp3 () { IntensityTagId = IntensityId.Forte, Label = "Forte", Value = 0, Correct = 0 }
  129.     };
  130. }
  131.  
  132. [System.Serializable]
  133. public class EvaluationApp4
  134. {
  135.     public string EvaluationID;
  136.  
  137.     public int Score;
  138.  
  139.     public int Duree;
  140.  
  141.     public int DureeMoyenne;
  142.  
  143.     public string nomExaimnateur;
  144.  
  145.     public string LieuExamination;
  146.  
  147.     public string DateExamination;
  148.  
  149.     public List<TagApp4> Tags2 = new List<TagApp4>() {
  150.         new TagApp4 () { logicID = LogicTagId.attributionEmpathique, Label = "attributionEmpathique", Value = 0, Correct = 0 },
  151.         new TagApp4 () { logicID = LogicTagId.EMaffectif, Label = "EMaffectif", Value = 0, Correct = 0 },
  152.         new TagApp4 () { logicID = LogicTagId.EMcognitif, Label = "EMcognitif", Value = 0, Correct = 0 },
  153.          new TagApp4 () { logicID = LogicTagId.comportementales, Label = "comportementales", Value = 0, Correct = 0 },
  154.         new TagApp4 () { logicID = LogicTagId.intentionelle, Label = "intentionelle", Value = 0, Correct = 0 },
  155.         new TagApp4 () { logicID = LogicTagId.logiquePhysique, Label = "logiquePhysique", Value = 0, Correct = 0 },
  156.     };
  157. }
  158.  
  159. [System.Serializable]
  160. public class Session
  161. {
  162.     public Session()
  163.     {
  164.         SituationsDone = new List<int>();
  165.     }
  166.  
  167.     public string SessionID;
  168.  
  169.     public string NomExaminateur;
  170.     public string DateExamination;
  171.     public string LieuExamination;
  172.  
  173.     public int ScoreSession;
  174.     public int Duree;
  175.  
  176.     public bool Synced;
  177.  
  178.     public List<TagApp1> Tags = new List<TagApp1>() {
  179.         new TagApp1 () { ID = TagID.Epistémique, Label = "Epistémique", Value = 0 },
  180.         new TagApp1 () { ID = TagID.EpistémiqueNiveau2, Label = "Epistémique Niveau 2", Value = 0 },
  181.         new TagApp1 () { ID = TagID.Affectif, Label = "Affectif", Value = 0 },
  182.         new TagApp1 () { ID = TagID.Intention, Label = "Intention", Value = 0 },
  183.         new TagApp1 () { ID = TagID.MaladresseSociale, Label = "Maladresse Sociale", Value = 0 },
  184.         new TagApp1 () { ID = TagID.CompréhensionSimple, Label = "Compréhension Simple", Value = 0 },
  185.         new TagApp1 () { ID = TagID.Contrôle, Label = "Contrôle", Value = 0 }
  186.     };
  187.  
  188.     // List of stories which are done in this session
  189.     public List<int> SituationsDone;
  190. }
  191.  
  192. [System.Serializable]
  193. public class DB
  194. {
  195.     public DB()
  196.     {
  197.         Enfants = new List<Enfant>();
  198.     }
  199.  
  200.     public List<Enfant> Enfants;
  201. }
  202.  
  203. public static class Persistence
  204. {
  205.     #if UNITY_EDITOR
  206.     public static string DataPath = Application.persistentDataPath + "/sessions.data";
  207.     #else
  208.     public static string DataPath = "/storage/sdcard0/Android/data/com.nextgen.therapieform/files/sessions.data";
  209.     #endif
  210.  
  211.     public static DB ReadDB()
  212.     {
  213.         BinaryFormatter bf = new BinaryFormatter();
  214.  
  215.         FileStream readFileStream = new FileStream(DataPath, FileMode.OpenOrCreate, FileAccess.Read);
  216.  
  217.         DB db;
  218.  
  219.         if (readFileStream.Length == 0)
  220.         {
  221.             db = new DB();
  222.         }
  223.         else
  224.         {
  225.             db = (DB)bf.Deserialize(readFileStream);
  226.         }
  227.  
  228.         readFileStream.Close();
  229.  
  230.         return db;
  231.     }
  232.  
  233.     public static void WriteDB(DB db)
  234.     {
  235.         BinaryFormatter bf = new BinaryFormatter();
  236.         FileStream writeFileStream = new FileStream(DataPath, FileMode.OpenOrCreate, FileAccess.Write);
  237.         bf.Serialize(writeFileStream, db);
  238.         writeFileStream.Close();
  239.     }
  240.  
  241.     public static List<Enfant> GetAllEnfants()
  242.     {
  243.         return ReadDB().Enfants;
  244.     }
  245.  
  246.     public static Enfant GetEnfantByID(int id)
  247.     {
  248.         return ReadDB().Enfants.First(enf => enf.EnfantID == id);
  249.     }
  250.  
  251.     public static Enfant GetEnfantByNumDossier(string numDossier)
  252.     {
  253.         return ReadDB().Enfants.FirstOrDefault(enfant => enfant.NumeroDossier == numDossier);
  254.     }
  255.  
  256.     public static List<EvaluationApp3> GetEvaluationsApp3ByEnfantID(int EnfantID)
  257.     {
  258.         return ReadDB().Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp3;
  259.     }
  260.  
  261.     public static List<EvaluationApp4> GetEvaluationsApp4ByEnfantID(int EnfantID)
  262.     {
  263.         return ReadDB().Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp4;
  264.     }
  265.  
  266.     public static List<EvaluationApp2> GetEvaluationsApp2ByEnfantID(int EnfantID)
  267.     {
  268.         return ReadDB().Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp2;
  269.     }
  270.  
  271.  
  272.     public static string TimeStampID()
  273.     {
  274.         return (Int32)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds + "";
  275.     }
  276.  
  277.  
  278.     public static void AddEvaluationApp3ForEnfant(int EnfantID, int score, int duree, int dureeMoyenne, int nonReponses, bool isVideo, int[] tags, int[] tagsCorrect)
  279.     {
  280.         DB db = ReadDB();
  281.  
  282.         EvaluationApp3 eval = new EvaluationApp3();
  283.  
  284.         eval.EvaluationID = TimeStampID();
  285.  
  286.         eval.Score = score;
  287.  
  288.         eval.Duree = duree;
  289.  
  290.         eval.NonReponse = nonReponses;
  291.  
  292.         eval.DureeMoyenne = dureeMoyenne;
  293.  
  294.         eval.isVideo = isVideo;
  295.  
  296.         eval.Tags[0].Value = tags[0];
  297.         eval.Tags[1].Value = tags[1];
  298.         eval.Tags[2].Value = tags[2];
  299.         eval.Tags[3].Value = tags[3];
  300.         eval.Tags[4].Value = tags[4];
  301.         eval.Tags[5].Value = tags[5];
  302.         eval.Tags[6].Value = tags[6];
  303.         eval.Tags[7].Value = tags[7];
  304.         eval.Tags[8].Value = tags[8];
  305.         eval.Tags[9].Value = tags[9];
  306.         eval.Tags[10].Value = tags[10];
  307.         eval.Tags[11].Value = tags[11];
  308.         eval.Tags[12].Value = tags[12];
  309.         eval.Tags[13].Value = tags[13];
  310.         eval.Tags[14].Value = tags[14];
  311.  
  312.         eval.Tags[0].Correct = tagsCorrect[0];
  313.         eval.Tags[1].Correct = tagsCorrect[1];
  314.         eval.Tags[2].Correct = tagsCorrect[2];
  315.         eval.Tags[3].Correct = tagsCorrect[3];
  316.         eval.Tags[4].Correct = tagsCorrect[4];
  317.         eval.Tags[5].Correct = tagsCorrect[5];
  318.         eval.Tags[6].Correct = tagsCorrect[6];
  319.         eval.Tags[7].Correct = tagsCorrect[7];
  320.         eval.Tags[8].Correct = tagsCorrect[8];
  321.         eval.Tags[9].Correct = tagsCorrect[9];
  322.         eval.Tags[10].Correct = tagsCorrect[10];
  323.         eval.Tags[11].Correct = tagsCorrect[11];
  324.         eval.Tags[12].Correct = tagsCorrect[12];
  325.         eval.Tags[13].Correct = tagsCorrect[13];
  326.         eval.Tags[14].Correct = tagsCorrect[14];
  327.  
  328.  
  329.         db.Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp3.Add(eval);
  330.  
  331.         WriteDB(db);
  332.     }
  333.  
  334.     public static void AddEvaluationApp4ForEnfant(int EnfantID, int score, int duree, int dureeMoyenne, int[] tags, int[] tagsCorrect)
  335.     {
  336.         DB db = ReadDB();
  337.  
  338.         EvaluationApp4 eval = new EvaluationApp4();
  339.  
  340.         eval.EvaluationID = TimeStampID();
  341.  
  342.         eval.Score = score;
  343.  
  344.         eval.Duree = duree;
  345.  
  346.         eval.DureeMoyenne = dureeMoyenne;
  347.  
  348.         eval.Tags2[0].Value = tags[0];
  349.         eval.Tags2[1].Value = tags[1];
  350.         eval.Tags2[2].Value = tags[2];
  351.         eval.Tags2[3].Value = tags[3];
  352.         eval.Tags2[4].Value = tags[4];
  353.         eval.Tags2[5].Value = tags[5];
  354.  
  355.         eval.Tags2[0].Correct = tagsCorrect[0];
  356.         eval.Tags2[1].Correct = tagsCorrect[1];
  357.         eval.Tags2[2].Correct = tagsCorrect[2];
  358.         eval.Tags2[3].Correct = tagsCorrect[3];
  359.         eval.Tags2[4].Correct = tagsCorrect[4];
  360.         eval.Tags2[5].Correct = tagsCorrect[5];
  361.  
  362.  
  363.         db.Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp4.Add(eval);
  364.  
  365.         WriteDB(db);
  366.     }
  367.  
  368.     public static void AddEvaluationApp2ForEnfant(int EnfantID, int score, int duree, params int[] tags)
  369.     {
  370.         DB db = ReadDB();
  371.  
  372.         EvaluationApp2 eval = new EvaluationApp2();
  373.  
  374.         eval.EvaluationID = TimeStampID();
  375.  
  376.         eval.Score = score;
  377.  
  378.         eval.Duree = duree;
  379.  
  380.         eval.Tags[0].Value = tags[0];
  381.         eval.Tags[1].Value = tags[1];
  382.         eval.Tags[2].Value = tags[2];
  383.         eval.Tags[3].Value = tags[3];
  384.  
  385.         db.Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp2.Add(eval);
  386.  
  387.         WriteDB(db);
  388.     }
  389.  
  390.     public static void UpdateEvaluationApp3WithScoreAndDurationAndTags(int EnfantID, string EvaluationID, int score, int duree, int dureeMoyenne, int nonReponses, bool isVideo, int[] tags, int[] tagsCorrect)
  391.     {
  392.         DB db = ReadDB();
  393.  
  394.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  395.  
  396.         EvaluationApp3 evaluation = enfant.EvaluationsApp3.First(eval => eval.EvaluationID == EvaluationID);
  397.  
  398.         evaluation.Score = score;
  399.  
  400.         evaluation.Duree = duree;
  401.  
  402.         evaluation.NonReponse = nonReponses;
  403.  
  404.         evaluation.DureeMoyenne = dureeMoyenne;
  405.  
  406.         evaluation.isVideo = isVideo;
  407.  
  408.         evaluation.Tags[0].Value = tags[0];
  409.         evaluation.Tags[1].Value = tags[1];
  410.         evaluation.Tags[2].Value = tags[2];
  411.         evaluation.Tags[3].Value = tags[3];
  412.         evaluation.Tags[4].Value = tags[4];
  413.         evaluation.Tags[5].Value = tags[5];
  414.         evaluation.Tags[6].Value = tags[6];
  415.         evaluation.Tags[7].Value = tags[7];
  416.         evaluation.Tags[8].Value = tags[8];
  417.         evaluation.Tags[9].Value = tags[9];
  418.         evaluation.Tags[10].Value = tags[10];
  419.         evaluation.Tags[11].Value = tags[11];
  420.         evaluation.Tags[12].Value = tags[12];
  421.         evaluation.Tags[13].Value = tags[13];
  422.         evaluation.Tags[14].Value = tags[14];
  423.  
  424.         evaluation.Tags[0].Correct = tagsCorrect[0];
  425.         evaluation.Tags[1].Correct = tagsCorrect[1];
  426.         evaluation.Tags[2].Correct = tagsCorrect[2];
  427.         evaluation.Tags[3].Correct = tagsCorrect[3];
  428.         evaluation.Tags[4].Correct = tagsCorrect[4];
  429.         evaluation.Tags[5].Correct = tagsCorrect[5];
  430.         evaluation.Tags[6].Correct = tagsCorrect[6];
  431.         evaluation.Tags[7].Correct = tagsCorrect[7];
  432.         evaluation.Tags[8].Correct = tagsCorrect[8];
  433.         evaluation.Tags[9].Correct = tagsCorrect[9];
  434.         evaluation.Tags[10].Correct = tagsCorrect[10];
  435.         evaluation.Tags[11].Correct = tagsCorrect[11];
  436.         evaluation.Tags[12].Correct = tagsCorrect[12];
  437.         evaluation.Tags[13].Correct = tagsCorrect[13];
  438.         evaluation.Tags[14].Correct = tagsCorrect[14];
  439.  
  440.         WriteDB(db);
  441.     }
  442.  
  443.     public static void UpdateEvaluationApp4WithScoreAndDurationAndTags(int EnfantID, string EvaluationID, int score, int duree, int dureeMoyenne, int[] tags, int[] tagsCorrect)
  444.     {
  445.         DB db = ReadDB();
  446.  
  447.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  448.  
  449.         EvaluationApp4 evaluation = enfant.EvaluationsApp4.First(eval => eval.EvaluationID == EvaluationID);
  450.  
  451.         evaluation.Score = score;
  452.  
  453.         evaluation.Duree = duree;
  454.  
  455.         evaluation.DureeMoyenne = dureeMoyenne;
  456.  
  457.         evaluation.Tags2[0].Value = tags[0];
  458.         evaluation.Tags2[1].Value = tags[1];
  459.         evaluation.Tags2[2].Value = tags[2];
  460.         evaluation.Tags2[3].Value = tags[3];
  461.         evaluation.Tags2[4].Value = tags[4];
  462.         evaluation.Tags2[5].Value = tags[5];
  463.  
  464.         evaluation.Tags2[0].Correct = tagsCorrect[0];
  465.         evaluation.Tags2[1].Correct = tagsCorrect[1];
  466.         evaluation.Tags2[2].Correct = tagsCorrect[2];
  467.         evaluation.Tags2[3].Correct = tagsCorrect[3];
  468.         evaluation.Tags2[4].Correct = tagsCorrect[4];
  469.         evaluation.Tags2[5].Correct = tagsCorrect[5];
  470.  
  471.         WriteDB(db);
  472.     }
  473.  
  474.     public static void UpdateEvaluationApp2WithScoreAndDurationAndTags(int EnfantID, string EvaluationID, int Score, int Duration, params int[] tags)
  475.     {
  476.         DB db = ReadDB();
  477.  
  478.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  479.  
  480.         EvaluationApp2 evaluation = enfant.EvaluationsApp2.First(eval => eval.EvaluationID == EvaluationID);
  481.  
  482.         evaluation.Score = Score;
  483.         evaluation.Duree = Duration;
  484.  
  485.         for (int i = 0; i < tags.Length; i++)
  486.         {
  487.             evaluation.Tags[i].Value += tags[i];
  488.         }
  489.  
  490.         WriteDB(db);
  491.     }
  492.  
  493.     public static List<EvaluationApp3> GetAllEvaluationApp3ForEnfant(int ID)
  494.     {
  495.         if (ReadDB().Enfants.Any((Enfant arg1) => arg1.EnfantID == ID))
  496.         {
  497.             return ReadDB().Enfants.First(el => el.EnfantID == ID).EvaluationsApp3;
  498.         }
  499.         else
  500.         {
  501.             return new List<EvaluationApp3>();
  502.         }
  503.     }
  504.  
  505.     public static List<EvaluationApp4> GetAllEvaluationApp4ForEnfant(int ID)
  506.     {
  507.         if (ReadDB().Enfants.Any((Enfant arg1) => arg1.EnfantID == ID))
  508.         {
  509.             return ReadDB().Enfants.First(el => el.EnfantID == ID).EvaluationsApp4;
  510.         }
  511.         else
  512.         {
  513.             return new List<EvaluationApp4>();
  514.         }
  515.     }
  516.  
  517.     public static List<EvaluationApp2> GetAllEvaluationApp2ForEnfant(int ID)
  518.     {
  519.         if (ReadDB().Enfants.Any((Enfant arg1) => arg1.EnfantID == ID))
  520.         {
  521.             return ReadDB().Enfants.First(el => el.EnfantID == ID).EvaluationsApp2;
  522.         }
  523.         else
  524.         {
  525.             return new List<EvaluationApp2>();
  526.         }
  527.     }
  528.  
  529.     public static string CreateNewEvalutionApp3(int EnfantID)
  530.     {
  531.         DB db = ReadDB();
  532.  
  533.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  534.  
  535.         EvaluationApp3 newEvaluation = new EvaluationApp3
  536.         {
  537.             EvaluationID = TimeStampID()
  538.         };
  539.         enfant.EvaluationsApp3.Add(newEvaluation);
  540.  
  541.         WriteDB(db);
  542.  
  543.         return newEvaluation.EvaluationID;
  544.     }
  545.  
  546.     public static string CreateNewEvalutionApp3(int EnfantID, string NomExaminateur, string LieuExamination, string DateExamination)
  547.     {
  548.         DB db = ReadDB();
  549.  
  550.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  551.  
  552.         EvaluationApp3 newEvaluation = new EvaluationApp3
  553.         {
  554.             EvaluationID = TimeStampID(),
  555.             nomExaimnateur = NomExaminateur,
  556.             LieuExamination = LieuExamination,
  557.             DateExamination = DateExamination
  558.         };
  559.         enfant.EvaluationsApp3.Add(newEvaluation);
  560.  
  561.         WriteDB(db);
  562.  
  563.         return newEvaluation.EvaluationID;
  564.     }
  565.  
  566.     public static string CreateNewEvalutionApp4(int EnfantID)
  567.     {
  568.         DB db = ReadDB();
  569.  
  570.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  571.  
  572.         EvaluationApp4 newEvaluation = new EvaluationApp4
  573.         {
  574.             EvaluationID = TimeStampID()
  575.         };
  576.         enfant.EvaluationsApp4.Add(newEvaluation);
  577.  
  578.         WriteDB(db);
  579.  
  580.         return newEvaluation.EvaluationID;
  581.     }
  582.  
  583.     public static string CreateNewEvalutionApp4(int EnfantID, string NomExaminateur, string LieuExamination, string DateExamination)
  584.     {
  585.         DB db = ReadDB();
  586.  
  587.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  588.  
  589.         EvaluationApp4 newEvaluation = new EvaluationApp4
  590.         {
  591.             EvaluationID = TimeStampID(),
  592.             nomExaimnateur = NomExaminateur,
  593.             LieuExamination = LieuExamination,
  594.             DateExamination = DateExamination
  595.         };
  596.         enfant.EvaluationsApp4.Add(newEvaluation);
  597.  
  598.         WriteDB(db);
  599.  
  600.         return newEvaluation.EvaluationID;
  601.     }
  602.  
  603.     public static string CreateNewEvalutionApp2(int EnfantID)
  604.     {
  605.         DB db = ReadDB();
  606.  
  607.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  608.  
  609.         EvaluationApp2 newEvaluation = new EvaluationApp2
  610.         {
  611.             EvaluationID = TimeStampID()
  612.         };
  613.         enfant.EvaluationsApp2.Add(newEvaluation);
  614.  
  615.         WriteDB(db);
  616.  
  617.         return newEvaluation.EvaluationID;
  618.     }
  619.  
  620.     public static List<Session> GetSessionsByEvaluationIDAndEnfantID(int EnfantID, string EvalutionID)
  621.     {
  622.         return ReadDB().Enfants.First(enfant => enfant.EnfantID == EnfantID).EvaluationsApp1.First(evaluation => evaluation.EvaluationID == EvalutionID).Sessions;
  623.     }
  624.  
  625.     public static int CreateEnfant(
  626.                                     string NumeroDossier,
  627.                                     string Nom,
  628.                                     string Prenom,
  629.                                     string Genre,
  630.                                     string DateDeNaissance,
  631.                                     string ct1,
  632.                                     string ct2,
  633.                                     string NiveauScolaire,
  634.                                     string MoyenneAnneePrecedente,
  635.                                     string NivSocioEco,
  636.                                     string DiagnostiqueDSMV,
  637.                                     string CPM,
  638.                                     string TestComprehension,
  639.                                     string TestDeFluenceVerbaleSemantique,
  640.                                     string NomRéférant,
  641.                                     string PrénomRéférant,
  642.                                     string StatusRéférant,
  643.                                     string situationMatrimoniale,
  644.                                     string NombreEnfants,
  645.                                     string MaladieAuLongCours,
  646.                                     string AntecedentsPsychiatriques
  647.                                    )
  648.     {
  649.         DB db = ReadDB();
  650.  
  651.         Enfant newEnfant = new Enfant
  652.         {
  653.             EnfantID = db.Enfants.Count,
  654.  
  655.             NumeroDossier = NumeroDossier,
  656.             Nom = Nom,
  657.             Prenom = Prenom,
  658.             Genre = Genre,
  659.             DateDeNaissance = DateDeNaissance,
  660.             ct1 = ct1,
  661.             ct2 = ct2,
  662.             NiveauScolaire = NiveauScolaire,
  663.             MoyenneAnneePrecedente = MoyenneAnneePrecedente,
  664.             NivSocioEco = NivSocioEco,
  665.             DiagnostiqueDSMV = DiagnostiqueDSMV,
  666.             CPM = CPM,
  667.             TestComprehension = TestComprehension,
  668.             TestDeFluenceVerbaleSemantique = TestDeFluenceVerbaleSemantique,
  669.             NomReferant = NomRéférant,
  670.             PrenomReferant = PrénomRéférant,
  671.             StatusReferant = StatusRéférant,
  672.             situationMatrimoniale = situationMatrimoniale,
  673.             NombreEnfants = NombreEnfants,
  674.             MaladieAuLongCours = MaladieAuLongCours,
  675.             AntecedentsPsychiatriques = AntecedentsPsychiatriques
  676.         };
  677.  
  678.         db.Enfants.Add(newEnfant);
  679.  
  680.         WriteDB(db);
  681.  
  682.         return newEnfant.EnfantID;
  683.     }
  684.  
  685.     public static string CreateNewEvalutionApp1(int EnfantID)
  686.     {
  687.         DB db = ReadDB();
  688.  
  689.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  690.  
  691.         EvaluationApp1 newEvaluation = new EvaluationApp1
  692.         {
  693.             EvaluationID = TimeStampID()
  694.         };
  695.         enfant.EvaluationsApp1.Add(newEvaluation);
  696.  
  697.         WriteDB(db);
  698.  
  699.         return newEvaluation.EvaluationID;
  700.     }
  701.  
  702.     public static string CreateNewSession(int EnfantID, int EvaluationID, string nomexa, string dateexa, string lieuexa)
  703.     {
  704.         DB db = ReadDB();
  705.  
  706.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  707.  
  708.         Session newSession = new Session
  709.         {
  710.             SessionID = TimeStampID(),
  711.  
  712.             NomExaminateur = nomexa,
  713.             DateExamination = dateexa,
  714.             LieuExamination = lieuexa,
  715.             Duree = 0,
  716.             ScoreSession = 0,
  717.             Synced = false
  718.         };
  719.         enfant.EvaluationsApp1[EvaluationID].Sessions.Add(newSession);
  720.  
  721.         WriteDB(db);
  722.  
  723.         return newSession.SessionID;
  724.     }
  725.  
  726.     public static void UpdateSessionWithScoreAndDurationAndTags(int EnfantID, int EvaluationID, int SessionID, int Score, int Duration, int StoryDoneID, List<TagApp1> tags)
  727.     {
  728.         DB db = ReadDB();
  729.  
  730.         Enfant enfant = db.Enfants.First(el => el.EnfantID == EnfantID);
  731.  
  732.         enfant.EvaluationsApp1[EvaluationID].Sessions[SessionID].ScoreSession = Score;
  733.         enfant.EvaluationsApp1[EvaluationID].Sessions[SessionID].Duree = Duration;
  734.         enfant.EvaluationsApp1[EvaluationID].Sessions[SessionID].SituationsDone.Add(StoryDoneID);
  735.  
  736.         for (int i = 0; i < tags.Count; i++)
  737.         {
  738.             if (tags[i].ID == enfant.EvaluationsApp1[EvaluationID].Sessions[SessionID].Tags[i].ID)
  739.             {
  740.                 enfant.EvaluationsApp1[EvaluationID].Sessions[SessionID].Tags[i].Value += tags[i].Value;
  741.             }
  742.         }
  743.  
  744.         // enfant.Evaluations [EvaluationID].Sessions [SessionID].Tags.Clear ();
  745.         // if (tags != null)
  746.         //enfant.Evaluations [EvaluationID].Sessions [SessionID].Tags.AddRange (tags);
  747.  
  748.         WriteDB(db);
  749.     }
  750.  
  751.     public static int GetScoreForEnfantIDAndEvaluationIDAndSessionID(int EnfantID, string EvaluationID, string SessionID)
  752.     {
  753.         return ReadDB().Enfants.First(e => e.EnfantID == EnfantID).EvaluationsApp1
  754.             .First(e => e.EvaluationID == EvaluationID).Sessions
  755.             .First(s => s.SessionID == SessionID).ScoreSession;
  756.     }
  757.  
  758.     public static List<EvaluationApp1> GetAllEvaluationsApp1ForEnfant(int EnfantID)
  759.     {
  760.         return ReadDB().Enfants.First(el => el.EnfantID == EnfantID).EvaluationsApp1;
  761.     }
  762.  
  763.     public static List<EvaluationApp3> GetAllEvaluationsApp3ForEnfant(int EnfantID)
  764.     {
  765.         return ReadDB().Enfants.First(el => el.EnfantID == EnfantID).EvaluationsApp3;
  766.     }
  767.  
  768.     public static List<EvaluationApp4> GetAllEvaluationsApp4ForEnfant(int EnfantID)
  769.     {
  770.         return ReadDB().Enfants.First(el => el.EnfantID == EnfantID).EvaluationsApp4;
  771.     }
  772.  
  773.     public static List<string> GetAllExaminateursNames()
  774.     {
  775.         List<string> result = new List<string>();
  776.  
  777.         List<Enfant> all = GetAllEnfants();
  778.  
  779.         foreach (var enfant in all)
  780.         {
  781.             foreach (var evaluation in enfant.EvaluationsApp1)
  782.             {
  783.                 foreach (var session in evaluation.Sessions)
  784.                 {
  785.                     if (!result.Exists(v => v == session.NomExaminateur))
  786.                     {
  787.                         result.Add(session.NomExaminateur);
  788.                     }
  789.                 }
  790.             }
  791.         }
  792.  
  793.         return result;
  794.     }
  795.  
  796.     public static List<string> GetAllLocations()
  797.     {
  798.         List<string> result = new List<string>();
  799.  
  800.         List<Enfant> all = GetAllEnfants();
  801.  
  802.         foreach (var enfant in all)
  803.         {
  804.             foreach (var evaluation in enfant.EvaluationsApp1)
  805.             {
  806.                 foreach (var session in evaluation.Sessions)
  807.                 {
  808.                     if (!result.Exists(v => v == session.LieuExamination))
  809.                     {
  810.                         result.Add(session.LieuExamination);
  811.                     }
  812.                 }
  813.             }
  814.         }
  815.  
  816.         return result;
  817.     }
  818. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement