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
Code c# (AccessStatsDao.cs) (248 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Data.Common; using System.Data; using be.gaudry.observer; using be.gaudry.model; namespace be.gaudry.bibliobrol.model.dao.msaccess { class AccessStatsDao : Observable, IStatsDao { #region singleton static AccessStatsDao instance = null; private String conStr; private DbProviderFactory dbpf; AccessStatsDao() { dbpf = ((AccessFactory)AccessFactory.Instance).getDbpf(); conStr = ((AccessFactory)AccessFactory.Instance).getConnectionString(); } public static AccessStatsDao Instance { get { lock (padlock) { if (instance == null) { } return instance; } } } #endregion #region IStatsDao Membres public Counter loadCounters() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; try { dbCon.Open(); dbDa.SelectCommand.CommandText = "SELECT COUNT(id) AS [nb] FROM person"; counter.PersonsCount = (int)dbDa.SelectCommand.ExecuteScalar(); dbDa.SelectCommand.CommandText = "SELECT COUNT(personId) AS [nb] FROM [user]"; counter.UsersCount = (int)dbDa.SelectCommand.ExecuteScalar(); dbDa.SelectCommand.CommandText = "SELECT COUNT(id) AS [nb] FROM borrow"; counter.BorrowsCount = (int)dbDa.SelectCommand.ExecuteScalar(); dbDa.SelectCommand.CommandText = "SELECT COUNT(id) AS [nb] FROM item"; counter.BrolCount = (int)dbDa.SelectCommand.ExecuteScalar(); dbCon.Close(); } catch (Exception e) { } finally { if (dbCon.State != ConnectionState.Closed) dbCon.Close(); } return counter; } public Stat loadActorRoles() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; StringBuilder str = new StringBuilder("SELECT COUNT(actor.roleId) AS [actors], role.roleName AS [role_name]"); str.Append(" FROM role INNER JOIN actor ON role.[id] = actor.[roleId]"); str.Append(" GROUP BY role.roleName, actor.roleId"); str.Append(" ORDER BY COUNT(actor.roleId) DESC"); /*StringBuilder str = new StringBuilder("SELECT COUNT(actor.personId) AS [actors], [firstName]+\" \"+[lastName] AS [actor_name]"); str.Append(" FROM person INNER JOIN actor ON person.[id] = actor.[personId]"); str.Append(" GROUP BY person.lastName, person.firstName, actor.roleId"); str.Append(" ORDER BY COUNT(actor.personId) DESC");*/ dbDa.SelectCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(brolDt); } catch (System.Data.OleDb.OleDbException e) { notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des rôles pour les statistiques", e, this)); } dbCon.Close(); foreach (DataRow dr in brolDt.Rows) { stat.increase((String)dr["role_name"],(int)dr["actors"]); } return stat; } public Stat loadCurrentBorrows() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; StringBuilder str = new StringBuilder("SELECT COUNT(borrow.id) AS [borrows], [firstName]+\" \"+[lastName] AS [borrower]"); str.Append(" FROM person INNER JOIN borrow ON person.[id] = borrow.[personId]"); str.Append(" GROUP BY person.lastName, person.firstName, borrow.endDate"); str.Append(" HAVING (((Count(borrow.id))>0) AND ((borrow.endDate) Is Null))"); str.Append(" ORDER BY COUNT(borrow.id) DESC"); dbDa.SelectCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(brolDt); } catch (System.Data.OleDb.OleDbException e) { notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des emprunts en cours pour les statistiques", e, this)); } dbCon.Close(); foreach (DataRow dr in brolDt.Rows) { stat.increase((String)dr["borrower"], (int)dr["borrows"]); } return stat; } public Stat loadAllBorrows() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; /* SELECT Count(borrow.id) AS borrows, [firstName]+" "+[lastName] AS borrower FROM person INNER JOIN borrow ON person.id = borrow.personId GROUP BY [firstName]+" "+[lastName] HAVING (((Count(borrow.id))>0)) ORDER BY Count(borrow.id) DESC; */ StringBuilder str = new StringBuilder("SELECT COUNT(borrow.id) AS [borrows],[firstName]+\" \"+[lastName] AS [borrower]"); str.Append(" FROM person INNER JOIN borrow ON person.[id] = borrow.[personId]"); str.Append(" GROUP BY [firstName]+\" \"+[lastName]"); str.Append(" HAVING COUNT(borrow.id)>0"); str.Append(" ORDER BY COUNT(borrow.id) DESC"); dbDa.SelectCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(brolDt); } catch (System.Data.OleDb.OleDbException e) { notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des emprunts pour les statistiques", e, this)); } dbCon.Close(); foreach (DataRow dr in brolDt.Rows) { stat.increase((String)dr["borrower"], (int)dr["borrows"]); } return stat; } public Stat loadBrolTypes() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; str.Append(" FROM type LEFT JOIN item ON type.id = item.typeId"); str.Append(" GROUP BY type.name"); str.Append(" ORDER BY COUNT(item.id) DESC;"); dbDa.SelectCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(brolDt); } catch (System.Data.OleDb.OleDbException e) { notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des types d'ouvrages pour les statistiques", e, this)); } dbCon.Close(); foreach (DataRow dr in brolDt.Rows) { stat.increase((String)dr["name"], (int)dr["items"]); } return stat; } public Stat loadMediaBrolTypes() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; str.Append(" FROM type LEFT JOIN (item LEFT JOIN itemBiblio ON item.id = itemBiblio.itemId) ON type.id = item.typeId"); str.Append(" GROUP BY type.name"); str.Append(" ORDER BY COUNT(itemBiblio.id) DESC;"); dbDa.SelectCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(brolDt); } catch (System.Data.OleDb.OleDbException e) { notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des types d'exemplaires pour les statistiques", e, this)); } dbCon.Close(); foreach (DataRow dr in brolDt.Rows) { stat.increase((String)dr["name"], (int)dr["items"]); } return stat; } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731763296 16/11/2024 14:21:36 |
| _ | utils | 0 octets | 1541007203 31/10/2018 18:33:23 |
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.