Browse Source

start the 3rd assignment

tags/1.0.0
Chris Cromer 10 months ago
parent
commit
18dafc38e1
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
63 changed files with 1811 additions and 226 deletions
  1. +1
    -0
      data/ui/sernatur.gresource.xml
  2. +39
    -110
      data/ui/sernatur.window.ui
  3. +55
    -0
      data/ui/splash.ui
  4. +0
    -0
      doc/Enunciados/trabajoSemestral(E1).pdf
  5. +0
    -0
      doc/Enunciados/trabajoSemestral(E2).pdf
  6. BIN
      doc/Enunciados/trabajoSemestral(E3).pdf
  7. +0
    -0
      doc/Informes/Informe1.pdf
  8. +0
    -0
      doc/Informes/Informe1.tex
  9. +0
    -0
      doc/Informes/Informe1_creartablas.sql
  10. +0
    -0
      doc/Informes/Informe1_insertarduplas.sql
  11. +0
    -0
      doc/Informes/Informe1corregido.pdf
  12. +0
    -0
      doc/Informes/Informe1corregido.tex
  13. +0
    -0
      doc/Informes/Informe1corregido_creartablas.sql
  14. +0
    -0
      doc/Informes/Informe1corregido_insertarduplas.sql
  15. +0
    -0
      doc/Informes/Informe2.pdf
  16. +0
    -0
      doc/Informes/Informe2.tex
  17. +0
    -0
      doc/Informes/Informe2_Q1.png
  18. +0
    -0
      doc/Informes/Informe2_Q2.png
  19. +0
    -0
      doc/Informes/Informe2_Q3.png
  20. +0
    -0
      doc/Informes/Informe2_Q4.png
  21. +0
    -0
      doc/Informes/Informe2_Q5.png
  22. +0
    -0
      doc/Informes/Informe2_vistaQ1.sql
  23. +0
    -0
      doc/Informes/Informe2_vistaQ2.sql
  24. +0
    -0
      doc/Informes/Informe2_vistaQ3.sql
  25. +0
    -0
      doc/Informes/Informe2_vistaQ4.sql
  26. +0
    -0
      doc/Informes/Informe2_vistaQ5.sql
  27. +0
    -0
      doc/Informes/MER.dia
  28. +0
    -0
      doc/Informes/MER.png
  29. +0
    -0
      doc/Informes/MERcorregido.dia
  30. +0
    -0
      doc/Informes/MERcorregido.png
  31. +0
    -0
      doc/Informes/ubblogo.png
  32. +11
    -5
      doc/meson.build
  33. +69
    -0
      lib/db/arrienda.vala
  34. +94
    -0
      lib/db/asociado.vala
  35. +50
    -0
      lib/db/categoria.vala
  36. +58
    -0
      lib/db/ciudad.vala
  37. +51
    -0
      lib/db/contacto_emergencia.vala
  38. +53
    -0
      lib/db/descuento.vala
  39. +56
    -0
      lib/db/empresa.vala
  40. +50
    -0
      lib/db/enfermedad.vala
  41. +50
    -0
      lib/db/especialidad.vala
  42. +69
    -0
      lib/db/guia.vala
  43. +69
    -0
      lib/db/lugar.vala
  44. +90
    -0
      lib/db/participa.vala
  45. +74
    -0
      lib/db/posee.vala
  46. +87
    -0
      lib/db/realiza.vala
  47. +50
    -0
      lib/db/region.vala
  48. +77
    -0
      lib/db/requerir_auto.vala
  49. +66
    -0
      lib/db/tiene_enfermedad.vala
  50. +72
    -0
      lib/db/tour.vala
  51. +62
    -0
      lib/db/turista.vala
  52. +56
    -0
      lib/db/vehiculo.vala
  53. +64
    -0
      lib/dbwrapper.vala
  54. +44
    -0
      lib/meson.build
  55. +139
    -0
      lib/rut.vala
  56. +9
    -1
      meson.build
  57. +4
    -0
      meson_options.txt
  58. +2
    -0
      po/POTFILES
  59. +28
    -22
      po/es.po
  60. +18
    -15
      po/sernatur.pot
  61. +5
    -17
      src/meson.build
  62. +86
    -53
      src/sernatur-window.vala
  63. +3
    -3
      src/sernatur.vala

+ 1
- 0
data/ui/sernatur.gresource.xml View File

@@ -15,6 +15,7 @@
<gresources>
<gresource prefix="/cl/cromer/ubb/sernatur">
<file preprocess="xml-stripblanks">sernatur.window.ui</file>
<file preprocess="xml-stripblanks">splash.ui</file>
<file preprocess="to-pixdata">pixdata/logo-sernatur.svg</file>
</gresource>
</gresources>

+ 39
- 110
data/ui/sernatur.window.ui View File

@@ -14,8 +14,8 @@ Redistribution and use in source and binary forms, with or without modification,
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.

-->
<interface>
<requires lib="gtk+" version="3.10"/>
<interface domain="sernatur">
<requires lib="gtk+" version="3.20"/>
<template class="SernaturMainWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="title">SERNATUR</property>
@@ -31,6 +31,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="baseline_position">top</property>
<child>
<object class="GtkMenuBar" id="menubar">
<property name="visible">True</property>
@@ -39,46 +40,64 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_File</property>
<property name="label" translatable="yes">_Menu</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-new</property>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="right_justified">True</property>
<property name="label" translatable="yes">Tours</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-open</property>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Guides and Staff</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-save</property>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tourists</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Illnesses</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tour</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-save-as</property>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Vehicles</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
@@ -88,93 +107,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-delete</property>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Quit</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="menu_quit" swapped="no"/>
</object>
</child>
</object>
@@ -189,16 +127,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
</packing>
</child>
<child>
<object class="GtkImage" id="logo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="resource">/cl/cromer/ubb/sernatur/pixdata/logo-sernatur.svg</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
</object>
</child>

