start the 3rd assignment

This commit is contained in:
Chris Cromer 2019-01-03 19:47:43 -03:00
parent 21f57a86e7
commit 18dafc38e1
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
63 changed files with 1818 additions and 233 deletions

View File

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

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. 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> <interface domain="sernatur">
<requires lib="gtk+" version="3.10"/> <requires lib="gtk+" version="3.20"/>
<template class="SernaturMainWindow" parent="GtkApplicationWindow"> <template class="SernaturMainWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title">SERNATUR</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="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="baseline_position">top</property>
<child> <child>
<object class="GtkMenuBar" id="menubar"> <object class="GtkMenuBar" id="menubar">
<property name="visible">True</property> <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"> <object class="GtkMenuItem">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</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> <property name="use_underline">True</property>
<child type="submenu"> <child type="submenu">
<object class="GtkMenu"> <object class="GtkMenu">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkImageMenuItem"> <object class="GtkMenuItem">
<property name="label">gtk-new</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="use_underline">True</property> <property name="right_justified">True</property>
<property name="use_stock">True</property> <property name="label" translatable="yes">Tours</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem"> <object class="GtkMenuItem">
<property name="label">gtk-open</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</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_underline">True</property>
<property name="use_stock">True</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem"> <object class="GtkMenuItem">
<property name="label">gtk-save</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Tourists</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="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> <property name="use_underline">True</property>
<property name="use_stock">True</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem"> <object class="GtkMenuItem">
<property name="label">gtk-save-as</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</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="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_underline">True</property>
<property name="use_stock">True</property>
</object> </object>
</child> </child>
<child> <child>
@ -87,94 +106,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<property name="can_focus">False</property> <property name="can_focus">False</property>
</object> </object>
</child> </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> <child>
<object class="GtkMenuItem"> <object class="GtkMenuItem">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">_Edit</property> <property name="label" translatable="yes">Quit</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child type="submenu"> <signal name="activate" handler="menu_quit" swapped="no"/>
<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>
<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">_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>
</object> </object>
</child> </child>
</object> </object>
@ -189,16 +127,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkImage" id="logo"> <placeholder/>
<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>
</child> </child>
</object> </object>
</child> </child>

55
data/ui/splash.ui Normal file
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>

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View File

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

@ -1,6 +1,7 @@
docs_enabled = get_option('valadocs') docs_enabled = get_option('valadocs')
valadoc = find_program('valadoc', required: docs_enabled) valadoc = find_program('valadoc', required: docs_enabled)
vala_doc_sources = vala_sources vala_doc_sources = vala_sources
vala_doc_sources += lib_sources
if docs_enabled if docs_enabled
valadocs_deps = get_option('valadocs_deps') valadocs_deps = get_option('valadocs_deps')
docs_deps = ['--pkg=gtk+-3.0'] docs_deps = ['--pkg=gtk+-3.0']
@ -29,10 +30,15 @@ if docs_enabled
) )
endif endif
install_data('trabajoSemestral(E1).pdf', 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('trabajoSemestral(E2).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('Informe1.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('MER.dia', 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('MER.png', 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('../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())) install_data('../README.md', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))

69
lib/db/arrienda.vala Normal file
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
lib/db/asociado.vala Normal file
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
lib/db/categoria.vala Normal file
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
lib/db/ciudad.vala Normal file
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;
}
}
}
}

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
lib/db/descuento.vala Normal file
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
lib/db/empresa.vala Normal file
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
lib/db/enfermedad.vala Normal file
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
lib/db/especialidad.vala Normal file
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
lib/db/guia.vala Normal file
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
lib/db/lugar.vala Normal file
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
lib/db/participa.vala Normal file
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
lib/db/posee.vala Normal file
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
lib/db/realiza.vala Normal file
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
lib/db/region.vala Normal file
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
lib/db/requerir_auto.vala Normal file
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;
}
}
}
}

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
lib/db/tour.vala Normal file
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
lib/db/turista.vala Normal file
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
lib/db/vehiculo.vala Normal file
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
lib/dbwrapper.vala Normal file
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
lib/meson.build Normal file
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
lib/rut.vala Normal file
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;
}
}
}
}
}

View File

