BiblioBrol : Autres classes du modèle

Nous allons créer certaines classes dans notre modèle, pour faciliter l'usage du modèle.

ModelAdapter

Tout d'abord, nous allons créer une classe ModelAdapter, dans laquelle nous allons simplement relayer les méthodes qui nous permettent d'accéder au DAO. Nous évitons ainsi aux classes qui accèdent au modèle de devoir savoir quelle interface du DAO demander pour effectuer une opération sur les données stockées.

Nous pouvons aussi remarquer une différence dans les noms de certaines méthodes : quand nous nous adressons de l'extérieur à notre classe ModelAdapter, nous utilisons le préfixe get pour signifier que nous désirons obtenir un objet, alors que quand la classe ModelAdapter demande ce même objet au DAO nous employons le préfixe load pour signifier qu'il faut le charger depuis le système de persistance.

Nous allons qualifier toutes les méthodes de la classe ModelAdapter avec le mot réservé static afin d'éviter de devoir créer une instance de ModelAdapter pour utiliser ces méthodes.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using be.gaudry.bibliobrol.model.dao;
  5. using be.gaudry.observer;
  6. using be.gaudry.model;
  7.  
  8. namespace be.gaudry.bibliobrol.model
  9. {
  10. /// <summary>
  11. /// Adapter for all model actions. Trade with dao.
  12. /// </summary>
  13. public class ModelAdapter : Observable
  14. {
  15. #region singleton
  16. static ModelAdapter instance = null;
  17. static readonly object padlock = new object();
  18. ModelAdapter()
  19. {
  20. notify(new Notification(Notification.VERBOSE.debug, "ModelAdapter singleton call", this));
  21. }
  22. public static ModelAdapter Instance
  23. {
  24. get
  25. {
  26. lock (padlock)
  27. {
  28. if (instance == null)
  29. {
  30. instance = new ModelAdapter();
  31. }
  32. return instance;
  33. }
  34. }
  35. }
  36. #endregion
  37.  
  38. #region static observer
  39. private static void setModified(String msg)
  40. {
  41. ModelAdapter.Instance.notify(new Notification(
  42. Notification.VERBOSE.modified,
  43. msg,
  44. ModelAdapter.Instance
  45. ));
  46. }
  47. #endregion
  48.  
  49. #region persistance
  50. /// <summary>
  51. /// Test if the application may use the system to store data
  52. /// </summary>
  53. /// <exception cref="PersistanceNotFoundException">If the persistance is not found or may not be used</exception>
  54. public static void isAvailablePersistance()
  55. {
  56. DAOFactory.Instance.getConfigDao().testPersistance();
  57. }
  58. #endregion
  59.  
  60. #region tasks
  61. /// <summary>
  62. /// Get the tasks
  63. /// </summary>
  64. /// <returns>List of tasks</returns>
  65. public static List<Task> getTasks()
  66. {
  67. return DAOFactory.Instance.getTaskDao().loadTasks();
  68. }
  69.  
  70. /// <summary>
  71. /// Modify a task
  72. /// </summary>
  73. /// <param name="currentTask">task to update</param>
  74. public static void updateTask(Task currentTask)
  75. {
  76. if (DAOFactory.Instance.getTaskDao().updateTask(currentTask))
  77. {
  78. setModified("updateTask");
  79. }
  80. }
  81.  
  82. /// <summary>
  83. /// Delete a task
  84. /// </summary>
  85. /// <param name="taskId">id of the task to delete</param>
  86. public static void deleteTask(int taskId)
  87. {
  88. if (DAOFactory.Instance.getTaskDao().deleteTask(taskId))
  89. {
  90. setModified("deleteTask");
  91. }
  92. }
  93. #endregion
  94.  
  95. #region brol
  96. /// <summary>
  97. /// Unlock a brol
  98. /// </summary>
  99. /// <param name="id">(int) id of the brol to unlock</param>
  100. public static void unlockBrol(int id)
  101. {
  102. DAOFactory.Instance.getBrolDao().unlockBrol(id);
  103. }
  104. /// <summary>
  105. /// load a brol from the persistant layer
  106. /// </summary>
  107. /// <param name="id">(int) id of the brol to load</param>
  108. /// <param name="edit">(bool) true if load to modify (edit mode)</param>
  109. /// <returns>(Brol) brol</returns>
  110. public static Brol getBrol(int id, bool edit)
  111. {
  112. return DAOFactory.Instance.getBrolDao().loadBrol(id, edit);
  113. }
  114. /// <summary>
  115. /// Insert a brol (i.e. a film) into the persistant layer
  116. /// </summary>
  117. /// <param name="brol">(Brol) brol to insert</param>
  118. /// <returns>(int) new brol id</returns>
  119. public static int insertBrol(Brol brol)
  120. {
  121. int r = DAOFactory.Instance.getBrolDao().insertBrol(brol);
  122. setModified("insertBrol");
  123. return r;
  124. }
  125. /// <summary>
  126. /// Delete a brol (i.e. a film) into the persistant layer
  127. /// </summary>
  128. /// <param name="brol">(Brol) brol to insert</param>
  129. /// <returns>(bool) true if deleted</returns>
  130. public static bool deleteBrol(Brol brol)
  131. {
  132. bool r = DAOFactory.Instance.getBrolDao().deleteBrol(brol);
  133. setModified("deleteBrol");
  134. return r;
  135. }
  136. /// <summary>
  137. /// Store new values for a brol.
  138. /// Verify if some categories or actors had been deleted, and delete it from the persistant layer.
  139. /// Add new categories or actors if exists.
  140. /// Update existing categories or actors.
  141. /// </summary>
  142. /// <param name="person">(Brol) brol with new values to store</param>
  143. /// <returns>(bool) true if update is done</returns>
  144. public static bool updateBrol(Brol brol)
  145. {
  146. bool r = DAOFactory.Instance.getBrolDao().updateBrol(brol);
  147. setModified("updateBrol");
  148. return r;
  149. }
  150. /// <summary>
  151. /// Get all brol types
  152. /// </summary>
  153. /// <returns>list of brol types</returns>
  154. public static List<BrolType> getBrolTypes()
  155. {
  156. return DAOFactory.Instance.getConfigDao().loadBrolTypes();
  157. }
  158.  
  159. /// <summary>
  160. /// Get categories for a brol type
  161. /// </summary>
  162. /// <param name="typeId">id of the brol type</param>
  163. /// <returns>list of categories</returns>
  164. public static List<BrolCategory> getCategories(int typeId)
  165. {
  166. return DAOFactory.Instance.getBrolDao().loadCategories(typeId);
  167. }
  168. #endregion
  169.  
  170. #region roles
  171. public static ActorRole getUserRole()
  172. {
  173. return DAOFactory.Instance.getPersonDao().getUserRole();
  174. }
  175. /// <summary>
  176. /// get all roles
  177. /// </summary>
  178. /// <returns>list of roles (ActorRole)</returns>
  179. public static List<ActorRole> getRoles()
  180. {
  181. return DAOFactory.Instance.getBrolDao().loadRoles();
  182. }
  183. /// <summary>
  184. /// get the default role for a person
  185. /// </summary>
  186. /// <param name="person"></param>
  187. /// <returns></returns>
  188. public static ActorRole getDefaultRole(Person person)
  189. {
  190. return DAOFactory.Instance.getBrolDao().loadDefaultRole(person);
  191. }
  192. /// <summary>
  193. /// set the default role for a person
  194. /// </summary>
  195. /// <param name="person"></param>
  196. /// <param name="role"></param>
  197. public static void setDefaultRole(Person person, ActorRole role)
  198. {
  199. DAOFactory.Instance.getBrolDao().setDefaultRole(person, role);
  200. }
  201. /// <summary>
  202. /// get the roles for a person
  203. /// </summary>
  204. /// <param name="person">person for witch we want the roles</param>
  205. /// <returns>list of roles (ActorRole)</returns>
  206. public static List<ActorRole> getRoles(Person person)
  207. {
  208. return DAOFactory.Instance.getBrolDao().loadRoles(person);
  209. }
  210.  
  211. /// <summary>
  212. /// get a roles with the id
  213. /// </summary>
  214. /// <param name="roleId">(int) id of the requested role</param>
  215. /// <returns>l(ActorRole) requested role</returns>
  216. public static ActorRole getRole(int roleId)
  217. {
  218. return DAOFactory.Instance.getBrolDao().loadRole(roleId);
  219. }
  220. /// <summary>
  221. /// get a roles with the name
  222. /// </summary>
  223. /// <param name="roleName">(string) name of the requested role</param>
  224. /// <returns>(ActorRole) requested role</returns>
  225. public static ActorRole loadRole(string roleName)
  226. {
  227. return DAOFactory.Instance.getBrolDao().loadRole(roleName);
  228. }
  229. /// <summary>
  230. /// get a list of roles with the same name
  231. /// </summary>
  232. /// <param name="roleName">(string) name of the requested roles</param>
  233. /// <returns>(List of ActorRole) requested roles</returns>
  234. public static List<ActorRole> loadRoles(string roleName)
  235. {
  236. return DAOFactory.Instance.getBrolDao().loadRoles(roleName);
  237. }
  238. /// <summary>
  239. /// Insert a new role. Don't check if the role name exists in the db. You must do it before.
  240. /// </summary>
  241. /// <param name="actor">(ActorRole) role to add</param>
  242. /// <returns></returns>
  243. public static bool insertRole(ActorRole role)
  244. {
  245. return DAOFactory.Instance.getBrolDao().insertRole(role);
  246. }
  247. #endregion
  248.  
  249. #region persons
  250.  
  251. #region get personsVos
  252. /// <summary>
  253. /// get a list of personsVos (value objects) for a role
  254. /// </summary>
  255. /// <param name="role">role where the persons may be</param>
  256. /// <returns>list of personsVos</returns>
  257. public static List<PersonLO> getPersonsVos(ActorRole role)
  258. {
  259. return DAOFactory.Instance.getPersonDao().loadPersonsVos(role);
  260. }
  261.  
  262. /// <summary>
  263. /// get a list of personsVos (value objects)
  264. /// </summary>
  265. /// <returns>list of personsVos</returns>
  266. public static List<PersonLO> getPersonsVos()
  267. {
  268. return DAOFactory.Instance.getPersonDao().loadVos();
  269. }
  270. /// <summary>
  271. /// Load a person from the persistant layer all persons matches (case insensitive) with lastName
  272. /// </summary>
  273. /// <param name="lastName">(String) lastName to match</param>
  274. /// <returns>List of persons with the same lastName</returns>
  275. public static List<PersonLO> getPersonsVos(String lastName)
  276. {
  277. return DAOFactory.Instance.getPersonDao().loadPersonsVos(lastName);
  278. }
  279. #endregion
  280.  
  281. #region user
  282.  
  283. /// <summary>
  284. /// Load a person from the persistant layer with an id arg.
  285. /// If this person shoud be modified, editing bool arg is true
  286. /// to avoid concurent modifications (nobody else can save this person).
  287. /// </summary>
  288. /// <param name="id">(int) Id of the selected person</param>
  289. /// <param name="editing">(bool) Shoud be modified or not</param>
  290. /// <returns>Selected person, or a new person if _ found</returns>
  291. public static User getUser(int persId)
  292. {
  293. return DAOFactory.Instance.getPersonDao().loadUser(persId);
  294. }
  295.  
  296. /// <summary>
  297. /// Insert or update a user
  298. /// </summary>
  299. /// <param name="user">user to insert or update</param>
  300. /// <returns>(int) id of the new person (-1 if a problem occurs in case of insert)</returns>
  301. public static int saveUser(User user)
  302. {
  303. return DAOFactory.Instance.getPersonDao().saveUser(user);
  304. }
  305.  
  306. /// <summary>
  307. /// Delete a user
  308. /// </summary>
  309. /// <param name="person">user to delete</param>
  310. /// <param name="deletePerson">true if the person must also be deleted</param>
  311. public static void deleteUser(User user, bool deletePerson)
  312. {
  313. DAOFactory.Instance.getPersonDao().deleteUser(user, deletePerson);
  314. }
  315. #endregion
  316.  
  317. #region getPerson
  318.  
  319. public static List<Person> getOwners()
  320. {
  321. return new List<Person>();
  322. }
  323. /// <summary>
  324. /// Load a person from the persistant layer with an id arg.
  325. /// If this person shoud be modified, editing bool arg is true
  326. /// to avoid concurent modifications (nobody else can save this person).
  327. /// </summary>
  328. /// <param name="id">(int) Id of the selected person</param>
  329. /// <param name="editing">(bool) Shoud be modified or not</param>
  330. /// <returns>Selected person, or a new person if _ found</returns>
  331. public static Person getPerson(int persId, bool edited)
  332. {
  333. return DAOFactory.Instance.getPersonDao().loadPerson(persId, edited);
  334. }
  335. /// <summary>
  336. /// Load a person from the persistant layer all persons matches (case insensitive) with lastName
  337. /// </summary>
  338. /// <param name="lastName">(String) lastName to match</param>
  339. /// <returns>List of persons with the same lastName</returns>
  340. public static List<Person> getPersons(String lastName)
  341. {
  342. return DAOFactory.Instance.getPersonDao().loadPersons(lastName);
  343. }
  344. #endregion
  345.  
  346. #region person actions
  347. /// <summary>
  348. /// Test if a person exists with the same name and firstname
  349. /// </summary>
  350. /// <param name="person">(Person) person to test</param>
  351. /// <returns>(int) id of the person found (-1 if not found)</returns>
  352. public static int personExists(Person person)
  353. {
  354. return DAOFactory.Instance.getPersonDao().personExists(person);
  355. }
  356.  
  357. /// <summary>
  358. /// Unlock a person (locked when loaded in update mode)
  359. /// </summary>
  360. /// <param name="personId">id of the locked person</param>
  361. public static bool unlockPerson(int personId)
  362. {
  363. return DAOFactory.Instance.getPersonDao().unlockPerson(personId);
  364. }
  365.  
  366. /// <summary>
  367. /// Insert a new person
  368. /// </summary>
  369. /// <param name="person">person to insert</param>
  370. /// <returns>(int) id of the new person (-1 if a problem occurs)</returns>
  371. public static int insertPerson(Person person)
  372. {
  373. int persId = DAOFactory.Instance.getPersonDao().insertPerson(person);
  374. setModified("insertPerson");
  375. return persId;
  376. }
  377.  
  378. /// <summary>
  379. /// Insert a new person and add it in the bibliobrolusers group
  380. /// </summary>
  381. /// <param name="person">person to insert</param>
  382. /// <returns>(int) id of the new person (-1 if a problem occurs)</returns>
  383. public static int insertBibliobrolUser(Person person)
  384. {
  385. int persId = DAOFactory.Instance.getPersonDao().insertBibliobrolUser(person);
  386. setModified("insertPerson");
  387. return persId;
  388. }
  389.  
  390. /// <summary>
  391. /// Update a person
  392. /// </summary>
  393. /// <param name="person">person to update</param>
  394. public static void updatePerson(Person person)
  395. {
  396. DAOFactory.Instance.getPersonDao().updatePerson(person);
  397. setModified("updatePerson");
  398. }
  399.  
  400. /// <summary>
  401. /// Delete a person
  402. /// </summary>
  403. /// <param name="person">person to delete</param>
  404. public static void deletePerson(Person person)
  405. {
  406. DAOFactory.Instance.getPersonDao().deletePerson(person);
  407. setModified("deletePerson");
  408. }
  409.  
  410. /// <summary>
  411. /// Load a person from the persistant layer with a lastname and a firstname.
  412. /// Search case insensitive.
  413. /// </summary>
  414. /// <param name="lastName">(string) lastname of the searched person</param>
  415. /// <param name="firstName">(string) firstname of the searched person</param>
  416. /// <returns>Persons found, or empty list</returns>
  417. public static List<Person> getPersons(string lastName, string firstName)
  418. {
  419. return DAOFactory.Instance.getPersonDao().loadPersons(lastName, firstName);
  420. }
  421. #endregion
  422.  
  423. #endregion
  424.  
  425. #region brol actions
  426. /// <summary>
  427. /// Execute batch actions (to add a lot of brols)
  428. /// </summary>
  429. /// <param name="insertMediabrol">true if we must insert a mediabrol for each brol</param>
  430. public static void executeBrolBatch(bool insertMediabrol)
  431. {
  432. DAOFactory.Instance.getBrolDao().executeBatch(insertMediabrol);
  433. }
  434. #endregion
  435.  
  436. #region MediaBrol
  437. /// <summary>
  438. /// load a datatable with selected fields of mediabrols
  439. /// </summary>
  440. /// <param name="mediabrolFields">fields of mediabrols to load</param>
  441. /// <param name="typeId">id of the brol type</param>
  442. /// <returns>datatable with mediabrols</returns>
  443. public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId)
  444. {
  445. return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId);
  446. }
  447.  
  448. /// <summary>
  449. /// load a datatable with selected fields of mediabrols
  450. /// </summary>
  451. /// <param name="mediabrolFields">fields of mediabrols to load</param>
  452. /// <param name="typeId">id of the brol type</param>
  453. /// <param name="categories">categories where may be the mediabrols</param>
  454. /// <returns>datatable with mediabrols</returns>
  455. public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId, List<BrolCategory> categories)
  456. {
  457. return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId, categories);
  458. }
  459.  
  460. /// <summary>
  461. /// load a datatable with selected fields of mediabrols
  462. /// </summary>
  463. /// <param name="mediabrolFields">fields of mediabrols to load</param>
  464. /// <param name="typeId">id of the brol type</param>
  465. /// <param name="categories">categories where may be the mediabrols</param>
  466. /// <param name="mediaId">id of the media</param>
  467. /// <returns>datatable with mediabrols</returns>
  468. public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId, List<BrolCategory> categories, int mediaId)
  469. {
  470. return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId, categories, mediaId);
  471. }
  472.  
  473. /// <summary>
  474. /// load a datatable with selected fields of mediabrols
  475. /// </summary>
  476. /// <param name="mediabrolFields">fields of mediabrols to load</param>
  477. /// <param name="typeId">id of the brol type</param>
  478. /// <param name="categories">categories where may be the mediabrols</param>
  479. /// <param name="mediaId">id of the media</param>
  480. /// <param name="title"></param>
  481. /// <returns>datatable with mediabrols</returns>
  482. public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId, List<BrolCategory> categories, int mediaId, string title)
  483. {
  484. return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId, categories, mediaId, title);
  485. }
  486.  
  487. /// <summary>
  488. /// load a mediabrol
  489. /// </summary>
  490. /// <param name="id">id of the mediabrol</param>
  491. /// <param name="editing">true if we will edit values (lock the record)</param>
  492. /// <returns>selected mediabrol</returns>
  493. public static MediaBrol loadMediaBrol(int id, bool editing)
  494. {
  495. return DAOFactory.Instance.getMediaBrolDao().loadMediaBrol(id, editing);
  496. }
  497.  
  498. /// <summary>
  499. /// Load medias for a brol type
  500. /// </summary>
  501. /// <param name="typeId">id of the brol type</param>
  502. /// <returns>list of medias</returns>
  503. public static List<Media> loadMedias(int typeId)
  504. {
  505. return DAOFactory.Instance.getMediaBrolDao().loadMedias(typeId);
  506. }
  507.  
  508. /// <summary>
  509. /// load qualities for a brol type
  510. /// </summary>
  511. /// <param name="brolType">id of the brol type</param>
  512. /// <returns>list of qualities</returns>
  513. public static List<Quality> loadQualities(BrolType brolType)
  514. {
  515. return DAOFactory.Instance.getMediaBrolDao().loadQualities(brolType);
  516. }
  517.  
  518. /// <summary>
  519. /// Delete a mediabrol
  520. /// </summary>
  521. /// <param name="mediabrol">mediabrol to delete</param>
  522. public static void deleteMediaBrol(MediaBrol mediabrol)
  523. {
  524. DAOFactory.Instance.getMediaBrolDao().deleteMediaBrol(mediabrol);
  525. setModified("deleteMediaBrol");
  526. }
  527.  
  528. /// <summary>
  529. /// Delete a mediabrol
  530. /// </summary>
  531. /// <param name="mediabrolId">id of the mediabrol</param>
  532. /// <param name="title"></param>
  533. /// <param name="deleteBrol">true if we want also delete the associated brol</param>
  534. public static void deleteMediaBrol(int mediabrolId, String title, bool deleteBrol)
  535. {
  536. DAOFactory.Instance.getMediaBrolDao().deleteMediaBrol(mediabrolId, title, deleteBrol);
  537. setModified("deleteMediaBrol");
  538. }
  539.  
  540. /// <summary>
  541. /// Update a mediabrol
  542. /// </summary>
  543. /// <param name="mediabrol">mediabrol to update</param>
  544. public static void updateMediaBrol(MediaBrol mediabrol)
  545. {
  546. DAOFactory.Instance.getMediaBrolDao().updateMediaBrol(mediabrol);
  547. setModified("updateMediaBrol");
  548. }
  549.  
  550. /// <summary>
  551. /// Insert a mediabrol
  552. /// </summary>
  553. /// <param name="mediabrol">mediabrol to insert</param>
  554. /// <returns>id of the new mediabrol</returns>
  555. public static int insertMediaBrol(MediaBrol mediabrol)
  556. {
  557. int r = DAOFactory.Instance.getMediaBrolDao().insertMediaBrol(mediabrol);
  558. setModified("insertMediaBrol");
  559. return r;
  560. }
  561. #endregion
  562.  
  563. #region borrows
  564. #region modify borrows
  565. /// <summary>
  566. /// Start a borrow
  567. /// </summary>
  568. /// <param name="mediabrolId">id of the borrowed mediabrol</param>
  569. /// <param name="borrowerId">id of the borrower</param>
  570. public static bool startBorrow(int mediabrolId, int borrowerId)
  571. {
  572. if (DAOFactory.Instance.getMediaBrolDao().startBorrow(mediabrolId, borrowerId))
  573. {
  574. setModified("startBorrow");
  575. return true;
  576. }
  577. return false;
  578. }
  579.  
  580. /// <summary>
  581. /// Stop a borrow (set end date)
  582. /// </summary>
  583. /// <param name="borrowId">id of the borrow</param>
  584. public static void stopBorrow(int borrowId)
  585. {
  586. DAOFactory.Instance.getMediaBrolDao().stopBorrow(borrowId);
  587. setModified("stopBorrow");
  588. }
  589.  
  590. /// <summary>
  591. /// Update borrow, set endDate to now
  592. /// </summary>
  593. /// <param name="mediabrol">(MediaBrol) borrowed mediabrol</param>
  594. /// <returns>(bool) true if stopped</returns>
  595. public static void stopBorrow(MediaBrol mediabrol)
  596. {
  597. DAOFactory.Instance.getMediaBrolDao().stopBorrow(mediabrol);
  598. setModified("stopBorrow");
  599. }
  600.  
  601. /// <summary>
  602. /// update a borrow
  603. /// </summary>
  604. /// <param name="borrow">borrow to update</param>
  605. public static void updateBorrow(Borrow borrow)
  606. {
  607. DAOFactory.Instance.getMediaBrolDao().updateBorrow(borrow);
  608. setModified("updateBorrow");
  609. }
  610.  
  611. /// <summary>
  612. /// Delete all borrows for a mediabrol
  613. /// </summary>
  614. /// <param name="mediabrolId">id of the mediabrol</param>
  615. /// <param name="forceDelete">set true to force to delete if the borrow is not closed</param>
  616. public static void cleanBorrows(int mediabrolId, bool forceDelete)
  617. {
  618. DAOFactory.Instance.getMediaBrolDao().cleanBorrows(mediabrolId, forceDelete);
  619. setModified("cleanBorrows");
  620. }
  621.  
  622. /// <summary>
  623. /// Delete a borrow
  624. /// </summary>
  625. /// <param name="selectedBorrowId">id of the borrow to delete</param>
  626. public static void cleanBorrow(int selectedBorrowId)
  627. {
  628. DAOFactory.Instance.getMediaBrolDao().cleanBorrow(selectedBorrowId);
  629. setModified("cleanBorrow");
  630. }
  631. #endregion
  632.  
  633. #region load borrows
  634. /// <summary>
  635. /// Load borrows for a mediabrol
  636. /// </summary>
  637. /// <param name="mediabrolId">id of the mediabrol</param>
  638. /// <param name="borrowFields">fields to load</param>
  639. /// <returns>datatable with borrows</returns>
  640. public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields)
  641. {
  642. return ModelAdapter.loadBorrows(mediabrolId, borrowFields, 0);
  643. }
  644.  
  645. /// <summary>
  646. /// Load borrows for a mediabrol
  647. /// </summary>
  648. /// <param name="mediabrolId">id of the mediabrol</param>
  649. /// <param name="borrowFields">fields to load</param>
  650. /// <param name="typeId"></param>
  651. /// <returns>datatable with borrows</returns>
  652. public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId)
  653. {
  654. return ModelAdapter.loadBorrows(mediabrolId, borrowFields, typeId, true);
  655. }
  656.  
  657. /// <summary>
  658. /// Load borrows for a mediabrol
  659. /// </summary>
  660. /// <param name="mediabrolId">id of the mediabrol</param>
  661. /// <param name="borrowFields">fields to load</param>
  662. /// <param name="typeId"></param>
  663. /// <param name="closed"></param>
  664. /// <returns>datatable with borrows</returns>
  665. public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId, bool closed)
  666. {
  667. return ModelAdapter.loadBorrows(mediabrolId, borrowFields, typeId, closed, "");
  668. }
  669.  
  670. /// <summary>
  671. /// Load borrows for a mediabrol
  672. /// </summary>
  673. /// <param name="mediabrolId">id of the mediabrol</param>
  674. /// <param name="borrowFields">fields to load</param>
  675. /// <param name="typeId"></param>
  676. /// <param name="closed"></param>
  677. /// <param name="title"></param>
  678. /// <returns>datatable with borrows</returns>
  679. public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId, bool closed, string title)
  680. {
  681. return DAOFactory.Instance.getMediaBrolDao().loadBorrows(mediabrolId, borrowFields, typeId, closed, title);
  682. }
  683.  
  684. /// <summary>
  685. /// Load a borrow
  686. /// </summary>
  687. /// <param name="borrowId">id of the borrow</param>
  688. /// <returns>selected borrow</returns>
  689. public static Borrow loadBorrow(int borrowId)
  690. {
  691. return DAOFactory.Instance.getMediaBrolDao().loadBorrow(borrowId);
  692. }
  693. #endregion
  694. #endregion
  695.  
  696. #region import export
  697. /// <summary>
  698. /// Export mediabrols into an xml file
  699. /// </summary>
  700. /// <param name="mediabrolIds">ids of the mediabrols to export</param>
  701. /// <param name="path">Exportation file path</param>
  702. public static void exportXMLMediaBrol(int[] mediabrolIds, String path)
  703. {
  704. DAOFactory.Instance.getExporterDao().exportXMLMediaBrol(mediabrolIds, path);
  705. }
  706.  
  707. /// <summary>
  708. /// Export mediabrols into a serialized file
  709. /// </summary>
  710. /// <param name="mediabrolIds">ids of the mediabrols to export</param>
  711. /// <param name="path">Exportation file path</param>
  712. /// <param name="exportMediabrol"></param>
  713. /// <param name="exportAllBrols"></param>
  714. /// <param name="anonymous"></param>
  715. public static void exportBinaryMediaBrol(int[] mediabrolIds, String path, bool exportMediabrol, bool exportAllBrols, bool anonymous)
  716. {
  717. DAOFactory.Instance.getExporterDao().exportBinaryMediaBrol(mediabrolIds, path, exportMediabrol, exportAllBrols, anonymous);
  718. }
  719.  
  720. /// <summary>
  721. /// Export mediabrols into a serialized file
  722. /// </summary>
  723. /// <param name="mediabrolIds">ids of the mediabrols to export</param>
  724. /// <param name="path">Exportation file path</param>
  725. /// <param name="exportMediabrol"></param>
  726. /// <param name="exportAllBrols"></param>
  727. /// <param name="anonymous"></param>
  728. public static void exportBinaryMediaBrolTest(int[] mediabrolIds, String path, bool exportMediabrol, bool exportAllBrols, bool anonymous)
  729. {
  730. DAOFactory.Instance.getExporterDao().exportBinaryMediaBrolTest(mediabrolIds, path, exportMediabrol, exportAllBrols, anonymous);
  731. }
  732.  
  733. /// <summary>
  734. /// Add an observer into the exporter (observable) observers list
  735. /// </summary>
  736. /// <param name="observer">observer to add</param>
  737. public static void addImportExporterObserver(IObserver observer)
  738. {
  739. DAOFactory.Instance.getExporterDao().addObserver(observer);
  740. DAOFactory.Instance.getImporterDao().addObserver(observer);
  741. }
  742.  
  743. /// <summary>
  744. /// Remove an observer from the exporter (observable) observers list
  745. /// </summary>
  746. /// <param name="observer">observer to remove</param>
  747. public static void removeImportExporterObserver(IObserver observer)
  748. {
  749. DAOFactory.Instance.getExporterDao().removeObserver(observer);
  750. DAOFactory.Instance.getImporterDao().removeObserver(observer);
  751. }
  752.  
  753. /// <summary>
  754. /// Import mediabrols objects from a serialized file
  755. /// </summary>
  756. /// <param name="path">path of the importation file</param>
  757. public static void importBinaryMediaBrol(String path)
  758. {
  759. DAOFactory.Instance.getImporterDao().importBinaryMediaBrol(path);
  760. setModified("importBinaryMediaBrol");
  761. }
  762.  
  763. /// <summary>
  764. /// Get a list of images from a serialized file
  765. /// </summary>
  766. /// <param name="path">path of the importation file</param>
  767. /// <returns>List of images</returns>
  768. public static List<System.Drawing.Image> importImages(string path)
  769. {
  770. return DAOFactory.Instance.getImporterDao().importImages(path);
  771. }
  772.  
  773. /// <summary>
  774. /// Export mediabrols in an Excel Sheet, or in CSV file
  775. /// </summary>
  776. /// <param name="mediabrolIds">ids of the mediabrols to export</param>
  777. /// <param name="path">path of the exportation file</param>
  778. /// <param name="type">Type of the exportation (csv or sheet)</param>
  779. public static void exportExcelMediaBrol(int[] mediabrolIds, String path, int type)
  780. {
  781. DAOFactory.Instance.getExporterDao().exportExcelMediaBrol(mediabrolIds, path, type);
  782. }
  783. #endregion
  784.  
  785. #region stats
  786. /// <summary>
  787. /// Get counters
  788. /// </summary>
  789. /// <returns>Counter object</returns>
  790. public static Counter getCounters()
  791. {
  792. return DAOFactory.Instance.getStatsDao().loadCounters();
  793. }
  794.  
  795. /// <summary>
  796. /// Get stats for actor roles
  797. /// </summary>
  798. /// <returns>Stat object</returns>
  799. public static Stat getStatsActorRoles()
  800. {
  801. return DAOFactory.Instance.getStatsDao().loadActorRoles();
  802. }
  803.  
  804. /// <summary>
  805. /// Get stats for current borrows
  806. /// </summary>
  807. /// <returns>Stat object</returns>
  808. public static Stat getStatsCurrentBorrows()
  809. {
  810. return DAOFactory.Instance.getStatsDao().loadCurrentBorrows();
  811. }
  812.  
  813. /// <summary>
  814. /// Get stats for all borrows
  815. /// </summary>
  816. /// <returns>Stat object</returns>
  817. public static Stat getStatsAllBorrows()
  818. {
  819. return DAOFactory.Instance.getStatsDao().loadAllBorrows();
  820. }
  821.  
  822. /// <summary>
  823. /// Get stats for brols by types
  824. /// </summary>
  825. /// <returns>Stat object</returns>
  826. public static Stat getStatsBrolTypes()
  827. {
  828. return DAOFactory.Instance.getStatsDao().loadBrolTypes();
  829. }
  830.  
  831. /// <summary>
  832. /// Get stats for mediabrols by types
  833. /// </summary>
  834. /// <returns>Stat object</returns>
  835. public static Stat getStatsMediaBrolTypes()
  836. {
  837. return DAOFactory.Instance.getStatsDao().loadMediaBrolTypes();
  838. }
  839. #endregion
  840.  
  841. #region serie
  842. /// <summary>
  843. /// Get the serie
  844. /// </summary>
  845. /// <returns>List of serie</returns>
  846. public static List<Serie> getSeries()
  847. {
  848. return DAOFactory.Instance.getSerieDao().loadSeries();
  849. }
  850.  
  851. /// <summary>
  852. /// Modify a Serie
  853. /// </summary>
  854. /// <param name="currentTask">Serie to update</param>
  855. public static bool updateSerie(Serie serie)
  856. {
  857. bool test = DAOFactory.Instance.getSerieDao().updateSerie(serie);
  858. if (test)
  859. {
  860. setModified("updateSerie");
  861. }
  862. return test;
  863. }
  864.  
  865. /// <summary>
  866. /// Delete a Serie
  867. /// </summary>
  868. /// <param name="taskId">id of the Serie to delete</param>
  869. public static bool deleteSerie(int serieId)
  870. {
  871. bool test = DAOFactory.Instance.getSerieDao().deleteSerie(serieId);
  872. if (test)
  873. {
  874. setModified("deleteSerie");
  875. }
  876. return test;
  877. }
  878. #endregion
  879. }
  880. }