+ 55
- 0
data/ui/splash.ui View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1

Copyright 2018 Chris Cromer

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

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.

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.

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.

-->
<interface domain="sernatur">
<requires lib="gtk+" version="3.20"/>
<object class="GtkGrid" id="content_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="resource">/cl/cromer/ubb/sernatur/pixdata/logo-sernatur.svg</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Christopher Cromer</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</interface>

doc/trabajoSemestral(E1).pdf → doc/Enunciados/trabajoSemestral(E1).pdf View File


doc/trabajoSemestral(E2).pdf → doc/Enunciados/trabajoSemestral(E2).pdf View File


BIN
doc/Enunciados/trabajoSemestral(E3).pdf View File


doc/Informe1.pdf → doc/Informes/Informe1.pdf View File


doc/Informe1.tex → doc/Informes/Informe1.tex View File


doc/Informe1_creartablas.sql → doc/Informes/Informe1_creartablas.sql View File


doc/Informe1_insertarduplas.sql → doc/Informes/Informe1_insertarduplas.sql View File


doc/Informe1corregido.pdf → doc/Informes/Informe1corregido.pdf View File


doc/Informe1corregido.tex → doc/Informes/Informe1corregido.tex View File


doc/Informe1corregido_creartablas.sql → doc/Informes/Informe1corregido_creartablas.sql View File


doc/Informe1corregido_insertarduplas.sql → doc/Informes/Informe1corregido_insertarduplas.sql View File


doc/Informe2.pdf → doc/Informes/Informe2.pdf View File


doc/Informe2.tex → doc/Informes/Informe2.tex View File


doc/Informe2_Q1.png → doc/Informes/Informe2_Q1.png View File


doc/Informe2_Q2.png → doc/Informes/Informe2_Q2.png View File


doc/Informe2_Q3.png → doc/Informes/Informe2_Q3.png View File


doc/Informe2_Q4.png → doc/Informes/Informe2_Q4.png View File


doc/Informe2_Q5.png → doc/Informes/Informe2_Q5.png View File


doc/Informe2_vistaQ1.sql → doc/Informes/Informe2_vistaQ1.sql View File


doc/Informe2_vistaQ2.sql → doc/Informes/Informe2_vistaQ2.sql View File


doc/Informe2_vistaQ3.sql → doc/Informes/Informe2_vistaQ3.sql View File


doc/Informe2_vistaQ4.sql → doc/Informes/Informe2_vistaQ4.sql View File


doc/Informe2_vistaQ5.sql → doc/Informes/Informe2_vistaQ5.sql View File


doc/MER.dia → doc/Informes/MER.dia View File


doc/MER.png → doc/Informes/MER.png View File


doc/MERcorregido.dia → doc/Informes/MERcorregido.dia View File


doc/MERcorregido.png → doc/Informes/MERcorregido.png View File


doc/ubblogo.png → doc/Informes/ubblogo.png View File


+ 11
- 5
doc/meson.build View File

@@ -1,6 +1,7 @@
docs_enabled = get_option('valadocs')
valadoc = find_program('valadoc', required: docs_enabled)
vala_doc_sources = vala_sources
vala_doc_sources += lib_sources
if docs_enabled
valadocs_deps = get_option('valadocs_deps')
docs_deps = ['--pkg=gtk+-3.0']
@@ -29,10 +30,15 @@ if docs_enabled
)
endif

