NoChangeConfigDao.cs
Description du code
NoChangeConfigDao.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# (NoChangeConfigDao.cs) (314 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.Common; using be.gaudry.observer; using be.gaudry.model.exceptions; using be.gaudry.view; namespace be.gaudry.bibliobrol.model.dao.mysql { public sealed class NoChangeConfigDao : Observable, IConfigDao { #region singleton static NoChangeConfigDao instance = null; private DbProviderFactory dbpf; private String conStr; NoChangeConfigDao() { dbpf = ((MySQLFactory)MySQLFactory.Instance).getDbpf(); conStr = ((MySQLFactory)MySQLFactory.Instance).getConnectionString(); } public static NoChangeConfigDao Instance { get { lock (padlock) { if (instance == null) { } return instance; } } } #endregion #region IConfigDao Members public List<BrolType> loadBrolTypes() { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; dbDa.SelectCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(typesDt); foreach (DataRow row in typesDt.Rows) { } } catch (Exception e) { } typesDt.Dispose(); dbCon.Close(); return types; } public Person loadOwner() { int ownerId; return(Int32.TryParse(loadConfig("ownerId"),out ownerId))?NoChangePersonDao.Instance.loadPerson(ownerId, false):new Person(); } public bool saveOwner(Person owner) { if (owner.Id < 0) { notify(new Notification(Notification.VERBOSE.error, "Impossible de sauver le propriétaire.", this)); return false; } return saveConfig("ownerId", owner.Id.ToString()); } public bool saveConfig(String configName, String configValue) { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.UpdateCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; dbCon.Open(); str.Append(MySQLUtils.escapeAndTrim(configValue)); str.Append("'"); str.Append(" WHERE configName='"); str.Append(MySQLUtils.escapeAndTrim(configName)); str.Append("'"); dbDa.UpdateCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this)); try { dbDa.UpdateCommand.ExecuteNonQuery(); } catch (Exception e) { return false; } finally { dbCon.Close(); } notify(new Notification(Notification.VERBOSE.opsResult, "La configuration est correctement modifiée", this)); return true; } public String loadConfig(String configName) { String configValue; DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; dbDa.SelectCommand.CommandText = "SELECT configValue FROM config WHERE configName='" + configName + "'"; notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this)); try { dbDa.Fill(dataTable); configValue = (String)dataTable.Rows[0]["configValue"]; } catch (Exception e) { configValue = ""; } dataTable.Dispose(); dbCon.Close(); return configValue; } /// <summary> /// Test if the persistance system is available /// </summary> public void testPersistance() { Splasher.Status = "Vérification de la base de données"; bool testPersistence = false; DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; dbDa.SelectCommand.CommandText = "SELECT id FROM type"; try { testPersistence = true; } catch (Exception) { } finally { dbCon.Close(); } if (testPersistence) { string version = loadConfig("persistanceVersion"); switch (version) { case "0.0.1.18": patch080103(); break; default: break; } } } /// <summary> /// insert new category, and return new id to the category object /// </summary> /// <param name="cat">(BrolCategory) category to insert</param> public int insertCategory(BrolCategory cat, BrolType type) { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; return insertCategory(cat, type, dbCon, dbDa); } /// <summary> /// insert new category, and return new id to the category object /// Use existing DbConnection and DbDataAdapter /// </summary> /// <param name="cat"></param> /// <param name="type"></param> /// <param name="dbCon"></param> /// <param name="dbDa"></param> internal int insertCategory(BrolCategory cat, BrolType type, DbConnection dbCon, DbDataAdapter dbDa) { str.Append("INSERT INTO category (name typeId) VALUES("); str.Append(cat.Name); str.Append(","); str.Append(type.Id); str.Append(");"); dbDa.InsertCommand = dbCon.CreateCommand(); dbDa.InsertCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this)); try { dbDa.InsertCommand.ExecuteNonQuery(); //bad smell code : may not work with concurent acces dbDa.InsertCommand.CommandText = "SELECT @@IDENTITY"; return (int)dbDa.InsertCommand.ExecuteScalar(); } catch (Exception e) { return -1; } } /// <summary> /// insert new insertBrolType, and return new id to the insertBrolType object /// </summary> /// <param name="cat">(BrolCategory) category to insert</param> public int insertBrolType(BrolType type) { DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.SelectCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; return insertBrolType(type, dbCon, dbDa); } /// <summary> /// insert new insertBrolType, and return new id to the insertBrolType object /// Use existing DbConnection and DbDataAdapter /// </summary> /// <param name="cat"></param> /// <param name="type"></param> /// <param name="dbCon"></param> /// <param name="dbDa"></param> internal int insertBrolType(BrolType type, DbConnection dbCon, DbDataAdapter dbDa) { str.Append("INSERT INTO type (name) VALUES("); /*str.Append(type.Id); str.Append(",");*/ str.Append(MySQLUtils.escapeAndTrim(type.Name)); str.Append(");"); dbDa.InsertCommand = dbCon.CreateCommand(); dbDa.InsertCommand.CommandText = str.ToString(); notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this)); try { dbDa.InsertCommand.ExecuteNonQuery(); //bad smell code : may not work with concurent acces dbDa.InsertCommand.CommandText = "SELECT @@IDENTITY"; return (int)dbDa.InsertCommand.ExecuteScalar(); } catch (Exception e) { return -1; } } #endregion #region db patches /// <summary> /// Adapt field size /// </summary> private void patch080103() { Splasher.Status = "Installation de la mise à jour 080103 de la base de données"; DbConnection dbCon = dbpf.CreateConnection(); DbDataAdapter dbDa = dbpf.CreateDataAdapter(); dbDa.UpdateCommand = dbCon.CreateCommand(); dbCon.ConnectionString = conStr; dbCon.Open(); dbDa.UpdateCommand.CommandText = "ALTER TABLE actor CHANGE roleValue roleValue VARCHAR( 100 )"; notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this)); try { int r = dbDa.UpdateCommand.ExecuteNonQuery(); //if (r==1) //{ dbDa.UpdateCommand.CommandText = "UPDATE `config` SET `configValue` = '0.0.1.19' WHERE `config`.`configName` = 'persistanceVersion' LIMIT 1 "; notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this)); r = dbDa.UpdateCommand.ExecuteNonQuery(); //} if (r == 1) { Splasher.Status = "La mise à jour 080103 de la base de données vient d'être appliquée."; } } catch (Exception e) { } finally { dbCon.Close(); } } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731754979 16/11/2024 12:02:59 |
| _ | 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/mysql/NoChangeConfigDao.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.