EntrepotChiffresSignificatifs.cs 4.8 KB

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