install_data('trabajoSemestral(E1).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('trabajoSemestral(E2).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informe1.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('MER.dia', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('MER.png', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Enunciados/trabajoSemestral(E1).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Enunciados/trabajoSemestral(E2).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Enunciados/trabajoSemestral(E3).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/Informe1.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/Informe1corregido.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/Informe2.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/MER.dia', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/MER.png', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/MERcorregido.dia', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('Informes/MERcorregido.png', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('../LICENSE', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
install_data('../README.md', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))

+ 69
- 0
lib/db/arrienda.vala View File

@@ -0,0 +1,69 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Arrienda : GLib.Object {
public uint precio { get; set; default = 0; }
public string fecha_devolucion { get; set; default = ""; }
public Vehiculo vehiculo { get; set; default = null; }
public Empresa empresa { get; set; default = null; }

public Arrienda (uint precio = 0, string fecha_devolucion = "", Vehiculo? vehiculo = null, Empresa? empresa = null) {
this.precio = precio;
this.fecha_devolucion = fecha_devolucion;
this.vehiculo = vehiculo;
this.empresa = empresa;
}

public static Arrienda[]? get_all_arriendas(Database conn) {
var res = conn.exec ("
SELECT A.precio, A.fecha_devolucion,
V.patente, V.ano_vehiculo, V.marca, V.capacidad,
E.rut_empresa, E.nombre_empresa, E.contacto, E.telefono
FROM arrienda A
JOIN vehiculo V ON (A.patente = V.patente)
JOIN empresa E ON (A.rut_empresa = E.rut_empresa)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Arrienda[] arriendas = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var arrienda = new Arrienda (wra.get_int_n (i, "precio"),
wra.get_string_n (i, "fecha_devolucion"),
new Vehiculo (wra.get_string_n (i, "patente"),
wra.get_int_n (i, "ano_vehiculo"),
wra.get_string_n (i, "marca"),
wra.get_int_n (i, "capacidad")
),
new Empresa (wra.get_string_n (i, "rut_empresa"),
wra.get_string_n (i, "nombre_empresa"),
wra.get_string_n (i, "contacto"),
wra.get_int_n (i, "telefono")
)
);
arriendas += arrienda;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return arriendas;
}
}
}
}

+ 94
- 0
lib/db/asociado.vala View File

@@ -0,0 +1,94 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Asociado : GLib.Object {
public string fecha_llegada { get; set; default = ""; }
public string hora_llegada { get; set; default = ""; }
public string fecha_salida { get; set; default = ""; }
public string hora_salida { get; set; default = ""; }
public Tour tour { get; set; default = null; }
public Lugar lugar { get; set; default = null; }

public Asociado (string fecha_llegada = "", string hora_llegada = "", string fecha_salida = "", string hora_salida = "", Tour? tour = null, Lugar? lugar = null) {
this.fecha_llegada = fecha_llegada;
this.hora_llegada = hora_llegada;
this.fecha_salida = fecha_salida;
this.hora_salida = hora_salida;
}

public static Asociado[]? get_all_asociados(Database conn) {
var res = conn.exec ("
SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida
T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel
C2.id_ciudad AS id_ciudad_lugar, C2.nombre_ciudad AS nombre_ciudad_lugar,
R2.id_region AS id_region_lugar, R2.nombre_region AS nombre_region_lugar
FROM asociado A
JOIN tour T ON (A.id_tour = T.id_tour)
JOIN ciudad C ON (T.id_cuidad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
JOIN lugar L ON (A.id_lugar = L.id_lugar)
JOIN ciudad C2 ON (L.id_ciudad = C2.id_ciudad)
JOIN region R2 ON (C2.id_region = R2.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Asociado[] asociados = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var asociado = new Asociado (wra.get_string_n (i, "fecha_llegada"),
wra.get_string_n (i, "hora_llegada"),
wra.get_string_n (i, "fecha_salida"),
wra.get_string_n (i, "hora_salida"),
new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
new Lugar (wra.get_int_n (i, "id_lugar"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "valor_entrada"),
wra.get_int_n (i, "nivel"),
new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"),
wra.get_string_n (i, "nombre_ciudad_lugar"),
new Region (wra.get_int_n (i, "id_region_lugar"),
wra.get_string_n (i, "nombre_region_lugar")
)
)
)
);
asociados += asociado;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return asociados;
}
}
}
}

+ 50
- 0
lib/db/categoria.vala View File

@@ -0,0 +1,50 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Categoria : GLib.Object {
public uint id_categoria { get; set; default = 0; }
public string descripcion_categoria { get; set; default = ""; }

public Categoria (uint id_categoria = 0, string descripcion_categoria = "") {
this.id_categoria = id_categoria;
this.descripcion_categoria = descripcion_categoria;
}

public static Categoria[]? get_all_categorias(Database conn) {
var res = conn.exec ("
SELECT id_categoria, descripcion_categoria FROM categoria
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Categoria[] categorias = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var categoria = new Categoria (wra.get_int_n (i, "id_categoria"),
wra.get_string_n (i, "descripcion_categoria")
);
categorias += categoria;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return categorias;
}
}
}
}

+ 58
- 0
lib/db/ciudad.vala View File

@@ -0,0 +1,58 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Ciudad : GLib.Object {
public uint id_ciudad { get; set; default = 0; }
public string nombre_ciudad { get; set; default = ""; }
public Region region { get; set; default = null; }

public Ciudad (uint id_ciudad = 0, string nombre_ciudad = "", Region? region = null) {
this.id_ciudad = id_ciudad;
this.nombre_ciudad = nombre_ciudad;
this.region = region;
}

public static Ciudad[]? get_all_ciudades(Database conn) {
var res = conn.exec ("
SELECT C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
FROM ciudad C
JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Ciudad[] ciudades = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var ciudad = new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
);
ciudades += ciudad;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return ciudades;
}
}
}
}

+ 51
- 0
lib/db/contacto_emergencia.vala View File

@@ -0,0 +1,51 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class ContactoEmergencia : GLib.Object {
public uint id_contacto { get; set; default = 0; }
public uint telefono_emergencia { get; set; default = 0; }
public string nombre_emergencia { get; set; default = ""; }

public ContactoEmergencia (uint id_contacto = 0, uint telefono_emergencia = 0, string nombre_emergencia = "") {
this.id_contacto = id_contacto;
this.telefono_emergencia = telefono_emergencia;
this.nombre_emergencia = nombre_emergencia;
}

public static ContactoEmergencia[]? get_all_contactos(Database conn) {
var res = conn.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
ContactoEmergencia[] contactos = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var contacto = new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
wra.get_int_n (i, "telefono_emergencia"),
wra.get_string_n (i, "nombre_emergencia")
);
contactos += contacto;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return contactos;
}
}
}
}

+ 53
- 0
lib/db/descuento.vala View File

@@ -0,0 +1,53 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Descuento : GLib.Object {
public uint id_descuento { get; set; default = 0; }
public string descripcion_descuento { get; set; default = ""; }
public float porcentaje { get; set; default = 0; }

public Descuento (uint id_descuento = 0, string descripcion_descuento = "", float porcentaje = 0) {
this.id_descuento = id_descuento;
this.descripcion_descuento = descripcion_descuento;
this.porcentaje = porcentaje;
}

public static Descuento[]? get_all_descuentos(Database conn) {
var res = conn.exec ("
SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Descuento[] descuentos = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var descuento = new Descuento (wra.get_int_n (i, "id_descuento"),
wra.get_string_n (i, "descripcion_descuento"),
wra.get_float_n (i, "porcentaje")
);
descuentos += descuento;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return descuentos;
}
}
}
}

