EntrepotDotation.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if (System.DateTime.Now.Month > 8)
  16. annee += 1;
  17. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  18. {
  19. try
  20. {
  21. connexion.Open();
  22. using (SqlCommand command = connexion.CreateCommand())
  23. {
  24. command.CommandText = "Select * from Dotation WHERE CodeRNE = @RNE AND Annee = @Annee";
  25. command.Parameters.AddWithValue("@RNE", codeRNE);
  26. command.Parameters.AddWithValue("@Annee", annee);
  27. using (SqlDataReader dr = command.ExecuteReader())
  28. {
  29. while (dr.Read())
  30. {
  31. switch (dr["Type"].ToString())
  32. {
  33. case "Viabilisation":
  34. resultat.Viabilisation = Convert.ToDouble(dr["Montant"].ToString());
  35. break;
  36. case "Entretien":
  37. resultat.Entretien = Convert.ToDouble(dr["Montant"].ToString());
  38. break;
  39. case "Autres dépenses":
  40. resultat.AutresDepenses = Convert.ToDouble(dr["Montant"].ToString());
  41. break;
  42. default:
  43. Console.WriteLine("{0}", "petite erreur au niveau de la dotation");
  44. break;
  45. }
  46. }
  47. }
  48. }
  49. }
  50. catch (Exception erreurInterne)
  51. {
  52. throw new Exception(" " + erreurInterne);
  53. }
  54. finally
  55. {
  56. if (connexion.State == ConnectionState.Open)
  57. connexion.Close();
  58. }
  59. }
  60. return resultat;
  61. }
  62. }
  63. }