Este proyecto es una aplicación para trabajar con un base de datos Postgresql por el ramo de base de datos. https://cromer.cl/sernatur
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.6KB

  1. /*
  2. * Copyright 2018-2019 Chris Cromer
  3. *
  4. * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5. *
  6. * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  7. *
  8. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  9. *
  10. * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  11. *
  12. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  13. */
  14. namespace LibSernatur {
  15. namespace DB {
  16. using Postgres;
  17. using Wrapper;
  18. /**
  19. * The Realiza class based on the database table
  20. */
  21. public class Realiza : Object {
  22. /**
  23. * The tour
  24. */
  25. public Tour tour { get; set; default = null; }
  26. /**
  27. * The tourist
  28. */
  29. public Turista turista { get; set; default = null; }
  30. /**
  31. * The discount
  32. */
  33. public Descuento descuento { get; set; default = null; }
  34. /**
  35. * Initialize the Realiza class
  36. * @param tour The tour
  37. * @param turista The tourist
  38. * @param descuento The discount
  39. */
  40. public Realiza (Tour? tour = null, Turista? turista = null, Descuento? descuento = null) {
  41. this.tour = tour;
  42. this.turista = turista;
  43. this.descuento = descuento;
  44. }
  45. /**
  46. * Get all tuples and fields from database
  47. * @param conn.db.The database conn.db.ction to use
  48. * @return Returns a list of Realiza
  49. */
  50. public static List<Realiza> get_all_realizas (Connection conn) {
  51. var res = conn.db.exec ("
  52. SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
  53. C.id_ciudad, C.nombre_ciudad,
  54. R.id_region, R.nombre_region,
  55. T2.rut_turista, T2.nombre_turista, T2.fecha_nacimento,
  56. C2.id_contacto, C2.telefono_emergencia, C2.nombre_emergencia,
  57. D.id_descuento, D.descripcion_descuento, D.porcentaje
  58. FROM realiza RE
  59. JOIN tour T ON (RE.id_tour = T.id_tour)
  60. JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
  61. JOIN region R ON (C.id_region = R.id_region)
  62. JOIN turista T2 ON (RE.rut_turista = T2.rut_turista)
  63. JOIN contacto_emergencia C2 ON (T2.id_contacto = C2.id_contacto)
  64. JOIN descuento D ON (RE.id_descuento = D.id_descuento)
  65. ");
  66. if (res.get_status () != ExecStatus.TUPLES_OK) {
  67. #if DEBUG
  68. error (conn.db.get_error_message ());
  69. #else
  70. warning (conn.db.get_error_message ());
  71. return new List<Realiza> ();
  72. #endif
  73. }
  74. var wra = new ResultWrapper (res);
  75. List<Realiza> list = new List<Realiza> ();
  76. int n = res.get_n_tuples ();
  77. for (int i = 0; i < n; i++) {
  78. try {
  79. var realiza = new Realiza (
  80. new Tour (wra.get_int_n (i, "id_tour"),
  81. wra.get_string_n (i, "nombre_tour"),
  82. wra.get_int_n (i, "costo_indiv"),
  83. wra.get_int_n (i, "costo_grupal"),
  84. wra.get_int_n (i, "minima_personas"),
  85. new Ciudad (wra.get_int_n (i, "id_ciudad"),
  86. wra.get_string_n (i, "nombre_ciudad"),
  87. new Region (wra.get_int_n (i, "id_region"),
  88. wra.get_string_n (i, "nombre_region")
  89. )
  90. )
  91. ),
  92. new Turista (wra.get_string_n (i, "rut_turista"),
  93. wra.get_string_n (i, "nombre_turista"),
  94. wra.get_string_n (i, "fecha_nacimento"),
  95. new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
  96. wra.get_int_n (i, "telefono_emergencia"),
  97. wra.get_string_n (i, "nombre_emergencia")
  98. )
  99. ),
  100. new Descuento (wra.get_int_n (i, "id_descuento"),
  101. wra.get_string_n (i, "descripcion_descuento"),
  102. wra.get_float_n (i, "porcentaje")
  103. )
  104. );
  105. list.append (realiza);
  106. }
  107. catch (Error e) {
  108. #if DEBUG
  109. error (e.message);
  110. #else
  111. warning (e.message);
  112. #endif
  113. }
  114. }
  115. return list;
  116. }
  117. }
  118. }
  119. }