+ 56
- 0
lib/db/empresa.vala View File

@@ -0,0 +1,56 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Empresa : GLib.Object {
public string rut_empresa { get; set; default = ""; }
public string nombre_empresa { get; set; default = ""; }
public string contacto { get; set; default = ""; }
public uint telefono { get; set; default = 0; }

public Empresa (string rut_empresa = "", string nombre_empresa = "", string contacto = "", uint telefono = 0) {
this.rut_empresa = rut_empresa;
this.nombre_empresa = nombre_empresa;
this.contacto = contacto;
this.telefono = telefono;
}

public static Empresa[]? get_all_empresas(Database conn) {
var res = conn.exec ("
SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Empresa[] empresas = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var empresa = new Empresa (wra.get_string_n (i, "rut_empresa"),
wra.get_string_n (i, "nombre_empresa"),
wra.get_string_n (i, "contacto"),
wra.get_int_n (i, "telefono")
);
empresas += empresa;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return empresas;
}
}
}
}

+ 50
- 0
lib/db/enfermedad.vala View File

@@ -0,0 +1,50 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Enfermedad : GLib.Object {
public uint id_enfermedad { get; set; default = 0; }
public string descripcion_enfermedad { get; set; default = ""; }

public Enfermedad (uint id_enfermedad = 0, string descripcion_enfermedad = "") {
this.id_enfermedad = id_enfermedad;
this.descripcion_enfermedad = descripcion_enfermedad;
}

public static Enfermedad[]? get_all_enfermedades(Database conn) {
var res = conn.exec ("
SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Enfermedad[] enfermedades = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var enfermedad = new Enfermedad (wra.get_int_n (i, "id_enfermedad"),
wra.get_string_n (i, "descripcion_enfermedad")
);
enfermedades += enfermedad;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return enfermedades;
}
}
}
}

+ 50
- 0
lib/db/especialidad.vala View File

@@ -0,0 +1,50 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Especialidad : GLib.Object {
public uint id_especialidad { get; set; default = 0; }
public string descripcion_especialidad { get; set; default = ""; }

public Especialidad (uint id_especialidad = 0, string descripcion_especialidad = "") {
this.id_especialidad = id_especialidad;
this.descripcion_especialidad = descripcion_especialidad;
}

public static Especialidad[]? get_all_especialidades(Database conn) {
var res = conn.exec ("
SELECT id_especialidad, descripcion_especialidad FROM especialidad
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Especialidad[] especialidades = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var especialidad = new Especialidad (wra.get_int_n (i, "id_especialidad"),
wra.get_string_n (i, "descripcion_especialidad")
);
especialidades += especialidad;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return especialidades;
}
}
}
}

+ 69
- 0
lib/db/guia.vala View File