DAOUtils

Nous pouvons demander de ne charger que partiellement certains objets depuis notre système de persistance. Pour cette raison, nous allons créer certaines énumérations qui contiendront les attributs à charger. En interne, le DAO utilisera ces valeurs pour en déduire les actions à effectuer.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace be.gaudry.bibliobrol.model.dao
  6. {
  7. public class DAOUtils
  8. {
  9. /// <summary>
  10. /// Fields of Borrow object that we want to load from persistant layer, independant from table structure, fields names, or other persistant structure.
  11. /// Mediabrol Id is allways loaded, no need to define here.
  12. /// </summary>
  13. public enum BORROW_FIELD
  14. {
  15. /// <summary>
  16. /// Id of the borrowed mediabrol.
  17. /// Be carrefull : using this id disallow using borrow id
  18. /// </summary>
  19. id,
  20. /// <summary>
  21. /// Name of the borrowed mediabrol
  22. /// </summary>
  23. name,
  24. /// <summary>
  25. /// Title of brol
  26. /// </summary>
  27. title,
  28. startDate,
  29. endDate,
  30. planDate,
  31. comment,
  32. /// <summary>
  33. /// Name of the borrower
  34. /// </summary>
  35. borrower,
  36. /// <summary>
  37. ///
  38. /// </summary>
  39. brolId,
  40. /// <summary>
  41. /// type name
  42. /// </summary>
  43. type
  44. };
  45. /// <summary>
  46. /// Fields of Brol object that we want to load from persistant layer, independant from table structure, fields names, or other persistant structure.
  47. /// </summary>
  48. public enum BROL_FIELD
  49. {
  50. id,
  51. title,
  52. category,
  53. synopsis,
  54. actors,
  55. cotation,
  56. date,
  57. serie
  58. };
  59. /// <summary>
  60. /// Fields of MediaBrol object that we want to load from persistant layer, independant from table structure, fields names, or other persistant structure.
  61. /// </summary>
  62. public enum MEDIABROL_FIELD
  63. {
  64. id,
  65. name,
  66. date,
  67. i_title,
  68. i_category,
  69. i_cotation,
  70. i_date,
  71. owner,
  72. brolId
  73. };
  74.  
  75. }
  76. }

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

4 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-8757
Document créé le 06/12/06 05:06, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http:///www.gaudry.be/bibliobrol-model-misc.html
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15838 documents
455 astuces.
550 niouzes.
3107 definitions.
447 membres.
8121 messages.

Document genere en :
0,21 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Le bonheur et le malheur sont toujours relatifs à quelque situation antécédente dont on conserve le souvenir.

Charles Bonnet
 
l'infobrol
Nous sommes le Mercredi 24 Mai 2017, 00:30, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)