@ -3,6 +3,7 @@ project('sernatur',
version: '1.0.0', version: '1.0.0',
license: 'BSD-3', license: 'BSD-3',
default_options: [ default_options: [
'c_std=c11',
'b_ofast=if-release', 'b_ofast=if-release',
'b_march_native=if-release', 'b_march_native=if-release',
'b_ndebug=if-release' 'b_ndebug=if-release'
@ -10,12 +11,19 @@ project('sernatur',
) )
add_global_arguments('-DGETTEXT_PACKAGE="sernatur"', language: 'c') 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', add_project_arguments(['--vapidir',
join_paths(meson.current_source_dir(), 'src/vapi')], join_paths(meson.current_source_dir(), 'vapi')],
language: 'vala') language: 'vala')
subdir('po') subdir('po')
subdir('data') subdir('data')
subdir('lib')
subdir('src') subdir('src')
subdir('doc') subdir('doc')
subdir('script') subdir('script')

View File

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

View File

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

View File

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: sernatur\n" "Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \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: 2018-12-23 19:21-0300\n" "PO-Revision-Date: 2019-01-01 21:06-0300\n"
"Last-Translator: Chris Cromer <chris@cromer.cl>\n" "Last-Translator: Chris Cromer <chris@cromer.cl>\n"
"Language-Team: none\n" "Language-Team: none\n"
"Language: es\n" "Language: es\n"
@ -18,33 +18,36 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n" "X-Generator: Poedit 2.0.6\n"
#: src/sernatur.vala:54 #: lib/dbwrapper.vala:57
#, c-format #, c-format
msgid "Could not load application icon: %s\n" msgid "The field %s was not found in the query results!"
msgstr "No se puede cargar el icono de la aplicación: %s\n" msgstr "La campo %s no estaba en los resultados de la consulta!"
#: src/sernatur-window.vala:97 #: lib/rut.vala:28
#, c-format
msgid "The RUT %s has an invalid character!"
msgstr "El RUT %s tiene un carácter invalido!"
#: lib/rut.vala:44
#, c-format
msgid "The RUT %s is too big!"
msgstr "El RUT %s es demasiado grande!"
#: lib/rut.vala:49
#, c-format
msgid "The verifier %C is invalid!"
msgstr "El verificador %C es invalido!"
#: src/sernatur-window.vala:128
msgid "Error" msgid "Error"
msgstr "Error" msgstr "Error"
#: src/sernatur-window.vala:125 #: src/sernatur-window.vala:133
msgid "Server version:" msgid "Postgresql server version:"
msgstr "Versión del servidor:" msgstr "Versión del servidor Postgresql:"
#: data/ui/sernatur.window.ui:42 #: data/ui/sernatur.window.ui:43
msgid "_File" msgid "_Menu"
msgstr ""
#: data/ui/sernatur.window.ui:107
msgid "_Edit"
msgstr ""
#: data/ui/sernatur.window.ui:157
msgid "_View"
msgstr ""
#: data/ui/sernatur.window.ui:165
msgid "_Help"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5 #: 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 #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:20
msgid "Window height" msgid "Window height"
msgstr "La altura de la venta" 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"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: sernatur\n" "Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,33 +17,36 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: src/sernatur.vala:54 #: lib/dbwrapper.vala:57
#, c-format #, c-format
msgid "Could not load application icon: %s\n" msgid "The field %s was not found in the query results!"
msgstr "" msgstr ""
#: src/sernatur-window.vala:97 #: lib/rut.vala:28
#, c-format
msgid "The RUT %s has an invalid character!"
msgstr ""
#: lib/rut.vala:44
#, c-format
msgid "The RUT %s is too big!"
msgstr ""
#: lib/rut.vala:49
#, c-format
msgid "The verifier %C is invalid!"
msgstr ""
#: src/sernatur-window.vala:128
msgid "Error" msgid "Error"
msgstr "" msgstr ""
#: src/sernatur-window.vala:125 #: src/sernatur-window.vala:133
msgid "Server version:" msgid "Postgresql server version:"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:42 #: data/ui/sernatur.window.ui:43
msgid "_File" msgid "_Menu"
msgstr ""
#: data/ui/sernatur.window.ui:107
msgid "_Edit"
msgstr ""
#: data/ui/sernatur.window.ui:157
msgid "_View"
msgstr ""
#: data/ui/sernatur.window.ui:165
msgid "_Help"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5

View File

