AccessTaskDao.cs

Description du code

AccessTaskDao.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 AccessTaskDao : Observable, ITaskDao
  11. {
  12. #region singleton
  13. static AccessTaskDao instance = null;
  14. static readonly object padlock = new object();
  15. private String conStr;
  16. private DbProviderFactory dbpf;
  17. AccessTaskDao()
  18. {
  19. notify(new Notification(Notification.VERBOSE.debug, "AccessTaskDao singleton call", this));
  20. dbpf = ((AccessFactory)AccessFactory.Instance).getDbpf();
  21. conStr = ((AccessFactory)AccessFactory.Instance).getConnectionString();
  22. }
  23. public static AccessTaskDao Instance
  24. {
  25. get
  26. {
  27. lock (padlock)
  28. {
  29. if (instance == null)
  30. {
  31. instance = new AccessTaskDao();
  32. }
  33. return instance;
  34. }
  35. }
  36. }
  37. #endregion
  38.  
  39. #region ITaskDao Membres
  40.  
  41. public bool insertTask(Task task)
  42. {
  43. if (task.Id > 0)
  44. {
  45. notify(new Notification(Notification.VERBOSE.opsResult, "Impossible d'insérer la tâche.", 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. StringBuilder str = new StringBuilder("INSERT INTO task (taskName, taskInfo, startDate");
  54. bool endDateValid = !task.EndDate.Equals(new DateTime(0L));
  55. if (endDateValid)
  56. {
  57. str.Append(", endDate");
  58. }
  59. bool planDateValid = !task.PlanDate.Equals(new DateTime(0L));
  60. if (planDateValid)
  61. {
  62. str.Append(", planDate");
  63. }
  64. str.Append(") VALUES ('");
  65. str.Append(AccessUtils.escapeAndTrim(task.TaskName));
  66. str.Append("','");
  67. str.Append(AccessUtils.escapeAndTrim(task.TaskInfo));
  68. str.Append("',");
  69. str.Append(AccessUtils.getAccessDate(task.StartDate.Equals(new DateTime(0L))?DateTime.Now:task.StartDate));
  70. if (endDateValid)
  71. {
  72. str.Append(",");
  73. str.Append(AccessUtils.getAccessDate(task.EndDate));
  74. }
  75. if (planDateValid)
  76. {
  77. str.Append(",");
  78. str.Append(AccessUtils.getAccessDate(task.PlanDate));
  79. }
  80. str.Append(")");
  81. dbDa.InsertCommand.CommandText = str.ToString();
  82. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  83. try
  84. {
  85. dbDa.InsertCommand.ExecuteNonQuery();
  86. }
  87. catch (Exception e)
  88. {
  89. notify(new Notification(Notification.VERBOSE.error, "Insertion d'une tâche", e, this));
  90. return false;
  91. }
  92. finally
  93. {
  94. dbCon.Close();
  95. }
  96. notify(new Notification(Notification.VERBOSE.opsResult, "La tâche \"" + task.TaskName + "\" est ajoutée", this));
  97. return true;
  98. }
  99.  
  100. public bool updateTask(Task task)
  101. {
  102. if (task.Id < 0)
  103. {
  104. return insertTask(task);
  105. }
  106. DbConnection dbCon = dbpf.CreateConnection();
  107. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  108. dbDa.UpdateCommand = dbCon.CreateCommand();
  109. dbCon.ConnectionString = conStr;
  110. dbCon.Open();
  111. StringBuilder str = new StringBuilder("UPDATE task SET ");
  112. str.Append("taskName='");
  113. str.Append(AccessUtils.escapeAndTrim(task.TaskName));
  114. str.Append("', taskInfo='");
  115. str.Append(AccessUtils.escapeAndTrim(task.TaskInfo));
  116. str.Append("'");
  117. /*if (!task.StartDate.Equals(new DateTime(0L)))
  118.   {
  119.   str.Append(", startDate=");
  120.   str.Append(AccessUtils.getAccessDate(task.StartDate));
  121.   }
  122.   if (!task.EndDate.Equals(new DateTime(0L)))
  123.   {
  124.   str.Append(", endDate=");
  125.   str.Append(AccessUtils.getAccessDate(task.EndDate));
  126.   }
  127.   if (!task.PlanDate.Equals(new DateTime(0L)))
  128.   {
  129.   str.Append(", planDate=");
  130.   str.Append(AccessUtils.getAccessDate(task.PlanDate));
  131.   }*/
  132. str.Append(", startDate=");
  133. str.Append((task.StartDate.Equals(new DateTime(0L))) ? "NULL" : AccessUtils.getAccessDate(task.StartDate));
  134. str.Append(", endDate=");
  135. str.Append((task.EndDate.Equals(new DateTime(0L))) ? "NULL" : AccessUtils.getAccessDate(task.EndDate));
  136. str.Append(", planDate=");
  137. str.Append((task.PlanDate.Equals(new DateTime(0L))) ? "NULL" : AccessUtils.getAccessDate(task.PlanDate));
  138. str.Append(" WHERE id=");
  139. str.Append(task.Id);
  140. dbDa.UpdateCommand.CommandText = str.ToString();
  141. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  142. try
  143. {
  144. dbDa.UpdateCommand.ExecuteNonQuery();
  145. }
  146. catch (Exception e)
  147. {
  148. notify(new Notification(Notification.VERBOSE.error, "Modification d'une tâche", e, this));
  149. return false;
  150. }
  151. finally
  152. {
  153. dbCon.Close();
  154. }
  155. notify(new Notification(Notification.VERBOSE.opsResult, "La tâche \"" + task.TaskName + "\" est modifiée", this));
  156. return true;
  157. }
  158. public bool deleteTask(int taskId)
  159. {
  160. if (taskId < 0)
  161. {
  162. notify(new Notification(Notification.VERBOSE.opsResult, "Impossible de supprimer la tâche.", this));
  163. return false;
  164. }
  165. DbConnection dbCon = dbpf.CreateConnection();
  166. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  167. dbDa.DeleteCommand = dbCon.CreateCommand();
  168. dbCon.ConnectionString = conStr;
  169. dbCon.Open();
  170. dbDa.DeleteCommand.CommandText = "DELETE FROM task WHERE id=" + taskId;
  171. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.DeleteCommand.CommandText, this));
  172. try
  173. {
  174. dbDa.DeleteCommand.ExecuteNonQuery();
  175. }
  176. catch (Exception e)
  177. {
  178. notify(new Notification(Notification.VERBOSE.error, "Suppression d'une tâche", e, this));
  179. return false;
  180. }
  181. finally
  182. {
  183. dbCon.Close();
  184. }
  185. notify(new Notification(Notification.VERBOSE.opsResult, "La tâche est supprimée", this));
  186. return true;
  187. }
  188.  
  189. public List<Task> loadTasks()
  190. {
  191. List<Task> tasks = new List<Task>();
  192. DbConnection dbCon = dbpf.CreateConnection();
  193. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  194. dbDa.SelectCommand = dbCon.CreateCommand();
  195. dbCon.ConnectionString = conStr;
  196. String str = "SELECT * FROM task ORDER BY startDate DESC";
  197. dbDa.SelectCommand.CommandText = str;
  198. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  199. DataTable tasksDt = new DataTable();
  200. try
  201. {
  202. dbDa.Fill(tasksDt);
  203. foreach (DataRow row in tasksDt.Rows)
  204. {
  205. tasks.Add(new Task(
  206. (int)row["id"],
  207. (row["startDate"] is DBNull) ? new DateTime(0L) : (DateTime)row["startDate"],
  208. (row["taskName"] is DBNull) ? "Non défini" : (String)row["taskName"],
  209. (row["planDate"] is DBNull) ? new DateTime(0L) : (DateTime)row["planDate"],
  210. (row["endDate"] is DBNull) ? new DateTime(0L) : (DateTime)row["endDate"],
  211. (row["taskInfo"] is DBNull) ? "Non défini" : (String)row["taskInfo"]));
  212. }
  213. }
  214. catch (Exception e)
  215. {
  216. notify(new Notification(Notification.VERBOSE.lowError,"Chargement des tâches", e, this));
  217. }
  218. tasksDt.Dispose();
  219. dbCon.Close();
  220. return tasks;
  221. }
  222.  
  223. #endregion
  224. }
  225. }

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 octets1719974311 03/07/2024 04:38:31
| _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/AccessTaskDao.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.