EntrepotDotation.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 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. if (dr.Read())
  28. {
  29. switch (dr["Type"].ToString())
  30. {
  31. case "Viabilisation":
  32. resultat.Viabilisation = Convert.ToDouble(dr["Montant"].ToString());
  33. break;
  34. case "Entretien":
  35. resultat.Entretien = Convert.ToDouble(dr["Montant"].ToString());
  36. break;
  37. case "Autres Depenses":
  38. resultat.AutresDepenses = Convert.ToDouble(dr["Montant"].ToString());
  39. break;
  40. default:
  41. Console.WriteLine("{0}", "petite erreur au niveau de la dotation");
  42. break;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. catch (Exception erreurInterne)
  49. {
  50. throw new Exception(" " + erreurInterne);
  51. }
  52. finally
  53. {
  54. if (connexion.State == ConnectionState.Open)
  55. connexion.Close();
  56. }
  57. }
  58. return resultat;
  59. }
  60. }
  61. }