EntrepotDotation.cs 2.8 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. 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. resultat.Annee = dr["annee"].ToString();
  36. break;
  37. case "Entretien":
  38. resultat.Entretien = Convert.ToDouble(dr["Montant"].ToString());
  39. resultat.Annee = dr["annee"].ToString();
  40. break;
  41. case "Autres dépenses":
  42. resultat.AutresDepenses = Convert.ToDouble(dr["Montant"].ToString());
  43. resultat.Annee = dr["annee"].ToString();
  44. break;
  45. default:
  46. Console.WriteLine("{0}", "Erreur dotation");
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. catch (Exception erreurInterne)
  54. {
  55. throw new Exception(" " + erreurInterne);
  56. }
  57. finally
  58. {
  59. if (connexion.State == ConnectionState.Open)
  60. connexion.Close();
  61. }
  62. }
  63. return resultat;
  64. }
  65. }
  66. }