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.

91 lines
3.3KB

  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 ValoresTours class based on the database table
  20. */
  21. public class ValoresTours : Object {
  22. /**
  23. * The id of the tour
  24. */
  25. public uint id_tour { get; set; default = 0; }
  26. /**
  27. * The name of the tour
  28. */
  29. public string nombre_tour { get; set; default = ""; }
  30. /**
  31. * The total sales value
  32. */
  33. public uint total_ventas { get; set; default = 0; }
  34. /**
  35. * Initialize the ValoresTours class
  36. * @param id_tour The tour id
  37. * @param nombre_tour The tour name
  38. * @param total_ventas The sales total
  39. */
  40. public ValoresTours (uint id_tour = 0, string nombre_tour = "", uint total_ventas = 0) {
  41. this.id_tour = id_tour;
  42. this.nombre_tour = nombre_tour;
  43. this.total_ventas = total_ventas;
  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 ValoresTours
  49. */
  50. public static List<ValoresTours> get_all_tour_sales (Connection conn) {
  51. var res = conn.db.exec ("
  52. SELECT idT, nombreT, TotalVentas FROM VALORES_TOURS
  53. ");
  54. if (res.get_status () != ExecStatus.TUPLES_OK) {
  55. #if DEBUG
  56. error (conn.db.get_error_message ());
  57. #else
  58. warning (conn.db.get_error_message ());
  59. return new List<ValoresTours> ();
  60. #endif
  61. }
  62. var wra = new ResultWrapper (res);
  63. List<ValoresTours> list = new List<ValoresTours> ();
  64. int n = res.get_n_tuples ();
  65. for (int i = 0; i < n; i++) {
  66. try {
  67. var tour_value = new ValoresTours (wra.get_int_n (i, "idT"),
  68. wra.get_string_n (i, "nombreT"),
  69. wra.get_int_n (i, "TotalVentas")
  70. );
  71. list.append (tour_value);
  72. }
  73. catch (Error e) {
  74. #if DEBUG
  75. error (e.message);
  76. #else
  77. warning (e.message);
  78. #endif
  79. }
  80. }
  81. return list;
  82. }
  83. }
  84. }
  85. }