EntrepotDotation.cs 2.9 KB

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