No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

NoChangeTaskDao.cs

Description du code

NoChangeTaskDao.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.mysql
  9. {
  10. class NoChangeTaskDao : Observable, ITaskDao
  11. {
  12. #region singleton
  13. static NoChangeTaskDao instance = null;
  14. static readonly object padlock = new object();
  15. private String conStr;
  16. private DbProviderFactory dbpf;
  17. NoChangeTaskDao()
  18. {
  19. notify(new Notification(Notification.VERBOSE.debug, "AccessTaskDao singleton call", this));
  20. dbpf = ((MySQLFactory)MySQLFactory.Instance).getDbpf();
  21. conStr = ((MySQLFactory)MySQLFactory.Instance).getConnectionString();
  22. }
  23. public static NoChangeTaskDao Instance
  24. {
  25. get
  26. {
  27. lock (padlock)
  28. {
  29. if (instance == null)
  30. {
  31. instance = new NoChangeTaskDao();
  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(MySQLUtils.escapeAndTrim(task.TaskName));
  66. str.Append("','");
  67. str.Append(MySQLUtils.escapeAndTrim(task.TaskInfo));
  68. str.Append("',");
  69. str.Append(MySQLUtils.getAccessDate(task.StartDate.Equals(new DateTime(0L))?DateTime.Now:task.StartDate));
  70. if (endDateValid)
  71. {
  72. str.Append(",");
  73. str.Append(MySQLUtils.getAccessDate(task.EndDate));
  74. }
  75. if (planDateValid)
  76. {
  77. str.Append(",");
  78. str.Append(MySQLUtils.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(MySQLUtils.escapeAndTrim(task.TaskName));
  114. str.Append("', taskInfo='");
  115. str.Append(MySQLUtils.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" : MySQLUtils.getAccessDate(task.StartDate));
  134. str.Append(", endDate=");
  135. str.Append((task.EndDate.Equals(new DateTime(0L))) ? "NULL" : MySQLUtils.getAccessDate(task.EndDate));
  136. str.Append(", planDate=");
  137. str.Append((task.PlanDate.Equals(new DateTime(0L))) ? "NULL" : MySQLUtils.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/mysql/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1719993913 03/07/2024 10:05:13
| _utils0 octets1541007203 31/10/2018 18:33:23
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/model/dao/mysql/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csNoChangeImporterDao.cs27.14 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeExporterDao.cs33.69 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeSerieDao.cs6.22 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csMySQLFactory.cs3.75 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csNoChangeConfigDao.cs12.25 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangePersonDao.cs59.9 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeTaskDao.cs8.92 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeBrolDao.cs58.25 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csMySQLStatsDao.cs10.63 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csMySQLMediaBrolDao.cs50.51 Ko31/10/2018 18:33:18-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/mysql/NoChangeTaskDao.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.