@ -3,21 +3,7 @@ gobject_dep = dependency('gobject-2.0')
gtk_dep = dependency('gtk+-3.0', version: '>=3.0.0') gtk_dep = dependency('gtk+-3.0', version: '>=3.0.0')
# gmodule-export-2.0 is needed to connect the handlers # gmodule-export-2.0 is needed to connect the handlers
gmodule_dep = dependency('gmodule-2.0', version: '>=2.0') gmodule_dep = dependency('gmodule-2.0', version: '>=2.0')
pq_dep = dependency('libpq', version: '>=10.0') pq_dep = dependency('libpq', version: '>=9.0')
posix_dep = meson.get_compiler('vala').find_library('posix')
# this is how to link against a c lib
#libsystemd_lib = meson.get_compiler('c').find_library('libsystemd')
#cc = meson.get_compiler('c')
# -no-pie so that the executable is double clickable in gui
#if cc.get_id() == 'gcc'
# c_args = ['-no-pie']
# link_args = ['-no-pie']
#else
# c_args ''
# link_args ''
#endif
vala_sources = files( vala_sources = files(
'sernatur.vala', 'sernatur.vala',
@ -29,11 +15,13 @@ c_sources = [sernatur_gresource_c]
sources = vala_sources sources = vala_sources
sources += c_sources sources += c_sources
vala_args = ['--vapidir='+join_paths(meson.source_root(),'src/vapi')] vala_args = ['--vapidir='+join_paths(meson.source_root(),'vapi')]
vala_args += ['--gresources='+join_paths(meson.source_root(),'data/ui/sernatur.gresource.xml')] vala_args += ['--gresources='+join_paths(meson.source_root(),'data/ui/sernatur.gresource.xml')]
sernatur_dep = declare_dependency(link_with: sernatur_lib, include_directories: include_directories('../lib'))
exe = executable('sernatur', exe = executable('sernatur',
sources, sources,
vala_args: vala_args, vala_args: vala_args,
dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, posix_dep], dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, sernatur_dep],
install: true) install: true)

View File

