MySQLMediaBrolDao.cs

Description du code

MySQLMediaBrolDao.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 System.Runtime.Serialization.Formatters.Binary;
  7. using System.IO;
  8. using be.gaudry.observer;
  9. using be.gaudry.bibliobrol.model.identity;
  10. using be.gaudry.model.exceptions;
  11.  
  12. namespace be.gaudry.bibliobrol.model.dao.mysql
  13. {
  14. public sealed class MySQLMediaBrolDao : Observable, IMediaBrolDao
  15. {
  16.  
  17. private String conStr;
  18.  
  19. #region singleton
  20. static MySQLMediaBrolDao instance = null;
  21. static readonly object padlock = new object();
  22. private DbProviderFactory dbpf;
  23. MySQLMediaBrolDao()
  24. {
  25. notify(new Notification(Notification.VERBOSE.debug,"AccessMediaBrolDao singleton call", this));
  26. dbpf = ((MySQLFactory)MySQLFactory.Instance).getDbpf();
  27. conStr = ((MySQLFactory)MySQLFactory.Instance).getConnectionString();
  28. }
  29. public static MySQLMediaBrolDao Instance
  30. {
  31. get
  32. {
  33. lock (padlock)
  34. {
  35. if (instance == null)
  36. {
  37. instance = new MySQLMediaBrolDao();
  38. }
  39. return instance;
  40. }
  41. }
  42. }
  43. #endregion
  44.  
  45. #region IMediaBrolDao Members
  46.  
  47. #region mediabrol
  48. public int insertMediaBrol(MediaBrol mediabrol)
  49. {
  50. StringBuilder str = new StringBuilder();
  51. int lastId = -1;
  52. if (mediabrol.Id <= 0)
  53. {
  54. DbConnection dbCon = dbpf.CreateConnection();
  55. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  56. dbDa.InsertCommand = dbCon.CreateCommand();
  57. dbCon.ConnectionString = conStr;
  58. dbCon.Open();
  59. bool insertionDateValid = (!mediabrol.InsertionDate.Equals(new DateTime(0L)));
  60. str.Append("INSERT INTO itemBiblio (biblioItemName, itemId, ownerId, mediaId, comment, localisation");
  61. if (insertionDateValid)
  62. str.Append(", insertionDate");
  63. str.Append(") VALUES('");
  64. str.Append(MySQLUtils.escapeAndTrim(mediabrol.Name));
  65. str.Append("',");
  66. str.Append(mediabrol.Brol.Id);
  67. str.Append(",");
  68. str.Append(mediabrol.Owner.Id);
  69. str.Append(",");
  70. str.Append(mediabrol.MediaType.Id);
  71. str.Append(",'");
  72. str.Append(MySQLUtils.escapeAndTrim(mediabrol.Comment));
  73. str.Append("','");
  74. str.Append(MySQLUtils.escapeAndTrim(mediabrol.Localisation));
  75. str.Append("',");
  76. str.Append(MySQLUtils.getAccessDate((insertionDateValid)?mediabrol.InsertionDate:DateTime.Now));
  77. str.Append(");");
  78. try
  79. {
  80. dbDa.InsertCommand.CommandText = str.ToString();
  81. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  82. if (dbDa.InsertCommand.ExecuteNonQuery() != 1)
  83. notify(new Notification(Notification.VERBOSE.error, "ERREUR Insertions multiples exemplaire", this));
  84. //bad smell code : may not work with concurent acces
  85. dbDa.InsertCommand.CommandText = "SELECT @@IDENTITY";
  86. lastId = (int)dbDa.InsertCommand.ExecuteScalar();
  87. mediabrol.Id = lastId;
  88. if (insertQualities(mediabrol, dbDa) == -1)
  89. notify(new Notification(Notification.VERBOSE.error, "ERREUR d'insertion des caractéristiques de media pour " + mediabrol.Name, this));
  90. }
  91. catch (Exception ex)
  92. {
  93. notify(new Notification(Notification.VERBOSE.error,"Insertion d'un exemplaire", ex, this));
  94. }
  95. dbCon.Close();
  96. }
  97. str = new StringBuilder("L'exemplaire \"");
  98. str.Append(mediabrol.Name);
  99. str.Append("\" de l'ouvrage \"");
  100. str.Append(mediabrol.Brol.Title);
  101. str.Append((lastId > 0) ? "\" est ajouté." : "\" ne peut être ajouté.");
  102. notify(new Notification(Notification.VERBOSE.opsResult, str.ToString(), this));
  103. return lastId;
  104. }
  105.  
  106. internal MediaBrol getMediaBrol(DataRow row, bool anonymous)
  107. {
  108. if (row["iid"] is DBNull) throw new BuildObjectException("No id found");
  109. //Load owner infos
  110. Person owner = new Person();
  111. if (!anonymous)
  112. {
  113. if (!(row["pid"] is DBNull))
  114. {
  115. owner.Id = (int)row["pid"];
  116. }
  117. if (!(row["lastName"] is DBNull))
  118. {
  119. owner.LastName = (String)row["lastName"];
  120. }
  121. if (!(row["firstName"] is DBNull))
  122. {
  123. owner.FirstName = (String)row["firstName"];
  124. }
  125. if (!(row["birthdate"] is DBNull))
  126. {
  127. owner.Birthdate = (DateTime)row["birthdate"];
  128. }
  129. }
  130. //load mediabrol infos
  131. MediaBrol mediabrol = new MediaBrol();
  132. mediabrol.Owner = owner;
  133. mediabrol.Id = (int)row["iid"];
  134. if (!(row["insertionDate"] is DBNull))
  135. {
  136. mediabrol.InsertionDate = (DateTime)row["insertionDate"];
  137. }
  138. if (!(row["biblioItemName"] is DBNull))
  139. {
  140. mediabrol.Name = (String)row["biblioItemName"];
  141. }
  142. if (!(row["comment"] is DBNull))
  143. {
  144. mediabrol.Comment = (String)row["comment"];
  145. }
  146. if (!(row["localisation"] is DBNull))
  147. {
  148. mediabrol.Localisation = (String)row["localisation"];
  149. }
  150. //load media infos
  151. if (!(row["mid"] is DBNull))
  152. {
  153. mediabrol.MediaType = new Media(
  154. (int)row["mid"],
  155. (row["name"] is DBNull) ? "" : (String)row["name"],
  156. (row["type"] is DBNull) ? new BrolType() : new BrolType((int)row["type"],"")
  157. );
  158. }
  159. return mediabrol;
  160. }
  161. private List<MediaBrol> loadSelectedMediaBrols(int id)
  162. {
  163. List<MediaBrol> mediabrols = new List<MediaBrol>();
  164. DbConnection dbCon = dbpf.CreateConnection();
  165. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  166. dbDa.SelectCommand = dbCon.CreateCommand();
  167. dbCon.ConnectionString = conStr;
  168. StringBuilder str = new StringBuilder("SELECT ");
  169. str.Append("i.id AS iid, p.id AS pid, m.id AS mid, ");// needed by MySQL to avoid having multiple id columns (it doesn't allows using p.id)
  170. str.Append("i.*, p.*, m.* FROM ");
  171. str.Append("(itemBiblio AS i");
  172. str.Append(" LEFT JOIN person AS p ON i.ownerId = p.id)");
  173. str.Append(" LEFT JOIN media AS m ON i.mediaId = m.id");
  174. str.Append(" WHERE i.id = ");
  175. str.Append(id);
  176. //todo : use another request to load qualities instead of join
  177. //todo : load borrows? NO : there are loades only if we click on borrows tabpage...
  178. dbDa.SelectCommand.CommandText = str.ToString();
  179. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  180. DataTable brolDt = new DataTable();
  181. MediaBrol mediabrol;
  182. try
  183. {
  184. dbDa.Fill(brolDt);
  185. foreach (DataRow brolRow in brolDt.Rows)
  186. {
  187. mediabrol = getMediaBrol(brolRow,false);
  188. try
  189. {
  190. mediabrol.Brol = NoChangeBrolDao.Instance.loadBrol((int)brolRow["itemId"], false);
  191. }
  192. catch (Exception eBrol)
  193. {
  194. notify(new Notification(Notification.VERBOSE.error,"Chargement des éléments", eBrol, this));
  195. }
  196. mediabrol.Qualities = loadQualitiesCommand(mediabrol.Id, dbDa);
  197. mediabrol.Borrowed = isBorrowed(mediabrol.Id, dbDa, dbCon);
  198. mediabrols.Add(mediabrol);
  199. }
  200. }
  201. catch (Exception eMedia)
  202. {
  203. notify(new Notification(Notification.VERBOSE.advancedOperation,"Chargement des media", eMedia, this));
  204.  
  205. }
  206. brolDt.Dispose();
  207. dbCon.Close();
  208. return mediabrols;
  209. }
  210. public MediaBrol loadMediaBrol(int id, bool editing)
  211. {
  212. List<MediaBrol> mediabrols = loadSelectedMediaBrols(id);
  213. /*int[] ids = { id };
  214.   List<MediaBrol> mediabrols = AccessImportExporter.Instance.loadSelectedMediaBrols(ids);*/
  215. if (mediabrols.Count > 0)
  216. {
  217. //if (editing) lockBrol(id);
  218. return mediabrols[0];
  219. }
  220. return new MediaBrol();
  221. }
  222. /// <summary>
  223. /// Load all mediabrols for a brol from the persistant layer.
  224. /// </summary>
  225. /// <param name="brol"></param>
  226. /// <param name="fields">list of fields to load</param>
  227. /// <returns>(DataTable) table with selected columns</returns>
  228. public DataTable loadMediaBrols(Brol brol, List<DAOUtils.MEDIABROL_FIELD> fields)
  229. {
  230. DbConnection dbCon = dbpf.CreateConnection();
  231. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  232. dbDa.SelectCommand = dbCon.CreateCommand();
  233. dbCon.ConnectionString = conStr;
  234. StringBuilder str = new StringBuilder("SELECT itemBiblio.id");
  235. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.name))
  236. str.Append(", itemBiblio.biblioItemName AS name");
  237. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.date))
  238. str.Append(", itemBiblio.insertionDate");
  239. bool owner = false;
  240. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.owner))
  241. {
  242. str.Append(", CONCAT_WS(' ',person.firstName,person.lastName) AS owner");
  243. owner = true;
  244. }
  245. str.Append(" FROM");
  246. if (owner)
  247. str.Append(" person RIGHT JOIN itemBiblio");
  248. if (owner)
  249. str.Append(" ON person.id = itemBiblio.ownerId");
  250. str.Append(" WHERE itemBiblio.itemId = ");
  251. str.Append(brol.Id);
  252. dbDa.SelectCommand.CommandText = str.ToString();
  253. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  254. DataTable brolDt = new DataTable();
  255. try
  256. {
  257. dbDa.Fill(brolDt);
  258. }
  259. catch (Exception e)
  260. {
  261. notify(new Notification(Notification.VERBOSE.error,"Chargement des exemplaires", e, this));
  262. }
  263. brolDt.Dispose();
  264. dbCon.Close();
  265. return brolDt;
  266. }
  267.  
  268. /// <summary>
  269. /// Load all available medias for a type from the Access database.
  270. /// i.e. for a film : DVD, VHS, CD, etc.
  271. /// </summary>
  272. /// <param name="typeId">(int) selected type (film, book, etc.)</param>
  273. /// <returns>List of Medias</returns>
  274. public List<Media> loadMedias(int typeId)
  275. {
  276. List<Media> medias = new List<Media>();
  277. DbConnection dbCon = dbpf.CreateConnection();
  278. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  279. dbDa.SelectCommand = dbCon.CreateCommand();
  280. dbCon.ConnectionString = conStr;
  281. StringBuilder str = new StringBuilder("SELECT media.id AS mi, media.name AS mn, type.id AS ti, type.name AS tn");
  282. str.Append(" FROM type RIGHT JOIN media ON type.id = media.type");
  283. str.Append(" WHERE type.id = ");
  284. str.Append(typeId);
  285. dbDa.SelectCommand.CommandText = str.ToString();
  286. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  287. DataTable brolDt = new DataTable();
  288. try
  289. {
  290. dbDa.Fill(brolDt);
  291. }
  292. catch (Exception e)
  293. {
  294. notify(new Notification(Notification.VERBOSE.error,"Chargement des media", e, this));
  295. }
  296. String mName;
  297. BrolType brolType;
  298. foreach (DataRow brolRow in brolDt.Rows)
  299. {
  300. mName = (brolRow["mn"] is DBNull) ? "" : (String)brolRow["mn"];
  301. brolType = (brolRow["ti"] is DBNull) ? new BrolType() : new BrolType((int)brolRow["ti"], (String)brolRow["tn"]);
  302. medias.Add(new Media((int)brolRow["mi"], mName, brolType));
  303. }
  304. brolDt.Dispose();
  305. dbCon.Close();
  306. return medias;
  307. }
  308.  
  309.  
  310. /// <summary>
  311. /// Load brols value objects (only selected fields) for a type from the Access database.
  312. /// </summary>
  313. /// <param name="fields">List of fields to load for the brols</param>
  314. /// <param name="typeId">
  315. /// (int) selected type (film, book, etc.)
  316. /// 0 allow to load all types
  317. /// </param>
  318. /// <returns>DataTable with selected fields for Brols</returns>
  319. public DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId)
  320. {
  321. return loadDataTableVos(fields, typeId, null);
  322. }
  323.  
  324. /// <summary>
  325. /// Load brols value objects (only selected fields) for a type from the Access database.
  326. /// </summary>
  327. /// <param name="fields">List of fields to load for the brols</param>
  328. /// <param name="typeId">
  329. /// (int) selected type (film, book, etc.)
  330. /// 0 allow to load all types
  331. /// </param>
  332. /// <param name="categories">List of categories to match</param>
  333. /// <returns>DataTable with selected fields for Brols</returns>
  334. public DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories)
  335. {
  336. return loadDataTableVos(fields, typeId, categories, 0);
  337. }
  338.  
  339. /// <summary>
  340. /// Load brols value objects (only selected fields) for a type from the Access database.
  341. /// </summary>
  342. /// <param name="fields">List of fields to load for the brols</param>
  343. /// <param name="typeId">
  344. /// (int) selected type (film, book, etc.)
  345. /// 0 allow to load all types
  346. /// </param>
  347. /// <param name="categories">List of categories to match</param>
  348. /// <param name="mediaId">media to match</param>
  349. /// <returns>DataTable with selected fields for Brols</returns>
  350. public DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories, int mediaId)
  351. {
  352. return loadDataTableVos(fields, typeId, categories, mediaId, "");
  353. }
  354.  
  355. /// <summary>
  356. /// Load brols value objects (only selected fields) for a type from the Access database.
  357. /// </summary>
  358. /// <param name="fields">List of fields to load for the brols</param>
  359. /// <param name="typeId">
  360. /// (int) selected type (film, book, etc.)
  361. /// 0 allow to load all types
  362. /// </param>
  363. /// <param name="categories">List of categories to match</param>
  364. /// <param name="mediaId">media to match</param>
  365. /// <param name="title">(String) string to find into brol's title</param>
  366. /// <returns>DataTable with selected fields for Brols</returns>
  367. public DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories, int mediaId, string title)
  368. {
  369. bool searchCategories = (categories != null && categories.Count > 0);
  370. DbConnection dbCon = dbpf.CreateConnection();
  371. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  372. dbDa.SelectCommand = dbCon.CreateCommand();
  373. dbCon.ConnectionString = conStr;
  374. StringBuilder str = new StringBuilder("SELECT itemBiblio.id");
  375. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.name))
  376. str.Append(", itemBiblio.biblioItemName");
  377. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.i_title))
  378. str.Append(", item.itemTitle");
  379. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.i_date))
  380. str.Append(", item.pubDate");
  381. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.date))
  382. str.Append(", itemBiblio.insertionDate");
  383. bool owner = false;
  384. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.owner))
  385. {
  386. str.Append(", CONCAT_WS(' ',person.firstName,person.lastName) AS owner");
  387. owner = true;
  388. }
  389. if (fields.Contains(DAOUtils.MEDIABROL_FIELD.brolId))
  390. str.Append(", item.id");
  391. str.Append(" FROM");
  392. if (owner)
  393. str.Append(" person RIGHT JOIN (");
  394. if (searchCategories)
  395. str.Append(" (categoryItemRelation INNER JOIN item ON categoryItemRelation.itemId = item.id)");
  396. else
  397. str.Append(" item");
  398. str.Append(" INNER JOIN itemBiblio ON item.id = itemBiblio.itemId");
  399. if (owner)
  400. str.Append(") ON person.id = itemBiblio.ownerId");
  401. str.Append(" WHERE item.id>0");
  402. if (typeId > 0)
  403. {
  404. str.Append(" AND item.typeId=");
  405. str.Append(typeId);
  406. if (searchCategories)
  407. {
  408. str.Append(" AND categoryItemRelation.categoryId IN(0");
  409. foreach(BrolCategory cat in categories)
  410. {
  411. str.Append(","+cat.Id);
  412. }
  413. str.Append(")");
  414. }
  415. if (mediaId>0)
  416. {
  417. str.Append(" AND itemBiblio.mediaId =");
  418. str.Append(mediaId);
  419. }
  420. }
  421. if (!String.Empty.Equals(title))
  422. {
  423. str.Append(" AND item.itemTitle LIKE ('");
  424. str.Append(MySQLUtils.escapeAndTrim(title));
  425. str.Append("')");
  426. }
  427. str.Append(" ORDER BY item.itemTitle ASC");
  428. dbDa.SelectCommand.CommandText = str.ToString();
  429. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  430. DataTable brolDt = new DataTable();
  431. try
  432. {
  433. dbDa.Fill(brolDt);
  434. }
  435. catch (Exception e)
  436. {
  437. notify(new Notification(Notification.VERBOSE.error, "Chargement des media", e, this));
  438. }
  439. brolDt.Dispose();
  440. dbCon.Close();
  441. return brolDt;
  442. }
  443.  
  444. public bool updateMediaBrol(MediaBrol mediabrol)
  445. {
  446. bool updated = true;
  447. DbConnection dbCon = dbpf.CreateConnection();
  448. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  449. dbDa.UpdateCommand = dbCon.CreateCommand();
  450. dbDa.InsertCommand = dbCon.CreateCommand();
  451. dbDa.DeleteCommand = dbCon.CreateCommand();
  452. dbCon.ConnectionString = conStr;
  453. dbCon.Open();
  454. StringBuilder str = new StringBuilder();
  455. try
  456. {
  457. str.Append("UPDATE itemBiblio SET biblioItemName='");
  458. str.Append(MySQLUtils.escapeAndTrim(mediabrol.Name));
  459. str.Append("', itemId=");
  460. str.Append(mediabrol.Brol.Id);
  461. str.Append(", ownerId=");
  462. str.Append(mediabrol.Owner.Id);
  463. str.Append(", mediaId=");
  464. str.Append(mediabrol.MediaType.Id);
  465. str.Append(", comment='");
  466. str.Append(MySQLUtils.escapeAndTrim(mediabrol.Comment));
  467. str.Append("', localisation='");
  468. str.Append(MySQLUtils.escapeAndTrim(mediabrol.Localisation));
  469. str.Append("'");
  470. if (!mediabrol.InsertionDate.Equals(new DateTime(0L)))
  471. {
  472. str.Append(", insertionDate=");
  473. str.Append(MySQLUtils.getAccessDate(mediabrol.InsertionDate));
  474. }
  475. str.Append(" WHERE id = ");
  476. str.Append(mediabrol.Id);
  477. dbDa.UpdateCommand.CommandText = str.ToString();
  478. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  479. int result = dbDa.UpdateCommand.ExecuteNonQuery();
  480. if (result < 1) updated = false;
  481. if (result > 1)
  482. notify(new Notification(Notification.VERBOSE.error, "ERREUR modifications multiples exemplaire", this));
  483. //todo : check multiple insertion sql request
  484. if (mediabrol.Qualities != null)
  485. {
  486. foreach (Quality q in mediabrol.Qualities)
  487. {
  488. switch (q.Status)
  489. {
  490. case STATUS.toAdd:
  491. str = new StringBuilder("INSERT INTO itemBiblioQualityRelation (itemBiblioId,qualityId) VALUES(");
  492. str.Append(mediabrol.Id);
  493. str.Append(",");
  494. str.Append(q.Id);
  495. str.Append(")");
  496. dbDa.InsertCommand.CommandText = str.ToString();
  497. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  498. dbDa.InsertCommand.ExecuteNonQuery();
  499. break;
  500. case STATUS.toDelete:
  501. StringBuilder strDel = new StringBuilder("DELETE FROM itemBiblioQualityRelation WHERE itemBiblioId = ");
  502. strDel.Append(mediabrol.Id);
  503. strDel.Append(" AND qualityId = ");
  504. strDel.Append(q.Id);
  505. dbDa.DeleteCommand.CommandText = strDel.ToString();
  506. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.DeleteCommand.CommandText, this));
  507. dbDa.DeleteCommand.ExecuteNonQuery();
  508. break;
  509. }
  510. }
  511. }
  512. }
  513. catch (Exception ex)
  514. {
  515. notify(new Notification(Notification.VERBOSE.error, "Insertion d'un exemplaire", ex, this));
  516. updated = false;
  517. }
  518. dbCon.Close();
  519. str = new StringBuilder("L'exemplaire \"");
  520. str.Append(mediabrol.Name);
  521. str.Append("\" de l'ouvrage \"");
  522. str.Append(mediabrol.Brol.Title);
  523. str.Append((updated)?"\" est mis à jour.":"\" ne peut être mis à jour.");
  524. notify(new Notification(Notification.VERBOSE.opsResult, str.ToString(), this));
  525. return updated;
  526. }
  527.  
  528. public bool lockMediaBrol(int id)
  529. {
  530. notify(new Notification(Notification.VERBOSE.lowError, "not implemented", this));
  531. throw new Exception("The method or operation is not implemented.");
  532.  
  533. }
  534.  
  535. public void unlockMediaBrol(int id)
  536. {
  537. notify(new Notification(Notification.VERBOSE.lowError, "not implemented", this));
  538. }
  539. /// <summary>
  540. /// If no currents borrows,
  541. /// delete a mediabrol, all associated borrows, and all qualities relations
  542. /// </summary>
  543. /// <param name="mediabrolId"></param>
  544. /// <param name="deleteBrol">Set true to delete associated brol</param>
  545. /// <returns></returns>
  546. public bool deleteMediaBrol(int mediabrolId, String title, bool deleteBrol)
  547. {
  548. bool deleted = false;
  549. StringBuilder str = new StringBuilder("L'exemplaire n°");
  550. str.Append(mediabrolId);
  551. str.Append(" \"");
  552. str.Append(title);
  553. if (cleanBorrows(mediabrolId, false) > -1)
  554. {
  555. DbConnection dbCon = dbpf.CreateConnection();
  556. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  557. dbDa.DeleteCommand = dbCon.CreateCommand();
  558. dbCon.ConnectionString = conStr;
  559. dbCon.Open();
  560. String strDel = "DELETE FROM itemBiblioQualityRelation WHERE itemBiblioId =" + mediabrolId;
  561. notify(new Notification(Notification.VERBOSE.persistentOperation, strDel, this));
  562. dbDa.DeleteCommand.CommandText = strDel;
  563. dbDa.DeleteCommand.ExecuteNonQuery();
  564. int brolId = 0;
  565. if (deleteBrol)
  566. {
  567. //get brol id
  568. strDel = "SELECT itemId FROM itemBiblio WHERE id =" + mediabrolId;
  569. notify(new Notification(Notification.VERBOSE.persistentOperation, strDel, this));
  570. dbDa.SelectCommand = dbCon.CreateCommand();
  571. dbDa.SelectCommand.CommandText = strDel;
  572. brolId = (int)dbDa.SelectCommand.ExecuteScalar();
  573. }
  574. strDel = "DELETE FROM itemBiblio WHERE id =" + mediabrolId;
  575. notify(new Notification(Notification.VERBOSE.persistentOperation, strDel, this));
  576. dbDa.DeleteCommand.CommandText = strDel;
  577. dbDa.DeleteCommand.ExecuteNonQuery();
  578. if (deleteBrol)
  579. {
  580. strDel = "SELECT COUNT(id) FROM itemBiblio WHERE itemId =" + brolId;
  581. notify(new Notification(Notification.VERBOSE.persistentOperation, strDel, this));
  582. dbDa.SelectCommand = dbCon.CreateCommand();
  583. dbDa.SelectCommand.CommandText = strDel;
  584. //test if we have more than this mediabrol for this brol
  585. if ((int)dbDa.SelectCommand.ExecuteScalar() == 0)
  586. {
  587. //call accessbroldao to
  588. //delete this brol
  589. NoChangeBrolDao.Instance.deleteBrol(new Brol(brolId,title,""));
  590. }
  591. }
  592. dbCon.Close();
  593. deleted = true;
  594. str.Append("\" est supprimé.");
  595. }
  596. else
  597. {
  598. str.Append("\" ne peut être supprimé.");
  599. str.AppendLine("\nIl faut d'abord clôturer l'emprunt en cours pour cet exemplaire.");
  600. }
  601. notify(new Notification(Notification.VERBOSE.opsResult, str.ToString(), this));
  602. return deleted;
  603. }
  604. /// <summary>
  605. /// If no currents borrows,
  606. /// delete a mediabrol, all associated borrows, and all qualities relations
  607. /// </summary>
  608. /// <param name="mediabrol"></param>
  609. /// <returns></returns>
  610. public bool deleteMediaBrol(MediaBrol mediabrol)
  611. {
  612. return deleteMediaBrol(mediabrol.Id, mediabrol.Brol.Title, false);
  613. }
  614. #endregion
  615.  
  616. #region borrows
  617. public List<Borrow> loadBorrows(Person person)
  618. {
  619. notify(new Notification(Notification.VERBOSE.lowError, "not implemented", this));
  620. throw new Exception("The method or operation is not implemented.");
  621. }
  622.  
  623. /// <summary>
  624. /// Load borrows and fill a DataTable.
  625. /// If mediabrolId equals 0, all borrows are loaded.
  626. /// </summary>
  627. /// <param name="mediabrolId">(int) Selected mediabrol id</param>
  628. /// <param name="borrowFields">List of fields to load for the borrows</param>
  629. /// <param name="typeId">
  630. /// (int) selected type (film, book, etc.)
  631. /// 0 allow to load all types
  632. /// </param>
  633. /// <param name="title">(String) string to find into brol's title</param>
  634. /// <returns>(DataTable) DataTable with borrows</returns>
  635. public DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> fields, int typeId, bool closed, string title)
  636. {
  637. DbConnection dbCon = dbpf.CreateConnection();
  638. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  639. dbDa.SelectCommand = dbCon.CreateCommand();
  640. dbCon.ConnectionString = conStr;
  641. StringBuilder str = new StringBuilder("SELECT ");
  642. if (fields.Contains(DAOUtils.BORROW_FIELD.id))
  643. str.Append("itemBiblio.id");
  644. else
  645. str.Append("borrow.id");
  646. if (fields.Contains(DAOUtils.BORROW_FIELD.type))
  647. str.Append(", type.name as typeName");
  648. if (fields.Contains(DAOUtils.BORROW_FIELD.borrower))
  649. str.Append(" ,CONCAT_WS(' ',person.firstName,person.lastName) AS borrower");
  650. if (fields.Contains(DAOUtils.BORROW_FIELD.name))
  651. str.Append(", biblioItemName AS name");
  652. if (fields.Contains(DAOUtils.BORROW_FIELD.startDate))
  653. str.Append(" ,borrow.startDate");
  654. if (fields.Contains(DAOUtils.BORROW_FIELD.endDate))
  655. str.Append(" ,borrow.endDate");
  656. if (fields.Contains(DAOUtils.BORROW_FIELD.planDate))
  657. str.Append(" ,borrow.planDate");
  658. if (fields.Contains(DAOUtils.BORROW_FIELD.comment))
  659. str.Append(" ,borrow.comment");
  660. if (fields.Contains(DAOUtils.BORROW_FIELD.title))
  661. str.Append(" ,item.itemTitle AS title");
  662. if (fields.Contains(DAOUtils.BORROW_FIELD.brolId))
  663. str.Append(" ,item.id AS brolId");
  664. str.Append(" FROM ");
  665. /*if (fields.Contains(DAOUtils.BORROW_FIELD.title))
  666.   {*/
  667. str.Append("(person INNER JOIN ((borrow");
  668. str.Append(" LEFT JOIN itemBiblio ON borrow.itemBiblioId = itemBiblio.id)");
  669. str.Append(" LEFT JOIN item ON itemBiblio.itemId = item.id)");
  670. str.Append(" ON person.id = borrow.personId)");
  671. if (fields.Contains(DAOUtils.BORROW_FIELD.type))
  672. str.Append(" LEFT JOIN type ON item.typeId = type.id");
  673. /*}
  674.   else
  675.   {
  676.   str.Append("(person RIGHT JOIN borrow ON person.id = borrow.personId)");
  677.   str.Append(" LEFT JOIN itemBiblio ON borrow.itemBiblioId = itemBiblio.id");
  678.   }*/
  679. str.Append(" WHERE itemBiblio.id>0");
  680. if (typeId > 0)
  681. {
  682. str.Append(" AND item.typeId = ");
  683. str.Append(typeId);
  684. }
  685. if (mediabrolId > 0)
  686. {
  687. str.Append(" AND itemBiblio.id = ");
  688. str.Append(mediabrolId);
  689. }
  690. if (!closed)
  691. {
  692. str.Append(" AND borrow.endDate IS NULL ");
  693. }
  694. if (!String.Empty.Equals(title))
  695. {
  696. str.Append(" AND item.itemTitle LIKE ('");
  697. str.Append(MySQLUtils.escapeAndTrim(title));
  698. str.Append("')");
  699. }
  700. str.Append(" ORDER BY borrow.startDate DESC");
  701. dbDa.SelectCommand.CommandText = str.ToString();
  702. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  703. DataTable brolDt = new DataTable();
  704. try
  705. {
  706. dbDa.Fill(brolDt);
  707. }
  708. catch (System.Data.OleDb.OleDbException e)
  709. {
  710. notify(new Notification(Notification.VERBOSE.criticalError, "Chargement des emprunts", e, this));
  711. }
  712. dbCon.Close();
  713. return brolDt;
  714. }
  715. /// <summary>
  716. /// Load selected borrow
  717. /// </summary>
  718. /// <param name="mediabrol"></param>
  719. /// <returns></returns>
  720. public Borrow loadBorrow(int borrowId)
  721. {
  722. Borrow borrow;
  723. DbConnection dbCon = dbpf.CreateConnection();
  724. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  725. dbDa.SelectCommand = dbCon.CreateCommand();
  726. dbCon.ConnectionString = conStr;
  727. StringBuilder str = new StringBuilder("SELECT person.*, borrow.*");
  728. str.Append(" FROM (person RIGHT JOIN borrow ON person.id = borrow.personId)");
  729. str.Append(" LEFT JOIN itemBiblio ON borrow.itemBiblioId = itemBiblio.id");
  730. str.Append(" WHERE borrow.id = ");
  731. str.Append(borrowId);
  732. dbDa.SelectCommand.CommandText = str.ToString();
  733. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  734. DataTable brolDt = new DataTable();
  735. try
  736. {
  737. dbDa.Fill(brolDt);
  738. }
  739. catch (Exception e)
  740. {
  741. notify(new Notification(Notification.VERBOSE.lowError, "Aucun emprunt à charger (ou alors la table est ouverte par un autre utilisateur)", e, this));
  742. //we may have exception if we have _ to fill
  743. }
  744. DataRow row = brolDt.Rows[0];
  745. borrow = new Borrow(
  746. borrowId,
  747. (row["itemBiblioId"] is DBNull) ? 0 : (int)row["itemBiblioId"],
  748. (row["startDate"] is DBNull) ? new DateTime(0L) : (DateTime)row["startDate"],
  749. (row["endDate"] is DBNull) ? new DateTime(0L) : (DateTime)row["endDate"],
  750. (row["planDate"] is DBNull) ? new DateTime(0L) : (DateTime)row["planDate"],
  751. getBorrower(row),
  752. (row["comment"] is DBNull) ? "" : (String)row["comment"]
  753. );
  754. brolDt.Dispose();
  755. dbCon.Close();
  756. return borrow;
  757. }
  758. private Person getBorrower(DataRow row)
  759. {
  760. if (row["person.id"] is DBNull || row["lastName"] is DBNull)
  761. return new Person();
  762. Person p = new Person((int)row["person.id"], (String)row["lastName"]);
  763. try
  764. {
  765.  
  766. if (!(row["firstName"] is DBNull))
  767. {
  768. p.FirstName = (String)row["firstName"];
  769. }
  770. if (!(row["personLocked"] is DBNull))
  771. {
  772. p.Edited = !row["personLocked"].ToString().Equals("False");
  773. }
  774. if (!(row["sex"] is DBNull))
  775. {
  776. SEX sex;
  777. try
  778. {
  779. sex = (SEX)Enum.Parse(typeof(SEX), (String)row["sex"], false);
  780. }
  781. catch (Exception)
  782. {
  783. sex = SEX._;
  784. }
  785. p.Sex = sex;
  786. }
  787. if (!(row["birthdate"] is DBNull))
  788. {
  789. p.Birthdate = (DateTime)row["birthdate"];
  790. }
  791. }
  792. catch (Exception e)
  793. {
  794. notify(new Notification(Notification.VERBOSE.error,"Chargement de l'emprunteur", e, this));
  795. }
  796. return p;
  797. }
  798. private bool isBorrowed(int mediabrolId, DbDataAdapter dbDa, DbConnection dbCon)
  799. {
  800. String str = String.Format("SELECT COUNT(0) FROM borrow WHERE itemBiblioId = {0} AND endDate IS NULL ", mediabrolId);
  801.  
  802. if(dbDa.SelectCommand==null)
  803. dbDa.SelectCommand = dbCon.CreateCommand();
  804. dbDa.SelectCommand.CommandText = str;
  805.  
  806. bool conOpen = dbCon.State.Equals(ConnectionState.Open);
  807. if (!conOpen)
  808. dbCon.Open();
  809. int r = (int)(Int64)dbDa.SelectCommand.ExecuteScalar();
  810. notify(new Notification(Notification.VERBOSE.debug, String.Format("{0}\n\nResult : {1}",dbDa.SelectCommand.CommandText,r), this));
  811. if (!conOpen)
  812. dbCon.Close();
  813. return r > 0;
  814. }
  815. /// <summary>
  816. /// Start a borrow if not borrowed
  817. /// </summary>
  818. /// <param name="mediabrolId">(int) id of the mediabrol to borrow</param>
  819. /// <param name="borrowerId">(int) id of the borrower</param>
  820. /// <returns></returns>
  821. public bool startBorrow(int mediabrolId, int borrowerId)
  822. {
  823. DbConnection dbCon = dbpf.CreateConnection();
  824. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  825. dbDa.InsertCommand = dbCon.CreateCommand();
  826. dbCon.ConnectionString = conStr;
  827. dbCon.Open();
  828.  
  829. if (isBorrowed(mediabrolId, dbDa, dbCon)) return false;
  830. StringBuilder str = new StringBuilder();
  831. str.Append("INSERT INTO borrow (itemBiblioId,personId,startDate) VALUES (");
  832. str.Append(mediabrolId);
  833. str.Append(", ");
  834. str.Append(borrowerId);
  835. str.Append(", ");
  836. str.Append(MySQLUtils.getAccessDate(DateTime.Now));
  837. str.Append(")");
  838. dbDa.InsertCommand.CommandText = str.ToString();
  839. try
  840. {
  841. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.InsertCommand.CommandText, this));
  842. dbDa.InsertCommand.ExecuteNonQuery();
  843. }
  844. catch (Exception ex)
  845. {
  846. notify(new Notification(Notification.VERBOSE.error, "Insertion d'un emprunt", ex, this));
  847. return false;
  848. }
  849. finally
  850. {
  851. dbCon.Close();
  852. }
  853. return true;
  854. }
  855.  
  856. public bool stopBorrow(int borrowId)
  857. {
  858. DbConnection dbCon = dbpf.CreateConnection();
  859. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  860. dbDa.UpdateCommand = dbCon.CreateCommand();
  861. dbCon.ConnectionString = conStr;
  862. dbCon.Open();
  863. StringBuilder str = new StringBuilder("UPDATE borrow SET endDate=");
  864. str.Append(MySQLUtils.getAccessDate(DateTime.Now));
  865. str.Append(" WHERE id=");
  866. str.Append(borrowId);
  867. dbDa.UpdateCommand.CommandText = str.ToString();
  868. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  869. try
  870. {
  871. dbDa.UpdateCommand.ExecuteNonQuery();
  872. }
  873. catch (Exception e)
  874. {
  875. notify(new Notification(Notification.VERBOSE.error, "Retour d'emprunt", e, this));
  876. return true;
  877. }
  878. finally
  879. {
  880. dbCon.Close();
  881. }
  882. return true;
  883. }
  884.  
  885. public bool stopBorrow(MediaBrol mediabrol)
  886. {
  887. DbConnection dbCon = dbpf.CreateConnection();
  888. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  889. dbDa.UpdateCommand = dbCon.CreateCommand();
  890. dbCon.ConnectionString = conStr;
  891. dbCon.Open();
  892. dbDa.UpdateCommand.CommandText = String.Format(
  893. "UPDATE borrow SET endDate={0} WHERE id=(SELECT id FROM borrow WHERE itemBiblioId = {1} AND endDate IS NULL)",
  894. MySQLUtils.getAccessDate(DateTime.Now),
  895. mediabrol.Id
  896. );
  897. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  898. try
  899. {
  900. dbDa.UpdateCommand.ExecuteNonQuery();
  901. }
  902. catch (Exception e)
  903. {
  904. notify(new Notification(Notification.VERBOSE.error, "Retour d'emprunt", e, this));
  905. return true;
  906. }
  907. finally
  908. {
  909. dbCon.Close();
  910. }
  911. return true;
  912. }
  913.  
  914. /// <summary>
  915. /// Delete all borrows for a mediabrol
  916. /// </summary>
  917. /// <param name="mediabrolId">(int) mediabrol identifier</param>
  918. public int cleanBorrows(int mediabrolId, bool forceDelete)
  919. {
  920. int result = -1;
  921. DbConnection dbCon = dbpf.CreateConnection();
  922. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  923. dbDa.SelectCommand = dbCon.CreateCommand();
  924. dbDa.DeleteCommand = dbCon.CreateCommand();
  925. dbCon.ConnectionString = conStr;
  926. dbCon.Open();
  927. StringBuilder str = new StringBuilder("SELECT COUNT(id) FROM borrow WHERE itemBiblioId =");
  928. str.Append(mediabrolId);
  929. str.Append(" AND endDate IS Null");
  930. dbDa.SelectCommand.CommandText = str.ToString();
  931. result = (int)dbDa.SelectCommand.ExecuteScalar();
  932. str.AppendLine("\nResult of this operation : ");
  933. str.Append(result);
  934. notify(new Notification(Notification.VERBOSE.persistentOperation, str.ToString(), this));
  935. if ((result > 0) && (!forceDelete))
  936. {
  937. notify(new Notification(Notification.VERBOSE.lowError, "Il n'est pas possible de supprimer l'exemplaire car il est en prêt", this));
  938. result = -1;
  939. }
  940. else
  941. {
  942. str = new StringBuilder("DELETE FROM borrow WHERE itemBiblioId =");
  943. str.Append(mediabrolId);
  944. notify(new Notification(Notification.VERBOSE.persistentOperation, str.ToString(), this));
  945. dbDa.DeleteCommand.CommandText = str.ToString();
  946. result = dbDa.DeleteCommand.ExecuteNonQuery();
  947. }
  948. dbCon.Close();
  949. return result;
  950. }
  951. /// <summary>
  952. /// Delete selected borrow
  953. /// </summary>
  954. /// <param name="selectedBorrowId">(int) borrow identifier</param>
  955. public void cleanBorrow(int selectedBorrowId)
  956. {
  957. DbConnection dbCon = dbpf.CreateConnection();
  958. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  959. dbDa.DeleteCommand = dbCon.CreateCommand();
  960. dbCon.ConnectionString = conStr;
  961. dbCon.Open();
  962. String str = "DELETE FROM borrow WHERE id =" + selectedBorrowId;
  963. notify(new Notification(Notification.VERBOSE.persistentOperation, str, this));
  964. dbDa.DeleteCommand.CommandText = str;
  965. int result = dbDa.DeleteCommand.ExecuteNonQuery();
  966. dbCon.Close();
  967. }
  968. /// <summary>
  969. /// Update a borrow
  970. /// </summary>
  971. /// <param name="borrow"></param>
  972. public bool updateBorrow(Borrow borrow)
  973. {
  974. if (borrow.Borrower == null ||
  975. borrow.Borrower.Id <= 0 ||
  976. borrow.MediabrolId <= 0)
  977. {
  978. notify(new Notification(Notification.VERBOSE.error, "Impossible de sauver les modifications apportées à l'emprunt.", this));
  979. return false;
  980. }
  981. DbConnection dbCon = dbpf.CreateConnection();
  982. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  983. dbDa.UpdateCommand = dbCon.CreateCommand();
  984. dbCon.ConnectionString = conStr;
  985. StringBuilder str = new StringBuilder("UPDATE borrow SET ");
  986. str.Append("comment='");
  987. str.Append(MySQLUtils.escapeAndTrim(borrow.Comment));
  988. str.Append("', personId=");
  989. str.Append(borrow.Borrower.Id);
  990. str.Append(", itemBiblioId=");
  991. str.Append(borrow.MediabrolId);
  992. str.Append(", startDate=");
  993. if (!borrow.StartDate.Equals(new DateTime(0L)))
  994. {
  995. str.Append(MySQLUtils.getAccessDate(borrow.StartDate));
  996. }
  997. else str.Append("NULL");
  998. str.Append(", planDate=");
  999. if (!borrow.PlanDate.Equals(new DateTime(0L)))
  1000. {
  1001. str.Append(MySQLUtils.getAccessDate(borrow.PlanDate));
  1002. }
  1003. else str.Append("NULL");
  1004. str.Append(", endDate=");
  1005. if (!borrow.EndDate.Equals(new DateTime(0L)))
  1006. {
  1007. str.Append(MySQLUtils.getAccessDate(borrow.EndDate));
  1008. }
  1009. else str.Append("NULL");
  1010. str.Append(" WHERE id=");
  1011. str.Append(borrow.Id);
  1012. dbCon.Open();
  1013. dbDa.UpdateCommand.CommandText = str.ToString();
  1014. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.UpdateCommand.CommandText, this));
  1015. try
  1016. {
  1017. dbDa.UpdateCommand.ExecuteNonQuery();
  1018. }
  1019. catch (Exception e)
  1020. {
  1021. notify(new Notification(Notification.VERBOSE.criticalError, "Retour d'emprunt", e, this));
  1022. return true;
  1023. }
  1024. finally
  1025. {
  1026. dbCon.Close();
  1027. }
  1028. return true;
  1029. }
  1030. #endregion
  1031.  
  1032. #region qualities
  1033.  
  1034. private int insertQualities(MediaBrol mediabrol, DbDataAdapter dbDa)
  1035. {
  1036. if (mediabrol.Id < 0) return -1;
  1037. int i = 0;
  1038. foreach (Quality q in mediabrol.Qualities)
  1039. {
  1040. if (q.Status.Equals(STATUS.toAdd))
  1041. {
  1042. ++i;
  1043. insertQuality(q, mediabrol.Id, dbDa.InsertCommand);
  1044. }
  1045. else notify(new Notification(Notification.VERBOSE.error, "Insertion des qualités : ERREUR (status != toAdd)", this));
  1046. }
  1047. return i;
  1048. }
  1049. private bool insertQuality(Quality q, int mediabrolId, DbCommand com)
  1050. {
  1051. if (q.Status.Equals(STATUS.toAdd))
  1052. {
  1053. StringBuilder str = new StringBuilder();
  1054. str.Append("INSERT INTO itemBiblioQualityRelation (itemBiblioId, qualityId) VALUES(");
  1055. str.Append(mediabrolId);
  1056. str.Append(",");
  1057. str.Append(q.Id);
  1058. str.Append(");");
  1059. com.CommandText = str.ToString();
  1060. notify(new Notification(Notification.VERBOSE.persistentOperation, com.CommandText, this));
  1061. return (com.ExecuteNonQuery() == 1);
  1062. }
  1063. notify(new Notification(Notification.VERBOSE.error, "Insertion d'une qualité : ERREUR (status != toAdd)", this));
  1064. return false;
  1065. }
  1066. public List<Quality> loadQualities(int itemBiblioBrolId)
  1067. {
  1068. List<Quality> qualities;
  1069. DbConnection dbCon = dbpf.CreateConnection();
  1070. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  1071. dbDa.SelectCommand = dbCon.CreateCommand();
  1072. dbCon.ConnectionString = conStr;
  1073. qualities = loadQualitiesCommand(itemBiblioBrolId, dbDa);
  1074. dbCon.Close();
  1075. return qualities;
  1076. }
  1077.  
  1078. internal List<Quality> loadQualitiesCommand(int itemBiblioBrolId, DbDataAdapter dbDa)
  1079. {
  1080. List<Quality> qualities = new List<Quality>();
  1081. StringBuilder str = new StringBuilder("SELECT quality.* ");
  1082. str.Append("FROM itemBiblioQualityRelation AS r ");
  1083. str.Append("LEFT JOIN quality ON r.qualityId = quality.id ");
  1084. str.Append("WHERE r.itemBiblioId = ");
  1085. str.Append(itemBiblioBrolId);
  1086. dbDa.SelectCommand.CommandText = str.ToString();
  1087. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  1088. DataTable brolDt = new DataTable();
  1089. try
  1090. {
  1091. dbDa.Fill(brolDt);
  1092. }
  1093. catch (Exception e)
  1094. {
  1095. notify(new Notification(Notification.VERBOSE.error, "Chargement des caractéristiques du support", e, this));
  1096. }
  1097. foreach (DataRow brolRow in brolDt.Rows)
  1098. {
  1099. qualities.Add(new Quality(
  1100. (int)brolRow["id"],
  1101. (brolRow["qualName"] is DBNull) ? "" : (String)brolRow["qualName"],
  1102. (brolRow["qualValue"] is DBNull) ? "" : (String)brolRow["qualValue"]
  1103. ));
  1104. }
  1105. brolDt.Dispose();
  1106. return qualities;
  1107. }
  1108.  
  1109. public List<Quality> loadQualities(BrolType brolType)
  1110. {
  1111. List<Quality> qualities = new List<Quality>();
  1112. DbConnection dbCon = dbpf.CreateConnection();
  1113. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  1114. dbDa.SelectCommand = dbCon.CreateCommand();
  1115. dbCon.ConnectionString = conStr;
  1116. StringBuilder str = new StringBuilder("SELECT * FROM quality WHERE typeId = ");
  1117. str.Append(brolType.Id);
  1118. dbDa.SelectCommand.CommandText = str.ToString();
  1119. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  1120. DataTable brolDt = new DataTable();
  1121. try
  1122. {
  1123. dbDa.Fill(brolDt);
  1124. }
  1125. catch (Exception e)
  1126. {
  1127. notify(new Notification(Notification.VERBOSE.error, "Chargement des caractéristiques du support", e, this));
  1128. }
  1129. foreach (DataRow brolRow in brolDt.Rows)
  1130. {
  1131. qualities.Add(new Quality(
  1132. (int)brolRow["id"],
  1133. (brolRow["qualName"] is DBNull) ? "" : (String)brolRow["qualName"],
  1134. (brolRow["qualValue"] is DBNull) ? "" : (String)brolRow["qualValue"]
  1135. ));
  1136. }
  1137. brolDt.Dispose();
  1138. dbCon.Close();
  1139. return qualities;
  1140. }
  1141. #endregion
  1142.  
  1143. #endregion
  1144. }
  1145. }

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 octets1719988872 03/07/2024 08:41:12
| _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.

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/mysql/MySQLMediaBrolDao.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.