ServiceFiche.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using System.Reflection;
  6. using System.Xml;
  7. using System.Xml.Serialization;
  8. using CG67.FicheCollege.Domaine;
  9. using CG67.FicheCollege.Entrepot;
  10. using CG67.FicheCollege.Interface;
  11. using System.Collections;
  12. namespace CG67.FicheCollege.Service
  13. {
  14. /// <summary>
  15. /// Une méthode est déclarée pour chaque Entrepot, ceci permet l'appel en static depuis n'importe où
  16. /// y compris depuis une page ASP.
  17. /// </summary>
  18. [DataObject]
  19. public static class ServiceFiche
  20. {
  21. public static IList<ActionEducative> GetActionEducativeByRNEAndAnnee(string codeRNE, int annee)
  22. {
  23. try
  24. {
  25. return EntrepotFactory.GetEntrepotActionEducative().GetByCodeRNEAndAnnee(codeRNE, annee);
  26. }
  27. catch (Exception erreur)
  28. {
  29. throw new Exception(erreur.ToString());
  30. }
  31. }
  32. public static IList<ATC> GetATCByRNE(string codeRNE)
  33. {
  34. try
  35. {
  36. return EntrepotFactory.GetEntrepotATC().GetByCodeRNE(codeRNE);
  37. }
  38. catch (Exception erreur)
  39. {
  40. throw new Exception(erreur.ToString());
  41. }
  42. }
  43. public static Bilinguisme GetBilinguismeByRNEAndAnnee(string codeRNE, int annee)
  44. {
  45. try
  46. {
  47. return EntrepotFactory.GetEntrepotBilinguisme().GetByCodeRNEAndAnnee(codeRNE, annee);
  48. }
  49. catch (Exception erreur)
  50. {
  51. throw new Exception(erreur.ToString());
  52. }
  53. }
  54. public static Dotation GetDotationByRNEAndAnnee(string codeRNE, int annee)
  55. {
  56. try
  57. {
  58. return EntrepotFactory.GetEntrepotDotation().GetByCodeRNEAndAnnee(codeRNE, annee);
  59. }
  60. catch (Exception erreur)
  61. {
  62. throw new Exception(erreur.ToString());
  63. }
  64. }
  65. public static IList<Equipement> GetEquipementByRNEAndAnnee(string codeRNE, int annee)
  66. {
  67. try
  68. {
  69. return EntrepotFactory.GetEntrepotEquipement().GetByCodeRNEAndAnnee(codeRNE, annee);
  70. }
  71. catch (Exception erreur)
  72. {
  73. throw new Exception(erreur.ToString());
  74. }
  75. }
  76. public static IList<Investissement> GetInvestissementByRNEAndAnnee(string codeRNE, int annee)
  77. {
  78. try
  79. {
  80. return EntrepotFactory.GetEntrepotInvestissement().GetByCodeRNEAndAnnee(codeRNE, annee);
  81. }
  82. catch (Exception erreur)
  83. {
  84. throw new Exception(erreur.ToString());
  85. }
  86. }
  87. public static Logement GetLogementByRNE(string codeRNE)
  88. {
  89. try
  90. {
  91. return EntrepotFactory.GetEntrepotLogement().GetByCodeRNE(codeRNE);
  92. }
  93. catch (Exception erreur)
  94. {
  95. throw new Exception(erreur.ToString());
  96. }
  97. }
  98. public static MCG GetMCGByRNE(string codeRNE)
  99. {
  100. try
  101. {
  102. return EntrepotFactory.GetEntrepotMCG().GetByCodeRNE(codeRNE);
  103. }
  104. catch (Exception erreur)
  105. {
  106. throw new Exception(erreur.ToString());
  107. }
  108. }
  109. public static IList<ProjetPilote> GetProjetPiloteByRNEAndAnnee(string codeRNE, int annee)
  110. {
  111. try
  112. {
  113. return EntrepotFactory.GetEntrepotProjetPilote().GetByCodeRNEAndAnnee(codeRNE, annee);
  114. }
  115. catch (Exception erreur)
  116. {
  117. throw new Exception(erreur.ToString());
  118. }
  119. }
  120. public static IList<RestaurationExterne> GetRestaurationExterneByRNEAndAnnee(string codeRNE, int annee)
  121. {
  122. try
  123. {
  124. return EntrepotFactory.GetEntrepotRestaurationExterne().GetByCodeRNEAndAnnee(codeRNE, annee);
  125. }
  126. catch (Exception erreur)
  127. {
  128. throw new Exception(erreur.ToString());
  129. }
  130. }
  131. public static IList<Contact> GetContactByRNE(string codeRNE)
  132. {
  133. try
  134. {
  135. return EntrepotFactory.GetEntrepotContact().GetByCodeRNE(codeRNE);
  136. }
  137. catch (Exception erreur)
  138. {
  139. throw new Exception(erreur.ToString());
  140. }
  141. }
  142. public static ChiffresSignificatifs GetChiffresSignificatifsByAnnee(int annee)
  143. {
  144. try
  145. {
  146. return EntrepotFactory.GetEntrepotChiffresSignificatifs().GetByAnnee(annee);
  147. }
  148. catch (Exception erreur)
  149. {
  150. throw new Exception(erreur.ToString());
  151. }
  152. }
  153. public static Commentaires GetCommentairesByCodeRNE(string codeRNE, int annee)
  154. {
  155. try
  156. {
  157. return EntrepotFactory.GetEntrepotCommentaires().GetByCodeRNEAndAnnee(codeRNE, annee);
  158. }
  159. catch
  160. {
  161. throw;
  162. }
  163. }
  164. public static Restauration GetRestaurationByCodeRNEAndAnnee(string codeRNE, int annee)
  165. {
  166. try
  167. {
  168. return EntrepotFactory.GetEntrepotRestauration().GetByRNEAndAnnee(codeRNE, annee);
  169. }
  170. catch
  171. {
  172. throw;
  173. }
  174. }
  175. public static IList<ProgTravaux> GetProgTravauxByCodeRNEAndAnnee(string codeRNE, int annee)
  176. {
  177. try
  178. {
  179. return EntrepotFactory.GetEntrepotProgTravaux().GetByCodeRNEAndAnnee(codeRNE, annee);
  180. }
  181. catch
  182. {
  183. throw;
  184. }
  185. }
  186. public static IList<Etablissement> GetAllEtablissement()
  187. {
  188. try
  189. {
  190. return EntrepotFactory.GetEntrepotEtablissement().GetAll();
  191. }
  192. catch
  193. {
  194. throw;
  195. }
  196. }
  197. public static Etablissement GetEtablissementByCodeRNEAndAnnee(string codeRNE, int annee)
  198. {
  199. try
  200. {
  201. return EntrepotFactory.GetEntrepotEtablissement().GetByCodeRNEAndAnnee(codeRNE, annee);
  202. }
  203. catch
  204. {
  205. throw;
  206. }
  207. }
  208. private static XmlNode GetXml(Object aSerialiser,XmlDocument document)
  209. {
  210. XmlNode resultat = document.CreateElement(aSerialiser.GetType().Name);
  211. foreach (PropertyInfo pi in aSerialiser.GetType().GetProperties())
  212. {
  213. if (pi.PropertyType.IsSerializable)
  214. {
  215. object valeur = pi.GetValue(aSerialiser, null);
  216. resultat.AppendChild(document.CreateElement(pi.Name)).InnerXml = valeur == null ? string.Empty : valeur.ToString() ;
  217. }
  218. }
  219. return resultat;
  220. }
  221. static XmlNode Serializer(Object objet, XmlDocument doc)
  222. {
  223. XmlNode resultat = doc.CreateElement(objet.GetType().Name);
  224. foreach (PropertyInfo pi in objet.GetType().GetProperties())
  225. {
  226. // Si la propriété comporte une méthode "count" je considère c'est une Liste
  227. if (pi.GetValue(objet, null) != null)
  228. {
  229. MethodInfo mi = pi.GetValue(objet, null).GetType().GetMethod("get_Count");
  230. if (mi != null)
  231. {
  232. object objListe = pi.GetValue(objet, null);
  233. int nb = (int)(mi.Invoke(objListe, null));
  234. XmlNode item = resultat.AppendChild(doc.CreateElement(pi.Name));
  235. for (int i = 0; i < nb; i++)
  236. { // on sérialise tous les items de la liste
  237. object obj = objListe.GetType().GetMethod("get_Item").Invoke(objListe, new Object[] { i });
  238. item.AppendChild(Serializer(obj, doc));
  239. }
  240. }
  241. else // c'est pas une Liste
  242. {
  243. switch (pi.GetValue(objet, null).GetType().Name)
  244. { // si c'est une type de "base" on l'affiche
  245. case "String":
  246. case "Int16":
  247. case "Int32":
  248. case "Double":
  249. case "Single":
  250. resultat.AppendChild(doc.CreateElement(pi.Name)).InnerXml = pi.GetValue(objet, null).ToString();
  251. break;
  252. default: // sinon on le décompose recursivement
  253. resultat.AppendChild(Serializer(pi.GetValue(objet, null), doc));
  254. break;
  255. }
  256. }
  257. }
  258. }
  259. return resultat;
  260. }
  261. public static XmlNode GetFicheCollege(string codeRNE, int annee)
  262. {
  263. XmlDocument resultat = new XmlDocument();
  264. XmlNode xmlCollege = resultat.AppendChild(resultat.CreateElement("college"));
  265. Etablissement etablissement = GetEtablissementByCodeRNEAndAnnee(codeRNE, annee);
  266. xmlCollege.AppendChild(Serializer(etablissement,resultat));
  267. ChiffresSignificatifs chiffres = GetChiffresSignificatifsByAnnee(annee);
  268. xmlCollege.AppendChild(Serializer(chiffres,resultat));
  269. return resultat;
  270. }
  271. }
  272. }