EntrepotChiffresSignificatifs.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using CG67.FicheCollege.Domaine;
  7. using CG67.FicheCollege.Interface;
  8. namespace CG67.FicheCollege.Entrepot
  9. {
  10. public class EntrepotChiffresSignificatifs : EntrepotBase, IEntrepotChiffresSignificatifs
  11. {
  12. public ChiffresSignificatifs GetByAnnee(int annee)
  13. {
  14. ChiffresSignificatifs resultat = new ChiffresSignificatifs();
  15. string sum;
  16. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  17. {
  18. try
  19. {
  20. connexion.Open();
  21. using (SqlCommand command = connexion.CreateCommand())
  22. {
  23. //Il n'est pas possible de tout faire en une requete ...
  24. //Du coup, une requete a été crée par chiffre (deux dans le cas du montant total des financements.
  25. command.CommandText = "SELECT sum(Dotation.Montant) as totalDotation FROM Dotation WHERE Dotation.Annee = @Annee";
  26. command.Parameters.AddWithValue("@Annee", annee);
  27. sum = command.ExecuteScalar().ToString();
  28. resultat.MontantTotalFinancements = string.IsNullOrEmpty(sum) ? 0 : Convert.ToDouble(sum);
  29. //using (SqlDataReader dr = command.ExecuteReader())
  30. //{
  31. // while (dr.Read())
  32. // {
  33. // resultat.MontantTotalFinancements += Convert.ToDouble(dr["totalDotation"].ToString());
  34. // }
  35. //}
  36. command.CommandText = "SELECT sum(MontantSubvention) as totalSubvention FROM Etablissement_ActionEducative WHERE Etablissement_ActionEducative.Annee = @Annee";
  37. sum = command.ExecuteScalar().ToString();
  38. resultat.MontantTotalFinancements = string.IsNullOrEmpty(sum) ? 0 : System.Convert.ToDouble(sum);
  39. //using (SqlDataReader dr2 = command.ExecuteReader())
  40. //{
  41. // while (dr2.Read())
  42. // {
  43. // resultat.MontantTotalFinancements += Convert.ToDouble(dr2["totalSubvention"].ToString());
  44. // }
  45. //}
  46. //command.CommandText = "SELECT sum(TotalEleves) as totalEleves FROM Effectif WHERE Effectif.Annee = @Annee";
  47. command.CommandText ="SELECT Sum(EffectifTotal.EffectifTotal) AS SommeDeEffectifTotal FROM EffectifTotal GROUP BY EffectifTotal.Annee HAVING (((EffectifTotal.Annee)=@Annee))";
  48. sum = command.ExecuteScalar().ToString();
  49. resultat.NbTotalEleves = string.IsNullOrEmpty(sum) ? (Int32) 0 : Convert.ToInt32 (sum);
  50. command.CommandText = "SELECT sum(Montant) as totalInvest FROM Investissement WHERE Investissement.Annee = @Annee";
  51. sum = command.ExecuteScalar().ToString();
  52. resultat.MontantTotalInvestissement = string.IsNullOrEmpty(sum) ? 0 : Convert.ToDouble (sum);
  53. //using (SqlDataReader dr4 = command.ExecuteReader())
  54. //{
  55. // while (dr4.Read())
  56. // {
  57. // resultat.MontantTotalInvestissement += Convert.ToDouble(dr4["totalInvest"].ToString());
  58. // }
  59. //}
  60. command.CommandText = "SELECT CoutTotal as totalTransport FROM Transport WHERE Transport.Annee = @Annee";
  61. using (SqlDataReader dr5 = command.ExecuteReader())
  62. {
  63. while (dr5.Read())
  64. {
  65. resultat.MontantTotalTransportScolaire += Convert.ToDouble(dr5["totalTransport"].ToString());
  66. }
  67. }
  68. }
  69. }
  70. catch (Exception erreurInterne)
  71. {
  72. throw new Exception(erreurInterne.ToString());
  73. }
  74. finally
  75. {
  76. if (connexion.State == ConnectionState.Open)
  77. connexion.Close();
  78. }
  79. }
  80. return resultat;
  81. }
  82. }
  83. }