AccessStatsDao.cs

Description du code

AccessStatsDao.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. using be.gaudry.model;
  8.  
  9. namespace be.gaudry.bibliobrol.model.dao.msaccess
  10. {
  11. class AccessStatsDao : Observable, IStatsDao
  12. {
  13. #region singleton
  14. static AccessStatsDao instance = null;
  15. static readonly object padlock = new object();
  16. private String conStr;
  17. private DbProviderFactory dbpf;
  18. AccessStatsDao()
  19. {
  20. notify(new Notification(Notification.VERBOSE.debug, "AccessStatsDao singleton call", this));
  21. dbpf = ((AccessFactory)AccessFactory.Instance).getDbpf();
  22. conStr = ((AccessFactory)AccessFactory.Instance).getConnectionString();
  23. }
  24. public static AccessStatsDao Instance
  25. {
  26. get
  27. {
  28. lock (padlock)
  29. {
  30. if (instance == null)
  31. {
  32. instance = new AccessStatsDao();
  33. }
  34. return instance;
  35. }
  36. }
  37. }
  38. #endregion
  39.  
  40. #region IStatsDao Membres
  41.  
  42. public Counter loadCounters()
  43. {
  44. Counter counter = new Counter();
  45.  
  46. DbConnection dbCon = dbpf.CreateConnection();
  47. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  48. dbDa.SelectCommand = dbCon.CreateCommand();
  49. dbCon.ConnectionString = conStr;
  50.  
  51. try
  52. {
  53. dbCon.Open();
  54. dbDa.SelectCommand.CommandText = "SELECT COUNT(id) AS [nb] FROM person";
  55. counter.PersonsCount = (int)dbDa.SelectCommand.ExecuteScalar();
  56.  
  57. dbDa.SelectCommand.CommandText = "SELECT COUNT(personId) AS [nb] FROM [user]";
  58. counter.UsersCount = (int)dbDa.SelectCommand.ExecuteScalar();
  59.  
  60. dbDa.SelectCommand.CommandText = "SELECT COUNT(id) AS [nb] FROM borrow";
  61. counter.BorrowsCount = (int)dbDa.SelectCommand.ExecuteScalar();
  62.  
  63. dbDa.SelectCommand.CommandText = "SELECT COUNT(id) AS [nb] FROM item";
  64. counter.BrolCount = (int)dbDa.SelectCommand.ExecuteScalar();
  65.  
  66. dbCon.Close();
  67. }
  68. catch (Exception e)
  69. {
  70. notify(new Notification(Notification.VERBOSE.error, "Chargement des statistiques", e, this));
  71. }
  72. finally
  73. {
  74. if (dbCon.State != ConnectionState.Closed) dbCon.Close();
  75. }
  76. return counter;
  77. }
  78.  
  79. public Stat loadActorRoles()
  80. {
  81. DbConnection dbCon = dbpf.CreateConnection();
  82. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  83. dbDa.SelectCommand = dbCon.CreateCommand();
  84. dbCon.ConnectionString = conStr;
  85. StringBuilder str = new StringBuilder("SELECT COUNT(actor.roleId) AS [actors], role.roleName AS [role_name]");
  86. str.Append(" FROM role INNER JOIN actor ON role.[id] = actor.[roleId]");
  87. str.Append(" GROUP BY role.roleName, actor.roleId");
  88. str.Append(" ORDER BY COUNT(actor.roleId) DESC");
  89. /*StringBuilder str = new StringBuilder("SELECT COUNT(actor.personId) AS [actors], [firstName]+\" \"+[lastName] AS [actor_name]");
  90.   str.Append(" FROM person INNER JOIN actor ON person.[id] = actor.[personId]");
  91.   str.Append(" GROUP BY person.lastName, person.firstName, actor.roleId");
  92.   str.Append(" ORDER BY COUNT(actor.personId) DESC");*/
  93. dbDa.SelectCommand.CommandText = str.ToString();
  94. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  95. DataTable brolDt = new DataTable();
  96. try
  97. {
  98. dbDa.Fill(brolDt);
  99. }
  100. catch (System.Data.OleDb.OleDbException e)
  101. {
  102. notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des rôles pour les statistiques", e, this));
  103. }
  104. dbCon.Close();
  105. Stat stat = new Stat("{0:0.0%} des personnes ({1}) pour le rôle \"{2}\"");
  106.  
  107. foreach (DataRow dr in brolDt.Rows)
  108. {
  109. stat.increase((String)dr["role_name"],(int)dr["actors"]);
  110. }
  111. return stat;
  112. }
  113.  
  114. public Stat loadCurrentBorrows()
  115. {
  116. DbConnection dbCon = dbpf.CreateConnection();
  117. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  118. dbDa.SelectCommand = dbCon.CreateCommand();
  119. dbCon.ConnectionString = conStr;
  120. StringBuilder str = new StringBuilder("SELECT COUNT(borrow.id) AS [borrows], [firstName]+\" \"+[lastName] AS [borrower]");
  121. str.Append(" FROM person INNER JOIN borrow ON person.[id] = borrow.[personId]");
  122. str.Append(" GROUP BY person.lastName, person.firstName, borrow.endDate");
  123. str.Append(" HAVING (((Count(borrow.id))>0) AND ((borrow.endDate) Is Null))");
  124. str.Append(" ORDER BY COUNT(borrow.id) DESC");
  125. dbDa.SelectCommand.CommandText = str.ToString();
  126. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  127. DataTable brolDt = new DataTable();
  128. try
  129. {
  130. dbDa.Fill(brolDt);
  131. }
  132. catch (System.Data.OleDb.OleDbException e)
  133. {
  134. notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des emprunts en cours pour les statistiques", e, this));
  135. }
  136. dbCon.Close();
  137. Stat stat = new Stat("{0:0.0%} d'emprunts ({1}) en cours pour {2}");
  138.  
  139. foreach (DataRow dr in brolDt.Rows)
  140. {
  141. stat.increase((String)dr["borrower"], (int)dr["borrows"]);
  142. }
  143. return stat;
  144. }
  145.  
  146. public Stat loadAllBorrows()
  147. {
  148. DbConnection dbCon = dbpf.CreateConnection();
  149. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  150. dbDa.SelectCommand = dbCon.CreateCommand();
  151. dbCon.ConnectionString = conStr;
  152. /*
  153.   SELECT Count(borrow.id) AS borrows, [firstName]+" "+[lastName] AS borrower
  154. FROM person INNER JOIN borrow ON person.id = borrow.personId
  155. GROUP BY [firstName]+" "+[lastName]
  156. HAVING (((Count(borrow.id))>0))
  157. ORDER BY Count(borrow.id) DESC;
  158.   */
  159. StringBuilder str = new StringBuilder("SELECT COUNT(borrow.id) AS [borrows],[firstName]+\" \"+[lastName] AS [borrower]");
  160. str.Append(" FROM person INNER JOIN borrow ON person.[id] = borrow.[personId]");
  161. str.Append(" GROUP BY [firstName]+\" \"+[lastName]");
  162. str.Append(" HAVING COUNT(borrow.id)>0");
  163. str.Append(" ORDER BY COUNT(borrow.id) DESC");
  164. dbDa.SelectCommand.CommandText = str.ToString();
  165. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  166. DataTable brolDt = new DataTable();
  167. try
  168. {
  169. dbDa.Fill(brolDt);
  170. }
  171. catch (System.Data.OleDb.OleDbException e)
  172. {
  173. notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des emprunts pour les statistiques", e, this));
  174. }
  175. dbCon.Close();
  176. Stat stat = new Stat("{0:0.0%} d'emprunts ({1}) sur le total pour {2}");
  177.  
  178. foreach (DataRow dr in brolDt.Rows)
  179. {
  180. stat.increase((String)dr["borrower"], (int)dr["borrows"]);
  181. }
  182. return stat;
  183. }
  184.  
  185. public Stat loadBrolTypes()
  186. {
  187. DbConnection dbCon = dbpf.CreateConnection();
  188. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  189. dbDa.SelectCommand = dbCon.CreateCommand();
  190. dbCon.ConnectionString = conStr;
  191. StringBuilder str = new StringBuilder("SELECT COUNT(item.id) AS items, type.name");
  192. str.Append(" FROM type LEFT JOIN item ON type.id = item.typeId");
  193. str.Append(" GROUP BY type.name");
  194. str.Append(" ORDER BY COUNT(item.id) DESC;");
  195. dbDa.SelectCommand.CommandText = str.ToString();
  196. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  197. DataTable brolDt = new DataTable();
  198. try
  199. {
  200. dbDa.Fill(brolDt);
  201. }
  202. catch (System.Data.OleDb.OleDbException e)
  203. {
  204. notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des types d'ouvrages pour les statistiques", e, this));
  205. }
  206. dbCon.Close();
  207. Stat stat = new Stat("{0:0.0%} d'ouvrages ({1}) pour le type {2}");
  208.  
  209. foreach (DataRow dr in brolDt.Rows)
  210. {
  211. stat.increase((String)dr["name"], (int)dr["items"]);
  212. }
  213. return stat;
  214. }
  215.  
  216. public Stat loadMediaBrolTypes()
  217. {
  218. DbConnection dbCon = dbpf.CreateConnection();
  219. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  220. dbDa.SelectCommand = dbCon.CreateCommand();
  221. dbCon.ConnectionString = conStr;
  222. StringBuilder str = new StringBuilder("SELECT COUNT(itemBiblio.id) AS items, type.name");
  223. str.Append(" FROM type LEFT JOIN (item LEFT JOIN itemBiblio ON item.id = itemBiblio.itemId) ON type.id = item.typeId");
  224. str.Append(" GROUP BY type.name");
  225. str.Append(" ORDER BY COUNT(itemBiblio.id) DESC;");
  226. dbDa.SelectCommand.CommandText = str.ToString();
  227. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  228. DataTable brolDt = new DataTable();
  229. try
  230. {
  231. dbDa.Fill(brolDt);
  232. }
  233. catch (System.Data.OleDb.OleDbException e)
  234. {
  235. notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des types d'exemplaires pour les statistiques", e, this));
  236. }
  237. dbCon.Close();
  238. Stat stat = new Stat("{0:0.0%} d'exemplaires ({1}) pour le type {2}");
  239.  
  240. foreach (DataRow dr in brolDt.Rows)
  241. {
  242. stat.increase((String)dr["name"], (int)dr["items"]);
  243. }
  244. return stat;
  245. }
  246. #endregion
  247. }
  248. }

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 octets1734906708 22/12/2024 23:31:48
| _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.

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-bibliobrol-source-rf-model/dao/msaccess/AccessStatsDao.cs.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.