AccessSerieDao.cs

Description du code

AccessSerieDao.cs est un fichier du projet BiblioBrol.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/src/.

Projet BiblioBrol :

Gestion de media en CSharp.

Pour plus d'infos, vous pouvez consulter la brève analyse.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data.Common;
  5. using System.Data;
  6. using be.gaudry.observer;
  7.  
  8. namespace be.gaudry.bibliobrol.model.dao.msaccess
  9. {
  10. class AccessSerieDao : Observable, ISerieDao
  11. {
  12. #region singleton
  13. static AccessSerieDao instance = null;
  14. static readonly object padlock = new object();
  15. private String conStr;
  16. private DbProviderFactory dbpf;
  17. AccessSerieDao()
  18. {
  19. notify(new Notification(Notification.VERBOSE.debug, "AccessSerieDao singleton call", this));
  20. dbpf = ((AccessFactory)AccessFactory.Instance).getDbpf();
  21. conStr = ((AccessFactory)AccessFactory.Instance).getConnectionString();
  22. }
  23. public static AccessSerieDao Instance
  24. {
  25. get
  26. {
  27. lock (padlock)
  28. {
  29. if (instance == null)
  30. {
  31. instance = new AccessSerieDao();
  32. }
  33. return instance;
  34. }
  35. }
  36. }
  37. #endregion
  38.  
  39. #region ISerieDao Membres
  40.  
  41. public bool insertSerie(Serie serie)
  42. {
  43. if (serie.Id > 0)
  44. {
  45. notify(new Notification(Notification.VERBOSE.opsResult, "Impossible d'insérer la série.", this));
  46. return false;
  47. }
  48. DbConnection dbCon = dbpf.CreateConnection();
  49. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  50. dbDa.InsertCommand = dbCon.CreateCommand();
  51. dbCon.ConnectionString = conStr;
  52. dbCon.Open();
  53. dbDa.InsertCommand.CommandText = string.Format(
  54. "INSERT INTO serie (name) VALUES ('{0}');",
  55. AccessUtils.escapeAndTrim(serie.Name)
  56. );
  57. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  58. try
  59. {
  60. dbDa.InsertCommand.ExecuteNonQuery();
  61. }
  62. catch (Exception e)
  63. {
  64. notify(new Notification(Notification.VERBOSE.error, "Insertion d'une série", e, this));
  65. return false;
  66. }
  67. finally
  68. {
  69. dbCon.Close();
  70. }
  71. notify(new Notification(Notification.VERBOSE.opsResult, "La série \"" + serie.Name + "\" est ajoutée", this));
  72. return true;
  73. }
  74.  
  75. public bool updateSerie(Serie serie)
  76. {
  77. if (serie.Id <= 0)
  78. {
  79. return insertSerie(serie);
  80. }
  81. DbConnection dbCon = dbpf.CreateConnection();
  82. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  83. dbDa.UpdateCommand = dbCon.CreateCommand();
  84. dbCon.ConnectionString = conStr;
  85. dbCon.Open();
  86.  
  87. dbDa.UpdateCommand.CommandText = string.Format(
  88. "UPDATE serie SET name='{0}' WHERE id={1};",
  89. AccessUtils.escapeAndTrim(serie.Name),
  90. serie.Id
  91. );
  92. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  93. try
  94. {
  95. dbDa.UpdateCommand.ExecuteNonQuery();
  96. }
  97. catch (Exception e)
  98. {
  99. notify(new Notification(Notification.VERBOSE.error, "Modification d'une série", e, this));
  100. return false;
  101. }
  102. finally
  103. {
  104. dbCon.Close();
  105. }
  106. notify(new Notification(Notification.VERBOSE.opsResult, "La série \"" + serie.Name + "\" est modifiée", this));
  107. return true;
  108. }
  109. public bool deleteSerie(int serieId)
  110. {
  111. if (serieId <= 0)
  112. {
  113. notify(new Notification(Notification.VERBOSE.opsResult, "Impossible de supprimer la série.", this));
  114. return false;
  115. }
  116. DbConnection dbCon = dbpf.CreateConnection();
  117. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  118. dbDa.DeleteCommand = dbCon.CreateCommand();
  119. dbCon.ConnectionString = conStr;
  120. dbCon.Open();
  121. dbDa.DeleteCommand.CommandText = "DELETE FROM serie WHERE id=" + serieId;
  122. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.DeleteCommand.CommandText, this));
  123. try
  124. {
  125. dbDa.DeleteCommand.ExecuteNonQuery();
  126. }
  127. catch (Exception e)
  128. {
  129. notify(new Notification(Notification.VERBOSE.error, "Suppression d'une série", e, this));
  130. return false;
  131. }
  132. finally
  133. {
  134. dbCon.Close();
  135. }
  136. notify(new Notification(Notification.VERBOSE.opsResult, "La série est supprimée", this));
  137. return true;
  138. }
  139.  
  140. public List<Serie> loadSeries()
  141. {
  142. List<Serie> series = new List<Serie>();
  143. DbConnection dbCon = dbpf.CreateConnection();
  144. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  145. dbDa.SelectCommand = dbCon.CreateCommand();
  146. dbCon.ConnectionString = conStr;
  147. String str = "SELECT * FROM serie ORDER BY name";
  148. dbDa.SelectCommand.CommandText = str;
  149. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  150. DataTable dt = new DataTable();
  151. try
  152. {
  153. dbDa.Fill(dt);
  154. foreach (DataRow row in dt.Rows)
  155. {
  156. series.Add(new Serie(
  157. (int)row["id"],
  158. (row["name"] is DBNull) ? "Sans nom" : (String)row["name"]));
  159. }
  160. }
  161. catch (Exception e)
  162. {
  163. notify(new Notification(Notification.VERBOSE.lowError,"Chargement des séries", e, this));
  164. }
  165. dt.Dispose();
  166. dbCon.Close();
  167. return series;
  168. }
  169.  
  170. #endregion
  171. }
  172. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/src/model/dao/msaccess/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1719973222 03/07/2024 04:20:22
| _utils0 octets1541007203 31/10/2018 18:33:23
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/model/dao/msaccess/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csAccessStatsDao.cs10.59 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessImporterDao.cs27.13 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessMediaBrolDao.cs50.3 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessExporterDao.cs33.67 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessTaskDao.cs8.93 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessBrolDao.cs58.26 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessSerieDao.cs6.22 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessConfigDao.cs12.22 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessPersonDao.cs59.94 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csAccessFactory.cs3.35 Ko31/10/2018 18:33:17-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Document créé le 16/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-bibliobrol-source-rf-model/dao/msaccess/AccessSerieDao.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.