EntrepotChiffresSignificatifs.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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) AND (Typedonnees='R'))";
  48. //command.CommandText = "SELECT Sum(EffectifTotal.EffectifTotal) AS SommeDeEffectifTotal FROM EffectifTotal WHERE Annee = @Annee ";
  49. command.CommandText = "SELECT Sum(EffectifTotal.EffectifTotal) AS SommeDeEffectifTotal FROM EffectifTotal GROUP BY EffectifTotal.Annee, EffectifTotal.Typedonnees, EffectifTotal.TypeClasses HAVING (EffectifTotal.Annee = @Annee) AND (EffectifTotal.TypeDonnees = 'R')";
  50. //command.Parameters.AddWithValue("@Annee", annee);
  51. sum = command.ExecuteScalar().ToString();
  52. resultat.NbTotalEleves = string.IsNullOrEmpty(sum) ? (Int32) 0 : Convert.ToInt32 (sum);
  53. command.CommandText = "SELECT sum(Montant) as totalInvest FROM Investissement WHERE Investissement.Annee = @Annee";
  54. sum = command.ExecuteScalar().ToString();
  55. resultat.MontantTotalInvestissement = string.IsNullOrEmpty(sum) ? 0 : Convert.ToDouble (sum);
  56. //using (SqlDataReader dr4 = command.ExecuteReader())
  57. //{
  58. // while (dr4.Read())
  59. // {
  60. // resultat.MontantTotalInvestissement += Convert.ToDouble(dr4["totalInvest"].ToString());
  61. // }
  62. //}
  63. command.CommandText = "SELECT CoutTotal as totalTransport FROM Transport WHERE Transport.Annee = @Annee";
  64. using (SqlDataReader dr5 = command.ExecuteReader())
  65. {
  66. while (dr5.Read())
  67. {
  68. resultat.MontantTotalTransportScolaire += Convert.ToDouble(dr5["totalTransport"].ToString());
  69. }
  70. }
  71. }
  72. }
  73. catch (Exception erreurInterne)
  74. {
  75. throw new Exception(erreurInterne.ToString());
  76. }
  77. finally
  78. {
  79. if (connexion.State == ConnectionState.Open)
  80. connexion.Close();
  81. }
  82. }
  83. return resultat;
  84. }
  85. }
  86. }