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.

115 lines
4.2KB

  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 RequerirAuto class based on the database table
  20. */
  21. public class RequerirAuto : Object {
  22. /**
  23. * The chofer
  24. */
  25. public string chofer { get; set; default = ""; }
  26. /**
  27. * The tour
  28. */
  29. public Tour tour { get; set; default = null; }
  30. /**
  31. * The vehicle
  32. */
  33. public Vehiculo vehiculo { get; set; default = null; }
  34. /**
  35. * Initialize the RequerirAuto class
  36. * @param chofer The chofer
  37. * @param tour The tour
  38. * @param vehiculo The vehicle
  39. */
  40. public RequerirAuto (string chofer = "", Tour? tour = null, Vehiculo? vehiculo = null) {
  41. this.chofer = chofer;
  42. this.tour = tour;
  43. this.vehiculo = vehiculo;
  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 RequerirAuto
  49. */
  50. public static List<RequerirAuto> get_all_requerir_autos (Connection conn) {
  51. var res = conn.db.exec ("
  52. SELECT R.chofer,
  53. T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
  54. C.id_ciudad, C.nombre_ciudad,
  55. R2.id_region, R2.nombre_region,
  56. V.patente, V.ano_vehiculo, V.marca, V.capacidad
  57. FROM requerir_auto R
  58. JOIN tour T ON (R.id_tour = T.id_tour)
  59. JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
  60. JOIN region R2 ON (C.id_region = R2.id_region)
  61. Join vehiculo V ON (R.patente = V.patente)
  62. ");
  63. if (res.get_status () != ExecStatus.TUPLES_OK) {
  64. #if DEBUG
  65. error (conn.db.get_error_message ());
  66. #else
  67. warning (conn.db.get_error_message ());
  68. return new List<RequerirAuto> ();
  69. #endif
  70. }
  71. var wra = new ResultWrapper(res);
  72. List<RequerirAuto> list = new List<RequerirAuto> ();
  73. int n = res.get_n_tuples ();
  74. for (int i = 0; i < n; i++) {
  75. try {
  76. var requerir_auto = new RequerirAuto (wra.get_string_n (i, "chofer"),
  77. new Tour (wra.get_int_n (i, "id_tour"),
  78. wra.get_string_n (i, "nombre_tour"),
  79. wra.get_int_n (i, "costo_indiv"),
  80. wra.get_int_n (i, "costo_grupal"),
  81. wra.get_int_n (i, "minima_personas"),
  82. new Ciudad (wra.get_int_n (i, "id_ciudad"),
  83. wra.get_string_n (i, "nombre_ciudad"),
  84. new Region (wra.get_int_n (i, "id_region"),
  85. wra.get_string_n (i, "nombre_region")
  86. )
  87. )
  88. ),
  89. new Vehiculo (wra.get_string_n (i, "patente"),
  90. wra.get_int_n (i, "ano_vehiculo"),
  91. wra.get_string_n (i, "marca"),
  92. wra.get_int_n (i, "capacidad")
  93. )
  94. );
  95. list.append (requerir_auto);
  96. }
  97. catch (Error e) {
  98. #if DEBUG
  99. error (e.message);
  100. #else
  101. warning (e.message);
  102. #endif
  103. }
  104. }
  105. return list;
  106. }
  107. }
  108. }
  109. }