Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

AccessConfigDao.cs

Description du code

AccessConfigDao.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;
  5. using System.Data.Common;
  6. using be.gaudry.observer;
  7. using be.gaudry.model.exceptions;
  8. using be.gaudry.view;
  9.  
  10. namespace be.gaudry.bibliobrol.model.dao.msaccess
  11. {
  12. public sealed class AccessConfigDao : Observable, IConfigDao
  13. {
  14. #region singleton
  15. static AccessConfigDao instance = null;
  16. static readonly object padlock = new object();
  17. private DbProviderFactory dbpf;
  18. private String conStr;
  19. AccessConfigDao()
  20. {
  21. dbpf = ((AccessFactory)AccessFactory.Instance).getDbpf();
  22. conStr = ((AccessFactory)AccessFactory.Instance).getConnectionString();
  23. }
  24.  
  25. public static AccessConfigDao Instance
  26. {
  27. get
  28. {
  29. lock (padlock)
  30. {
  31. if (instance == null)
  32. {
  33. instance = new AccessConfigDao();
  34. }
  35. return instance;
  36. }
  37. }
  38. }
  39. #endregion
  40.  
  41. #region IConfigDao Members
  42.  
  43. public List<BrolType> loadBrolTypes()
  44. {
  45. List<BrolType> types = new List<BrolType>();
  46. DbConnection dbCon = dbpf.CreateConnection();
  47. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  48. dbDa.SelectCommand = dbCon.CreateCommand();
  49. dbCon.ConnectionString = conStr;
  50. StringBuilder str = new StringBuilder("SELECT id, name FROM type");
  51. dbDa.SelectCommand.CommandText = str.ToString();
  52. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  53. DataTable typesDt = new DataTable();
  54. try
  55. {
  56. dbDa.Fill(typesDt);
  57. foreach (DataRow row in typesDt.Rows)
  58. {
  59. types.Add(new BrolType((int)row["id"],(String)row["name"]));
  60. }
  61. }
  62. catch (Exception e)
  63. {
  64. notify(new Notification(Notification.VERBOSE.error, "Chargement des types", e, this));
  65. }
  66. typesDt.Dispose();
  67. dbCon.Close();
  68. return types;
  69. }
  70.  
  71. public Person loadOwner()
  72. {
  73. int ownerId;
  74. return(Int32.TryParse(loadConfig("ownerId"),out ownerId))?AccessPersonDao.Instance.loadPerson(ownerId, false):new Person();
  75. }
  76.  
  77. public bool saveOwner(Person owner)
  78. {
  79. if (owner.Id < 0)
  80. {
  81. notify(new Notification(Notification.VERBOSE.error, "Impossible de sauver le propriétaire.", this));
  82. return false;
  83. }
  84. return saveConfig("ownerId", owner.Id.ToString());
  85. }
  86.  
  87. public bool saveConfig(String configName, String configValue)
  88. {
  89.  
  90. DbConnection dbCon = dbpf.CreateConnection();
  91. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  92. dbDa.UpdateCommand = dbCon.CreateCommand();
  93. dbCon.ConnectionString = conStr;
  94. dbCon.Open();
  95. StringBuilder str = new StringBuilder("UPDATE config SET configValue='");
  96. str.Append(AccessUtils.escapeAndTrim(configValue));
  97. str.Append("'");
  98. str.Append(" WHERE configName='");
  99. str.Append(AccessUtils.escapeAndTrim(configName));
  100. str.Append("'");
  101. dbDa.UpdateCommand.CommandText = str.ToString();
  102. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  103. try
  104. {
  105. dbDa.UpdateCommand.ExecuteNonQuery();
  106. }
  107. catch (Exception e)
  108. {
  109. notify(new Notification(Notification.VERBOSE.error, "Modification de la configuration", e, this));
  110. return false;
  111. }
  112. finally
  113. {
  114. dbCon.Close();
  115. }
  116. notify(new Notification(Notification.VERBOSE.opsResult, "La configuration est correctement modifiée", this));
  117. return true;
  118. }
  119. public String loadConfig(String configName)
  120. {
  121. String configValue;
  122. DbConnection dbCon = dbpf.CreateConnection();
  123. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  124. dbDa.SelectCommand = dbCon.CreateCommand();
  125. dbCon.ConnectionString = conStr;
  126. dbDa.SelectCommand.CommandText = "SELECT configValue FROM config WHERE configName='" + configName + "'";
  127. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  128. DataTable dataTable = new DataTable();
  129. try
  130. {
  131. dbDa.Fill(dataTable);
  132. configValue = (String)dataTable.Rows[0]["configValue"];
  133. }
  134. catch (Exception e)
  135. {
  136. notify(new Notification(Notification.VERBOSE.error, "Chargement de la configuration", e, this));
  137. configValue = "";
  138. }
  139. dataTable.Dispose();
  140. dbCon.Close();
  141. return configValue;
  142. }
  143.  
  144. /// <summary>
  145. /// Test if the persistance system is available
  146. /// </summary>
  147. public void testPersistance()
  148. {
  149. Splasher.Status = "Vérification de la base de données";
  150. bool testPersistence = false;
  151. DbConnection dbCon = dbpf.CreateConnection();
  152. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  153. dbDa.SelectCommand = dbCon.CreateCommand();
  154. dbCon.ConnectionString = conStr;
  155. dbDa.SelectCommand.CommandText = "SELECT id FROM type";
  156. try
  157. {
  158. dbDa.Fill(new DataTable());
  159. testPersistence = true;
  160. }
  161. catch (Exception)
  162. {
  163. throw new PersistanceNotFoundException("Base de données Access (" + conStr + ")");
  164. }
  165. finally
  166. {
  167. dbCon.Close();
  168. }
  169. if (testPersistence)
  170. {
  171. string version = loadConfig("persistanceVersion");
  172. switch (version)
  173. {
  174. case "0.0.1.18":
  175. patch080103();
  176. break;
  177. default: break;
  178. }
  179. }
  180. }
  181.  
  182. /// <summary>
  183. /// insert new category, and return new id to the category object
  184. /// </summary>
  185. /// <param name="cat">(BrolCategory) category to insert</param>
  186. public int insertCategory(BrolCategory cat, BrolType type)
  187. {
  188. DbConnection dbCon = dbpf.CreateConnection();
  189. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  190. dbDa.SelectCommand = dbCon.CreateCommand();
  191. dbCon.ConnectionString = conStr;
  192. return insertCategory(cat, type, dbCon, dbDa);
  193. }
  194. /// <summary>
  195. /// insert new category, and return new id to the category object
  196. /// Use existing DbConnection and DbDataAdapter
  197. /// </summary>
  198. /// <param name="cat"></param>
  199. /// <param name="type"></param>
  200. /// <param name="dbCon"></param>
  201. /// <param name="dbDa"></param>
  202. internal int insertCategory(BrolCategory cat, BrolType type, DbConnection dbCon, DbDataAdapter dbDa)
  203. {
  204. StringBuilder str = new StringBuilder();
  205. str.Append("INSERT INTO category (name typeId) VALUES(");
  206. str.Append(cat.Name);
  207. str.Append(",");
  208. str.Append(type.Id);
  209. str.Append(");");
  210. dbDa.InsertCommand = dbCon.CreateCommand();
  211. dbDa.InsertCommand.CommandText = str.ToString();
  212. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  213. try
  214. {
  215. dbDa.InsertCommand.ExecuteNonQuery();
  216. //bad smell code : may not work with concurent acces
  217. dbDa.InsertCommand.CommandText = "SELECT @@IDENTITY";
  218. return (int)dbDa.InsertCommand.ExecuteScalar();
  219. }
  220. catch (Exception e)
  221. {
  222. notify(new Notification(Notification.VERBOSE.error, "Ajout d'une catégorie", e, this));
  223. return -1;
  224. }
  225. }
  226.  
  227.  
  228. /// <summary>
  229. /// insert new insertBrolType, and return new id to the insertBrolType object
  230. /// </summary>
  231. /// <param name="cat">(BrolCategory) category to insert</param>
  232. public int insertBrolType(BrolType type)
  233. {
  234. DbConnection dbCon = dbpf.CreateConnection();
  235. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  236. dbDa.SelectCommand = dbCon.CreateCommand();
  237. dbCon.ConnectionString = conStr;
  238. return insertBrolType(type, dbCon, dbDa);
  239. }
  240. /// <summary>
  241. /// insert new insertBrolType, and return new id to the insertBrolType object
  242. /// Use existing DbConnection and DbDataAdapter
  243. /// </summary>
  244. /// <param name="cat"></param>
  245. /// <param name="type"></param>
  246. /// <param name="dbCon"></param>
  247. /// <param name="dbDa"></param>
  248. internal int insertBrolType(BrolType type, DbConnection dbCon, DbDataAdapter dbDa)
  249. {
  250. StringBuilder str = new StringBuilder();
  251. str.Append("INSERT INTO type (name) VALUES(");
  252. /*str.Append(type.Id);
  253.   str.Append(",");*/
  254. str.Append(AccessUtils.escapeAndTrim(type.Name));
  255. str.Append(");");
  256. dbDa.InsertCommand = dbCon.CreateCommand();
  257. dbDa.InsertCommand.CommandText = str.ToString();
  258. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  259. try
  260. {
  261. dbDa.InsertCommand.ExecuteNonQuery();
  262. //bad smell code : may not work with concurent acces
  263. dbDa.InsertCommand.CommandText = "SELECT @@IDENTITY";
  264. return (int)dbDa.InsertCommand.ExecuteScalar();
  265. }
  266. catch (Exception e)
  267. {
  268. notify(new Notification(Notification.VERBOSE.error, "Ajout d'une catégorie", e, this));
  269. return -1;
  270. }
  271. }
  272. #endregion
  273.  
  274. #region db patches
  275.  
  276. /// <summary>
  277. /// Adapt field size
  278. /// </summary>
  279. private void patch080103()
  280. {
  281. Splasher.Status = "Installation de la mise à jour 080103 de la base de données";
  282. DbConnection dbCon = dbpf.CreateConnection();
  283. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  284. dbDa.UpdateCommand = dbCon.CreateCommand();
  285. dbCon.ConnectionString = conStr;
  286. dbCon.Open();
  287. dbDa.UpdateCommand.CommandText = "ALTER TABLE [actor] ALTER COLUMN [roleValue] TEXT(100)";
  288. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  289. try
  290. {
  291. int r = dbDa.UpdateCommand.ExecuteNonQuery();
  292. //if (r==1)
  293. //{
  294. dbDa.UpdateCommand.CommandText = "UPDATE [config] SET configValue = '0.0.1.19' WHERE configName = 'persistanceVersion'";
  295. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  296. r = dbDa.UpdateCommand.ExecuteNonQuery();
  297. //}
  298. if (r == 1)
  299. {
  300. Splasher.Status = "La mise à jour 080103 de la base de données vient d'être appliquée.";
  301. }
  302. }
  303. catch (Exception e)
  304. {
  305. notify(new Notification(Notification.VERBOSE.criticalError, e, this));
  306. }
  307. finally
  308. {
  309. dbCon.Close();
  310. }
  311. }
  312. #endregion
  313. }
  314. }

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 octets1719990838 03/07/2024 09:13:58
| _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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-bibliobrol-source-rf-model/dao/msaccess/AccessConfigDao.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.