@@ -0,0 +1,69 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Guia : GLib.Object {
public string rut_guia { get; set; default = ""; }
public string nombre_guia { get; set; default = ""; }
public string calle { get; set; default = ""; }
public uint numero { get; set; default = 0; }
public Ciudad ciudad { get; set; default = null; }

public Guia (string rut_guia = "", string nombre_guia = "", string calle = "", uint numero = 0, Ciudad? ciudad = null) {
this.rut_guia = rut_guia;
this.nombre_guia = nombre_guia;
this.calle = calle;
this.numero = numero;
this.ciudad = ciudad;
}

public static Guia[]? get_all_guias(Database conn) {
var res = conn.exec ("
SELECT G.rut_guia, G.nombre_guia, G.calle, G.numero,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
FROM guia G
JOIN ciudad C ON (G.id_ciudad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Guia[] guias = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var guia = new Guia (wra.get_string_n (i, "rut_guia"),
wra.get_string_n (i, "nombre_guia"),
wra.get_string_n (i, "calle"),
wra.get_int_n (i, "numero"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
);
guias += guia;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return guias;
}
}
}
}

+ 69
- 0
lib/db/lugar.vala View File

@@ -0,0 +1,69 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Lugar : GLib.Object {
public uint id_lugar { get; set; default = 0; }
public string nombre_lugar { get; set; default = ""; }
public uint valor_entrada { get; set; default = 0; }
public uint nivel { get; set; default = 0; }
public Ciudad ciudad { get; set; default = null; }

public Lugar (uint id_lugar = 0, string nombre_lugar = "", uint valor_entrada = 0, uint nivel = 0, Ciudad? ciudad = null) {
this.id_lugar = id_lugar;
this.nombre_lugar = nombre_lugar;
this.valor_entrada = valor_entrada;
this.nivel = nivel;
this.ciudad = ciudad;
}

public static Lugar[]? get_all_lugares(Database conn) {
var res = conn.exec ("
SELECT L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
FROM lugar L
JOIN ciudad C ON (L.id_ciudad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Lugar[] lugares = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var lugar = new Lugar (wra.get_int_n (i, "id_lugar"),
wra.get_string_n (i, "nombre_lugar"),
wra.get_int_n (i, "valor_entrada"),
wra.get_int_n (i, "nivel"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region(wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
);
lugares += lugar;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return lugares;
}
}
}
}

+ 90
- 0
lib/db/participa.vala View File

@@ -0,0 +1,90 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Participa : GLib.Object {
public Tour tour { get; set; default = null; }
public Guia guia { get; set; default = null; }
public Categoria categoria { get; set; default = null; }

public Participa (Tour? tour = null, Guia? guia = null, Categoria? categoria = null) {
this.tour = tour;
this.guia = guia;
this.categoria = categoria;
}

public static Participa[]? get_all_participas(Database conn) {
var res = conn.exec ("
SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
G.rut_guia, G.nombre_guia, G.calle, G.numero,
C2.id_ciudad AS id_ciudad_guia, C2.nombre_ciudad AS nombre_ciudad_guia,
R2.id_region AS id_region_guia, R2.nombre_region AS nombre_region_guia,
C3.id_categoria, C3.descripcion_categoria
FROM participa P
JOIN tour T ON (P.id_tour = T.id_tour)
JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
JOIN region R on (C.id_region = R.id_region)
JOIN guia G on (P.rut_guia = G.rut_guia)
JOIN ciudad C2 ON (G.id_ciudad = C2.id_ciudad)
JOIN region R2 ON (C2.id_region = R2.id_region)
JOIN categoria C3 ON (P.id_categoria = C3.id_categoria)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper(res);
Participa[] participas = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var participa = new Participa (
new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
new Guia (wra.get_string_n (i, "rut_guia"),
wra.get_string_n (i, "nombre_guia"),
wra.get_string_n (i, "calle"),
wra.get_int_n (i, "numero"),
new Ciudad (wra.get_int_n (i, "id_ciudad_guia"),
wra.get_string_n (i, "id_region_guia"),
new Region (wra.get_int_n (i, "id_region_guia"),
wra.get_string_n (i, "nombre_region_guia"))
)
),
new Categoria (wra.get_int_n (i, "id_categoria"),
wra.get_string_n (i, "descripcion_categoria")
)
);
participas += participa;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return participas;
}
}
}
}

+ 74
- 0
lib/db/posee.vala View File

@@ -0,0 +1,74 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Posee : GLib.Object {
public uint nivel_especialidad { get; set; default = 0; }
public Guia guia { get; set; default = null; }
public Especialidad especialidad { get; set; default = null; }

public Posee (uint nivel_especialidad = 0, Guia? guia = null, Especialidad? especialidad = null) {
this.nivel_especialidad = nivel_especialidad;
this.guia = guia;
this.especialidad = especialidad;
}

public static Posee[]? get_all_posees(Database conn) {
var res = conn.exec ("
SELECT P.nivel_especialidad,
G.rut_guia, G.nombre_guia, G.calle, G.numero,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
E.id_especialidad, E.descripcion_especialidad
FROM posee P
JOIN guia G on (P.rut_guia = G.rut_guia)
JOIN ciudad C ON (G.id_ciudad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
JOIN especialidad E ON (P.id_especialidad = E.id_especialidad)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Posee[] posees = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var posee = new Posee (wra.get_int_n (i, "nivel_especialidad"),
new Guia (wra.get_string_n (i, "rut_guia"),
wra.get_string_n (i, "nombre_guia"),
wra.get_string_n (i, "calle"),
wra.get_int_n (i, "numero"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
new Especialidad (wra.get_int_n (i, "id_especialidad"),
wra.get_string_n (i, "descripcion_especialidad")
)
);
posees += posee;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return posees;
}
}
}
}

+ 87
- 0
lib/db/realiza.vala View File

@@ -0,0 +1,87 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Realiza : GLib.Object {
public Tour tour { get; set; default = null; }
public Turista turista { get; set; default = null; }
public Descuento descuento { get; set; default = null; }

public Realiza (Tour? tour = null, Turista? turista = null, Descuento? descuento = null) {
this.tour = tour;
this.turista = turista;
this.descuento = descuento;
}

public static Realiza[]? get_all_realizas(Database conn) {
var res = conn.exec ("
SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
T2.rut_turista, T2.nombre_turista, T2.fecha_nacimento,
C2.id_contacto, C2.telefono_emergencia, C2.nombre_emergencia,
D.id_descuento, D.descripcion_descuento, D.porcentaje
FROM realiza RE
JOIN tour T ON (RE.id_tour = T.id_tour)
JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
JOIN turista T2 ON (RE.rut_turista = T2.rut_turista)
JOIN contacto_emergencia C2 ON (T2.id_contacto = C2.id_contacto)
JOIN descuento D ON (RE.id_descuento = D.id_descuento)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Realiza[] realizas = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var realiza = new Realiza (
new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
new Turista (wra.get_string_n (i, "rut_turista"),
wra.get_string_n (i, "nombre_turista"),
wra.get_string_n (i, "fecha_nacimento"),
new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
wra.get_int_n (i, "telefono_emergencia"),
wra.get_string_n (i, "nombre_emergencia")
)
),
new Descuento (wra.get_int_n (i, "id_descuento"),
wra.get_string_n (i, "descripcion_descuento"),
wra.get_float_n (i, "porcentaje")
)
);
realizas += realiza;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return realizas;
}
}
}
}

+ 50
- 0
lib/db/region.vala View File

@@ -0,0 +1,50 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Region : GLib.Object {
public uint id_region { get; set; default = 0; }
public string nombre_region { get; set; default = ""; }

public Region (uint id_region = 0, string nombre_region = "") {
this.id_region = id_region;
this.nombre_region = nombre_region;
}

public static Region[]? get_all_regiones(Database conn) {
var res = conn.exec ("
SELECT id_region, nombre_region FROM region
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Region[] regiones = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var region = new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
);
regiones += region;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return regiones;
}
}
}
}

+ 77
- 0
lib/db/requerir_auto.vala View File

