AccessMediaBrolDao.cs

Description du code

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

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 octets1731765179 16/11/2024 14:52:59
| _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//AccessMediaBrolDao.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.