@ -16,13 +16,16 @@
* The main Sernatur namespace * The main Sernatur namespace
*/ */
namespace Sernatur { namespace Sernatur {
using Postgres; using DB;
/** /**
* The MainWindow class * The MainWindow class
*/ */
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/sernatur.window.ui")] [GtkTemplate (ui = "/cl/cromer/ubb/sernatur/sernatur.window.ui")]
public class MainWindow : Gtk.ApplicationWindow { public class MainWindow : Gtk.ApplicationWindow {
Gtk.Grid content;
[GtkChild]
private Gtk.Box mainbox;
/** /**
* This is a callback for when the window is maximized or unmaximized * This is a callback for when the window is maximized or unmaximized
@ -32,7 +35,7 @@ namespace Sernatur {
*/ */
[GtkCallback] [GtkCallback]
private bool maximize_window(Gtk.Widget widget, Gdk.EventWindowState state) { private bool maximize_window(Gtk.Widget widget, Gdk.EventWindowState state) {
Settings settings = new Settings ("cl.cromer.ubb.sernatur.window"); var settings = new Settings ("cl.cromer.ubb.sernatur.window");
if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) { if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) {
// Maximized // Maximized
settings.set_boolean ("maximized", true); settings.set_boolean ("maximized", true);
@ -52,7 +55,7 @@ namespace Sernatur {
*/ */
[GtkCallback] [GtkCallback]
private bool resize_window(Gtk.Widget widget, Gdk.Event event) { private bool resize_window(Gtk.Widget widget, Gdk.Event event) {
Settings settings = new Settings ("cl.cromer.ubb.sernatur.window"); var settings = new Settings ("cl.cromer.ubb.sernatur.window");
if (event.get_event_type () == Gdk.EventType.CONFIGURE && !settings.get_boolean ("maximized")) { if (event.get_event_type () == Gdk.EventType.CONFIGURE && !settings.get_boolean ("maximized")) {
if (settings.get_int ("width") != event.get_window ().get_width ()) { if (settings.get_int ("width") != event.get_window ().get_width ()) {
settings.set_int ("width", event.get_window ().get_width ()); settings.set_int ("width", event.get_window ().get_width ());
@ -64,27 +67,49 @@ namespace Sernatur {
return false; return false;
} }
[GtkCallback]
private void menu_quit(Gtk.MenuItem menu_item) {
application.quit ();
}
/** /**
* Initialize the main window class * Initialize the main window class
* @param application The application used to make the GLib object * @param application The application used to make the GLib object
*/ */
public MainWindow (Gtk.Application application) { public MainWindow (Gtk.Application application) {
GLib.Object (application: application); GLib.Object (application: application);
Database conn;
Settings settings = new Settings ("cl.cromer.ubb.sernatur.db"); // Load logo
string host = settings.get_string ("host"); var builder = new Gtk.Builder ();
string port = settings.get_string ("port"); try {
string options = settings.get_string ("options"); builder.add_from_resource ("/cl/cromer/ubb/sernatur/splash.ui");
string tty = settings.get_string ("tty"); builder.connect_signals (null);
string database = settings.get_string ("database"); content = builder.get_object ("content_grid") as Gtk.Grid;
string username = settings.get_string ("username");
string password = settings.get_string ("password");
conn = set_db_login (host, port, options, tty, database, username, password); // Add logo to main main box
if (conn.get_status () != ConnectionStatus.OK) { mainbox.pack_start (content, true, false, 0);
stderr.printf ("%s\n", conn.get_error_message ()); }
Gtk.MessageDialog msg = new Gtk.MessageDialog (this, catch (Error e) {
// This error is not fatal, so let's keep going
warning (e.message);
}
var settings = new Settings ("cl.cromer.ubb.sernatur.db");
var host = settings.get_string ("host");
var port = settings.get_string ("port");
var options = settings.get_string ("options");
var tty = settings.get_string ("tty");
var database = settings.get_string ("database");
var username = settings.get_string ("username");
var password = settings.get_string ("password");
var conn = Postgres.set_db_login (host, port, options, tty, database, username, password);
if (conn.get_status () != Postgres.ConnectionStatus.OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
var msg = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL, Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR, Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE, Gtk.ButtonsType.CLOSE,
@ -103,32 +128,40 @@ namespace Sernatur {
msg.set_title (dgettext (null, "Error")); msg.set_title (dgettext (null, "Error"));
msg.show (); msg.show ();
return; return;
#endif
} }
print (dgettext (null, "Postgresql server version:") + " %d\n", conn.get_server_version ());
/*Result res = conn.exec ("CREATE DATABASE bdd;"); /*var tour = Tour.get_all_tours (conn);
if (res.get_status () != ExecStatus.COMMAND_OK) { print (tour[0].ciudad.region.nombre_region + "\n");
stderr.printf ("%s\n", conn.get_error_message ()); var tiene_enfermedad = TieneEnfermedad.get_all_tiene_enfermedades (conn);
application.quit (); print (tiene_enfermedad[0].turista.contacto_emergencia.nombre_emergencia + "\n");
return; var descuento = Descuento.get_all_descuentos (conn);
print (descuento[0].porcentaje.to_string () + "\n");
var realiza = Realiza.get_all_realizas (conn);
print (realiza[0].turista.contacto_emergencia.nombre_emergencia + "\n");
var posee = Posee.get_all_posees (conn);
print (posee[0].guia.ciudad.region.nombre_region + "\n");
var region = Region.get_all_regiones (conn);
print (region[0].nombre_region + "\n");
var participa = Participa.get_all_participas (conn);
print (participa[0].guia.ciudad.region.nombre_region + "\n");
print (participa[0].tour.ciudad.region.nombre_region + "\n");
var requerir_auto = RequerirAuto.get_all_requerir_autos (conn);
print (requerir_auto[0].vehiculo.marca + "\n");
try {
var rut = new Person.Rut ("23.660.457-8");
print (rut.get_rut () + "\n");
if (rut.type () == Person.Rut.Type.RUN) {
print ("person\n");
} }
else {
string password = encrypt_password ("bdd", "bdd"); print ("company\n");
res = conn.exec ("CREATE USER bdd WITH ENCRYPTED PASSWORD '" + password + "';");
if (res.get_status () != ExecStatus.COMMAND_OK) {
stderr.printf ("%s\n", conn.get_error_message ());
application.quit ();
return;
} }
}
res = conn.exec ("GRANT ALL PRIVILEGES ON DATABASE bdd TO bdd;"); catch (Person.InvalidRut e) {
if (res.get_status () != ExecStatus.COMMAND_OK) { print ("Rut is invalid");
stderr.printf ("%s\n", conn.get_error_message ());
application.quit ();
return;
}*/ }*/
GLib.print (dgettext (null, "Server version:") + " %d\n", conn.get_server_version ());
} }
} }
} }

View File

@ -39,7 +39,7 @@ namespace Sernatur {
*/ */
public override void activate () { public override void activate () {
window = new MainWindow (this); window = new MainWindow (this);
GLib.Settings settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window"); var settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
window.set_default_size (settings.get_int("width"), settings.get_int("height")); window.set_default_size (settings.get_int("width"), settings.get_int("height"));
@ -51,7 +51,7 @@ namespace Sernatur {
window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0); window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
} }
catch (Error e) { catch (Error e) {
stderr.printf (dgettext (null, "Could not load application icon: %s\n"), e.message); warning (e.message);
} }
window.present (); window.present ();
} }