@@ -0,0 +1,77 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class RequerirAuto : GLib.Object {
public string chofer { get; set; default = ""; }
public Tour tour { get; set; default = null; }
public Vehiculo vehiculo { get; set; default = null; }

public RequerirAuto (string chofer = "", Tour? tour = null, Vehiculo? vehiculo = null) {
this.chofer = chofer;
this.tour = tour;
this.vehiculo = vehiculo;
}

public static RequerirAuto[]? get_all_requerir_autos(Database conn) {
var res = conn.exec ("
SELECT R.chofer,
T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R2.id_region, R2.nombre_region,
V.patente, V.ano_vehiculo, V.marca, V.capacidad
FROM requerir_auto R
JOIN tour T ON (R.id_tour = T.id_tour)
JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
JOIN region R2 ON (C.id_region = R2.id_region)
Join vehiculo V ON (R.patente = V.patente)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper(res);
RequerirAuto[] requerir_autos = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var requerir_auto = new RequerirAuto (wra.get_string_n (i, "chofer"),
new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
new Vehiculo (wra.get_string_n (i, "patente"),
wra.get_int_n (i, "ano_vehiculo"),
wra.get_string_n (i, "marca"),
wra.get_int_n (i, "capacidad")
)
);
requerir_autos += requerir_auto;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return requerir_autos;
}
}
}
}

+ 66
- 0
lib/db/tiene_enfermedad.vala View File

@@ -0,0 +1,66 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class TieneEnfermedad : GLib.Object {
public Turista turista { get; set; default = null; }
public Enfermedad enfermedad { get; set; default = null; }

public TieneEnfermedad (Turista? turista = null, Enfermedad? enfermedad = null) {
this.turista = turista;
this.enfermedad = enfermedad;
}

public static TieneEnfermedad[]? get_all_tiene_enfermedades(Database conn) {
var res = conn.exec ("
SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
C.id_contacto, C.telefono_emergencia, C.nombre_emergencia,
E.id_enfermedad, E.descripcion_enfermedad
FROM tiene_enfermedad TE
JOIN turista T ON (TE.rut_turista = T.rut_turista)
JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto)
JOIN enfermedad E ON (TE.id_enfermedad = E.id_enfermedad)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
TieneEnfermedad[] tiene_enfermedades = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var tiene_enfermedad = new TieneEnfermedad (
new Turista (wra.get_string_n (i, "rut_turista"),
wra.get_string_n (i, "nombre_turista"),
wra.get_string_n (i, "fecha_nacimento"),
new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
wra.get_int_n (i, "telefono_emergencia"),
wra.get_string_n (i, "nombre_emergencia")
)
),
new Enfermedad (wra.get_int_n (i, "id_enfermedad"),
wra.get_string_n (i, "descripcion_enfermedad")
)
);
tiene_enfermedades += tiene_enfermedad;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return tiene_enfermedades;
}
}
}
}

+ 72
- 0
lib/db/tour.vala View File

@@ -0,0 +1,72 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Tour : GLib.Object {
public uint id_tour { get; set; default = 0; }
public string nombre_tour { get; set; default = ""; }
public uint costo_indiv { get; set; default = 0; }
public uint costo_grupal { get; set; default = 0; }
public uint minima_personas { get; set; default = 0; }
public Ciudad ciudad { get; set; default = null; }

public Tour (uint id_tour = 0, string nombre_tour = "", uint costo_indiv = 0, uint costo_grupal = 0, uint minima_personas = 0, Ciudad? ciudad = null) {
this.id_tour = id_tour;
this.nombre_tour = nombre_tour;
this.costo_indiv = costo_indiv;
this.costo_grupal = costo_grupal;
this.minima_personas = minima_personas;
this.ciudad = ciudad;
}

public static Tour[]? get_all_tours(Database conn) {
var res = conn.exec ("
SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
FROM tour T
JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Tour[] tours = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var tour = new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
);
tours += tour;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return tours;
}
}
}
}

+ 62
- 0
lib/db/turista.vala View File

@@ -0,0 +1,62 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Turista : GLib.Object {
public string rut_turista { get; set; default = ""; }
public string nombre_turista { get; set; default = ""; }
public string fecha_nacimento { get; set; default = ""; }
public ContactoEmergencia contacto_emergencia { get; set; default = null; }

public Turista (string rut_turista = "", string nombre_turista = "", string fecha_nacimento = "", ContactoEmergencia? contacto_emergencia = null) {
this.rut_turista = rut_turista;
this.nombre_turista = nombre_turista;
this.fecha_nacimento = fecha_nacimento;
this.contacto_emergencia = contacto_emergencia;
}

public static Turista[]? get_all_turistas(Database conn) {
var res = conn.exec ("
SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
C.id_contacto, C.telefono_emergencia, C.nombre_emergencia
FROM turista T
JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Turista[] turistas = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var turista = new Turista (wra.get_string_n (i, "rut_turista"),
wra.get_string_n (i, "nombre_turista"),
wra.get_string_n (i, "fecha_nacimento"),
new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
wra.get_int_n (i, "telefono_emergencia"),
wra.get_string_n (i, "nombre_emergencia")
)
);
turistas += turista;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return turistas;
}
}
}
}

+ 56
- 0
lib/db/vehiculo.vala View File

@@ -0,0 +1,56 @@
namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;

