EntrepotDotation.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 EntrepotDotation : EntrepotBase, IEntrepotDotation
  11. {
  12. public Dotation GetByCodeRNEAndAnnee(string codeRNE, int annee)
  13. {
  14. Dotation resultat = new Dotation();
  15. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  16. {
  17. try
  18. {
  19. connexion.Open();
  20. using (SqlCommand command = connexion.CreateCommand())
  21. {
  22. command.CommandText = "Select * from Dotation INNER JOIN TypeDotation ON IdDotation = id WHERE CodeRNE = @RNE AND Annee = @Annee";
  23. command.Parameters.AddWithValue("@RNE", codeRNE);
  24. command.Parameters.AddWithValue("@Annee", annee);
  25. using (SqlDataReader dr = command.ExecuteReader())
  26. {
  27. while (dr.Read())
  28. {
  29. switch (dr["Libelle"].ToString())
  30. {
  31. case "Viabilisation":
  32. resultat.Viabilisation = Convert.ToDouble(dr["Montant"].ToString());
  33. resultat.Annee = dr["annee"].ToString();
  34. break;
  35. case "Entretien":
  36. resultat.Entretien = Convert.ToDouble(dr["Montant"].ToString());
  37. resultat.Annee = dr["annee"].ToString();
  38. break;
  39. case "Autres dépenses":
  40. resultat.AutresDepenses = Convert.ToDouble(dr["Montant"].ToString());
  41. resultat.Annee = dr["annee"].ToString();
  42. break;
  43. case "Réfaction":
  44. resultat.Refaction = Convert.ToDouble(dr["Montant"].ToString());
  45. resultat.Annee = dr["annee"].ToString();
  46. break;
  47. default:
  48. Console.WriteLine("{0}", "Erreur dotation");
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. }
  55. catch (Exception erreurInterne)
  56. {
  57. throw new Exception(" " + erreurInterne);
  58. }
  59. finally
  60. {
  61. if (connexion.State == ConnectionState.Open)
  62. connexion.Close();
  63. }
  64. }
  65. return resultat;
  66. }
  67. }
  68. }