public class Vehiculo : GLib.Object {
public string patente { get; set; default = ""; }
public uint ano_vehiculo { get; set; default = 0; }
public string marca { get; set; default = ""; }
public uint capacidad { get; set; default = 0; }

public Vehiculo (string patente = "", uint ano_vehiculo = 0, string marca = "", uint capacidad = 0) {
this.patente = patente;
this.ano_vehiculo = ano_vehiculo;
this.marca = marca;
this.capacidad = capacidad;
}

public static Vehiculo[]? get_all_vehiculos(Database conn) {
var res = conn.exec ("
SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}

var wra = new ResultWrapper (res);
Vehiculo[] vehiculos = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var vehiculo = new Vehiculo (wra.get_string_n (i, "patente"),
wra.get_int_n (i, "ano_vehiculo"),
wra.get_string_n (i, "marca"),
wra.get_int_n (i, "capacidad")
);
vehiculos += vehiculo;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return vehiculos;
}
}
}
}

+ 64
- 0
lib/dbwrapper.vala View File

@@ -0,0 +1,64 @@
namespace Sernatur {
/**
* This is the database namespace for Sernatur
*/
namespace DB {
/**
* This is a wrapper for Postgres that allows easier use of the database
*/
namespace Wrapper {
using Postgres;

public errordomain Field {
NOTFOUND
}

public class ResultWrapper : GLib.Object {
public unowned Result result { get; set; default = null; }

public ResultWrapper (Result? result = null) {
this.result = result;
}

public string get_string_v (int tup_num, int field_num) {
return result.get_value (tup_num, field_num);
}

public int get_int_v (int tup_num, int field_num) {
return int.parse (result.get_value (tup_num, field_num));
}

public float get_float_v (int tup_num, int field_num) {
return float.parse(result.get_value (tup_num, field_num));
}

public double get_double_v (int tup_num, int field_num) {
return double.parse (result.get_value (tup_num, field_num));
}

public string get_string_n (int tup_num, string name) throws Field {
return get_string_v (tup_num, check_field_found (result.get_field_number (name), name));;
}

public int get_int_n (int tup_num, string name) throws Field {
return get_int_v (tup_num, check_field_found (result.get_field_number (name), name));;
}

public float get_float_n (int tup_num, string name) throws Field {
return get_float_v (tup_num, check_field_found (result.get_field_number (name), name));;
}

public double get_double_n (int tup_num, string name) throws Field {
return get_double_v (tup_num, check_field_found (result.get_field_number (name), name));
}

private int check_field_found (int field_num, string name) throws Field {
if (field_num == -1) {
throw new Field.NOTFOUND (dgettext (null, "The field %s was not found in the query results!"), name);
}
return field_num;
}
}
}
}
}

+ 44
- 0
lib/meson.build View File

@@ -0,0 +1,44 @@
glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')
pq_dep = dependency('libpq', version: '>=9.0')

lib_sources = files(
'dbwrapper.vala',
'rut.vala',
'db/arrienda.vala',
'db/asociado.vala',
'db/categoria.vala',
'db/ciudad.vala',
'db/contacto_emergencia.vala',
'db/descuento.vala',
'db/empresa.vala',
'db/enfermedad.vala',
'db/especialidad.vala',
'db/guia.vala',
'db/lugar.vala',
'db/participa.vala',
'db/posee.vala',
'db/realiza.vala',
'db/region.vala',
'db/requerir_auto.vala',
'db/tiene_enfermedad.vala',
'db/tour.vala',
'db/turista.vala',
'db/vehiculo.vala')

vala_args = ['--vapidir='+join_paths(meson.source_root(),'vapi')]

sernatur_lib = library('sernatur',
lib_sources,
vala_header: 'sernatur.h',
vala_vapi: 'sernatur-1.0.0.vapi',
# vala_gir: 'Sernatur-1.0.0.gir',
vala_args: vala_args,
dependencies: [glib_dep, gobject_dep, pq_dep],
version: '1.0.0',
soversion: '1',
install: true,
install_dir: [true, true, true])

pkg_mod = import('pkgconfig')
pkg_mod.generate(sernatur_lib)

+ 139
- 0
lib/rut.vala View File

@@ -0,0 +1,139 @@
namespace Sernatur {
namespace Person {

public errordomain InvalidRut {
INVALID,
TOOLARGE,
INVALIDVERIFIER
}

public class Rut : GLib.Object {
private string clean_rut;
private string pretty_rut;
private unichar verifier;

public enum Type {
RUN,
RUT
}

public Rut (string rut) throws InvalidRut {
parse (rut);
}

private void parse (string rut) throws InvalidRut {
try {
var regex = new Regex ("^[ ]*([0-9.]{0,11}[\\-]?[0-9kK])?[ ]*$");
if (!regex.match (rut)) {
throw new InvalidRut.INVALID (dgettext (null, "The RUT %s has an invalid character!"), rut);
}
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
try {
var regex = new Regex ("([.-])");
string new_rut = rut.up ();
new_rut = new_rut.strip ();
rut = regex.replace (new_rut, new_rut.length, 0, "");
if (int.parse (rut.substring (0, rut.length - 1)) > 100000000) {
throw new InvalidRut.TOOLARGE (dgettext (null, "The RUT %s is too big!"), rut);
}
this.verifier = rut.get_char (rut.length - 1);
this.clean_rut = rut.substring (0, rut.length - 1);
if (generate_verfifier (this.clean_rut) != this.verifier) {
throw new InvalidRut.INVALIDVERIFIER (dgettext (null, "The verifier %C is invalid!"), this.verifier);
}
pretty();
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}

private void pretty () {
string new_rut = "";
string temp_rut = this.clean_rut.reverse ();
int rut_length = this.clean_rut.length;
for (int i = 0; i < rut_length; i++) {
new_rut = new_rut + temp_rut.get_char(i).to_string ();
if ((i + 1) % 3 == 0) {
new_rut = new_rut + ".";
}
}
new_rut = new_rut.reverse ();
this.pretty_rut = new_rut + "-" + this.verifier.to_string ();
}

private unichar generate_verfifier (string rut) {
/**
* 1. Multiply each digit of the RUT by 2, 3, ..., 7, 2, 3, ... from the end of the RUT moving forward.
* 2. Add the partial multiplications.
* 3. Calculate the remainder of the division by 11.
* 4. The verifier is 11 minus the previous result. If the result is 10, change it to K.
*/
int multiplier = 2;
int sum = 0;
int remainder;
int division;
int rut_length = rut.length;

// Steps 1 and 2
for (int i = rut_length - 1; i >= 0; i--) {
sum = sum + (int.parse (rut.substring(i, 1)) * multiplier);
multiplier++;
if (multiplier == 8) {
multiplier = 2;
}
}

// Step 3
division = sum / 11;
division = division * 11;
remainder = sum - division;

// Step 4
if (remainder != 0) {
remainder = 11 - remainder;
}

// Let's return their verifier
if (remainder == 10) {
// Their verifier is 10 so let's return K.
return 'K';
}
else {
return (unichar) remainder + '0';
}
}

public string get_clean_rut () {
return this.clean_rut + this.verifier.to_string ();
}

public string get_rut () {
return this.pretty_rut;
}

public Type type () {
uint rut = int.parse (this.clean_rut);
if (rut < 100000000 && rut > 50000000) {
// Company
return Type.RUT;
}
else {
// Person
return Type.RUN;
}
}
}
}
}

+ 9
- 1
meson.build View File

@@ -3,6 +3,7 @@ project('sernatur',
version: '1.0.0',
license: 'BSD-3',
default_options: [
'c_std=c11',
'b_ofast=if-release',
'b_march_native=if-release',
'b_ndebug=if-release'
@@ -10,12 +11,19 @@ project('sernatur',
)
add_global_arguments('-DGETTEXT_PACKAGE="sernatur"', language: 'c')

debugging = get_option('debugging')
if debugging
add_global_arguments('-DDEBUG', language : 'c')
add_global_arguments('-D', 'DEBUG', language : 'vala')
endif

add_project_arguments(['--vapidir',
join_paths(meson.current_source_dir(), 'src/vapi')],
join_paths(meson.current_source_dir(), 'vapi')],
language: 'vala')

subdir('po')
subdir('data')
subdir('lib')
subdir('src')
subdir('doc')
subdir('script')

+ 4
- 0
meson_options.txt View File

@@ -1,3 +1,7 @@
option('debugging',
type: 'boolean',
value: false,
description: 'Build with debugging preprocessor')
option('valadocs',
type: 'boolean',
value: true,

+ 2
- 0
po/POTFILES View File

@@ -1,3 +1,5 @@
lib/dbwrapper.vala
lib/rut.vala
src/sernatur.vala
src/sernatur-window.vala
data/ui/sernatur.window.ui

+ 28
- 22
po/es.po View File

@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-23 19:19-0300\n"
"PO-Revision-Date: 2018-12-23 19:21-0300\n"
"POT-Creation-Date: 2019-01-03 19:19-0300\n"
"PO-Revision-Date: 2019-01-01 21:06-0300\n"
"Last-Translator: Chris Cromer <chris@cromer.cl>\n"
"Language-Team: none\n"
"Language: es\n"
@@ -18,33 +18,36 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n"

#: src/sernatur.vala:54
#: lib/dbwrapper.vala:57
#, c-format
msgid "Could not load application icon: %s\n"
msgstr "No se puede cargar el icono de la aplicación: %s\n"
msgid "The field %s was not found in the query results!"
msgstr "La campo %s no estaba en los resultados de la consulta!"

#: src/sernatur-window.vala:97
msgid "Error"
msgstr "Error"
#: lib/rut.vala:28
#, c-format
msgid "The RUT %s has an invalid character!"
msgstr "El RUT %s tiene un carácter invalido!"

#: src/sernatur-window.vala:125
msgid "Server version:"
msgstr "Versión del servidor:"
#: lib/rut.vala:44
#, c-format
msgid "The RUT %s is too big!"
msgstr "El RUT %s es demasiado grande!"

#: data/ui/sernatur.window.ui:42
msgid "_File"
msgstr ""
#: lib/rut.vala:49
#, c-format
msgid "The verifier %C is invalid!"
msgstr "El verificador %C es invalido!"

#: data/ui/sernatur.window.ui:107
msgid "_Edit"
msgstr ""
#: src/sernatur-window.vala:128
msgid "Error"
msgstr "Error"

#: data/ui/sernatur.window.ui:157
msgid "_View"
msgstr ""
#: src/sernatur-window.vala:133
msgid "Postgresql server version:"
msgstr "Versión del servidor Postgresql:"

#: data/ui/sernatur.window.ui:165
msgid "_Help"
#: data/ui/sernatur.window.ui:43
msgid "_Menu"
msgstr ""

#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5
@@ -96,3 +99,6 @@ msgstr "El ancho de la ventana"
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:20
msgid "Window height"
msgstr "La altura de la venta"

#~ msgid "Could not load application icon: %s\n"
#~ msgstr "No se puede cargar el icono de la aplicación: %s\n"

+ 18
- 15
po/sernatur.pot View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-23 19:19-0300\n"
"POT-Creation-Date: 2019-01-03 19:19-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,33 +17,36 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/sernatur.vala:54
#: lib/dbwrapper.vala:57
#, c-format
msgid "Could not load application icon: %s\n"
msgid "The field %s was not found in the query results!"
msgstr ""

#: src/sernatur-window.vala:97
msgid "Error"
#: lib/rut.vala:28