finish queries window

This commit is contained in:
Chris Cromer 2019-01-15 13:12:38 -03:00
parent 0f6ddb8075
commit 24932b6d94
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
37 changed files with 1018 additions and 101 deletions

View File

@ -78,12 +78,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="tour_name_q2">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tour Name</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="total_value">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Total Value</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
@ -106,12 +118,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="tour_name_q3">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tour Name</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="coordinator_total">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Coordinator Total</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
@ -134,12 +158,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="tour_name_q">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tour Name</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tourist_total">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tourist Total</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
@ -162,6 +198,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="percentage">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Percentage</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
</object>

View File

@ -21,8 +21,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<property name="type">popup</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">640</property>
<property name="default_height">480</property>
<property name="default_width">800</property>
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="icon_name">sernatur</property>
<property name="type_hint">dialog</property>

View File

@ -32,6 +32,9 @@ namespace LibSernatur {
CONNECT
}
/**
* The errors that can be thrown while doing queries in the database
*/
public errordomain DBError {
/**
* Invalid value

View File

@ -57,7 +57,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Arrienda
*/
public static List<Arrienda> get_all_arriendas(Database conn) {
public static List<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,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Asociado
*/
public static List<Asociado> get_all_asociados(Database conn) {
public static List<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,

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Categoria
*/
public static List<Categoria> get_all_categorias(Database conn) {
public static List<Categoria> get_all_categorias (Database conn) {
var res = conn.exec ("
SELECT id_categoria, descripcion_categoria FROM categoria
");

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Ciudad
*/
public static List<Ciudad> get_all_ciudades(Database conn) {
public static List<Ciudad> get_all_ciudades (Database conn) {
var res = conn.exec ("
SELECT C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of ContactoEmergencia
*/
public static List<ContactoEmergencia> get_all_contactos(Database conn) {
public static List<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

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Descuento
*/
public static List<Descuento> get_all_descuentos(Database conn) {
public static List<Descuento> get_all_descuentos (Database conn) {
var res = conn.exec ("
SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento
");

View File

@ -57,7 +57,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Empresa
*/
public static List<Empresa> get_all_empresas(Database conn) {
public static List<Empresa> get_all_empresas (Database conn) {
var res = conn.exec ("
SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa
");

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Enfermedad
*/
public static List<Enfermedad> get_all_enfermedades(Database conn) {
public static List<Enfermedad> get_all_enfermedades (Database conn) {
var res = conn.exec ("
SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad
");

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Especialidad
*/
public static List<Especialidad> get_all_especialidades(Database conn) {
public static List<Especialidad> get_all_especialidades (Database conn) {
var res = conn.exec ("
SELECT id_especialidad, descripcion_especialidad FROM especialidad
");

View File

@ -63,7 +63,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Guia
*/
public static List<Guia> get_all_guias(Database conn) {
public static List<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,

View File

@ -63,7 +63,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Lugar
*/
public static List<Lugar> get_all_lugares(Database conn) {
public static List<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,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Participa
*/
public static List<Participa> get_all_participas(Database conn) {
public static List<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,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Posee
*/
public static List<Posee> get_all_posees(Database conn) {
public static List<Posee> get_all_posees (Database conn) {
var res = conn.exec ("
SELECT P.nivel_especialidad,
G.rut_guia, G.nombre_guia, G.calle, G.numero,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Realiza
*/
public static List<Realiza> get_all_realizas(Database conn) {
public static List<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,

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Region
*/
public static List<Region> get_all_regiones(Database conn) {
public static List<Region> get_all_regiones (Database conn) {
var res = conn.exec ("
SELECT id_region, nombre_region FROM region
");

View File

@ -18,7 +18,7 @@ namespace LibSernatur {
using Wrapper;
/**
* The Region class based on the database table
* The RegionesSinDescuento class based on the database table
*/
public class RegionesSinDescuento : GLib.Object {
/**
@ -44,9 +44,9 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of RegionesSinDescuento
*/
public static List<RegionesSinDescuento> get_regions(Database conn) {
public static List<RegionesSinDescuento> get_all_regions_without_discount (Database conn) {
var res = conn.exec ("
SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO))
SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of RequerirAuto
*/
public static List<RequerirAuto> get_all_requerir_autos(Database conn) {
public static List<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,

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of TieneEnfermedad
*/
public static List<TieneEnfermedad> get_all_tiene_enfermedades(Database conn) {
public static List<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,

View File

@ -0,0 +1,75 @@
/*
* Copyright 2018-2019 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.
*/
namespace LibSernatur {
namespace DB {
using Postgres;
using Wrapper;
/**
* The TotalArriendos class based on the database table
*/
public class TotalArriendos : GLib.Object {
/**
* The total of rented vehicles
*/
public uint total_arriendo { get; set; default = 0; }
/**
* Initialize the TotalArriendos class
* @param total_arriendo The total of rented vehicles
*/
public TotalArriendos (uint total_arriendo = 0) {
this.total_arriendo = total_arriendo;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of TotalArriendos
*/
public static List<TotalArriendos> get_all_rent_totals (Database conn) {
var res = conn.exec ("
SELECT TotalArriendo FROM TOTAL_ARRIENDOS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<TotalArriendos> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalArriendos> list = new List<TotalArriendos> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var total = new TotalArriendos (wra.get_int_n (i, "TotalArriendo"));
list.append (total);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2018-2019 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.
*/
namespace LibSernatur {
namespace DB {
using Postgres;
using Wrapper;
/**
* The TotalCoordinadores class based on the database table
*/
public class TotalCoordinadores : GLib.Object {
/**
* The id of the region
*/
public uint id_tour { get; set; default = 0; }
/**
* The name of the region
*/
public string nombre_tour { get; set; default = ""; }
/**
* The total number of coordinators
*/
public uint total_coordinadores { get; set; default = 0; }
/**
* Initialize the TotalCoordinadores class
* @param id_tour The tour id
* @param nombre_tour The tour name
* @param total_coordinadores The total number of coordinators
*/
public TotalCoordinadores (uint id_tour = 0, string nombre_tour = "", uint total_coordinadores = 0) {
this.id_tour = id_tour;
this.nombre_tour = nombre_tour;
this.total_coordinadores = total_coordinadores;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of TotalCoordinadores
*/
public static List<TotalCoordinadores> get_all_coordinator_totals (Database conn) {
var res = conn.exec ("
SELECT idT, nombreT, TotalCoordinadores FROM TOTAL_COORDINADORES
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<TotalCoordinadores> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalCoordinadores> list = new List<TotalCoordinadores> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var total = new TotalCoordinadores (wra.get_int_n (i, "idT"),
wra.get_string_n (i, "nombreT"),
wra.get_int_n (i, "TotalCoordinadores")
);
list.append (total);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2018-2019 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.
*/
namespace LibSernatur {
namespace DB {
using Postgres;
using Wrapper;
/**
* The TotalTuristas class based on the database table
*/
public class TotalTuristas : GLib.Object {
/**
* The id of the tour
*/
public uint id_tour { get; set; default = 0; }
/**
* The name of the tour
*/
public string nombre_tour { get; set; default = ""; }
/**
* The total number of tourists
*/
public uint total_turistas { get; set; default = 0; }
/**
* Initialize the TotalTuristas class
* @param id_tour The tour id
* @param nombre_tour The tour name
* @param total_turistas The number of tourists
*/
public TotalTuristas (uint id_tour = 0, string nombre_tour = "", uint total_turistas = 0) {
this.id_tour = id_tour;
this.nombre_tour = nombre_tour;
this.total_turistas = total_turistas;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of TotalTuristas
*/
public static List<TotalTuristas> get_all_tourist_totals (Database conn) {
var res = conn.exec ("
SELECT idT, nombreT, TotalTuristas FROM TOTAL_TURISTAS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<TotalTuristas> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalTuristas> list = new List<TotalTuristas> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var total = new TotalTuristas (wra.get_int_n (i, "idT"),
wra.get_string_n (i, "nombreT"),
wra.get_int_n (i, "TotalTuristas")
);
list.append (total);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright 2018-2019 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.
*/
namespace LibSernatur {
namespace DB {
using Postgres;
using Wrapper;
/**
* The TotalVehiculos class based on the database table
*/
public class TotalVehiculos : GLib.Object {
/**
* The total of vehicles
*/
public uint total_veh { get; set; default = 0; }
/**
* Initialize the TotalVehiculos class
* @param total_veh The total of vehicles
*/
public TotalVehiculos (uint total_veh = 0) {
this.total_veh = total_veh;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of TotalVehiculos
*/
public static List<TotalVehiculos> get_all_vehicle_totals (Database conn) {
var res = conn.exec ("
SELECT TotalVeh FROM TOTAL_VEHICULOS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<TotalVehiculos> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalVehiculos> list = new List<TotalVehiculos> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var total = new TotalVehiculos (wra.get_int_n (i, "TotalVeh"));
list.append (total);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
}
}

View File

@ -69,7 +69,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Tour
*/
public static List<Tour> get_all_tours(Database conn) {
public static List<Tour> get_all_tours (Database conn) {
var res = conn.exec (Query.get_query (Query.Type.SELECT_ALL_TOURS, null));
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
@ -112,8 +112,8 @@ namespace LibSernatur {
/**
* Update a tour in the database
* @param conn The database connection
* @param tour The tour to update
* @return Returns true if updated
* @throws DBError Thrown if the data in the object is invalid
*/
public static void update_tour (Database conn, Tour tour) throws DBError {

View File

@ -52,13 +52,12 @@ namespace LibSernatur {
this.contacto_emergencia = contacto_emergencia;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of Turista
*/
public static List<Turista> get_all_turistas(Database conn) {
public static List<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

90
lib/db/valores_tours.vala Normal file
View File

@ -0,0 +1,90 @@
/*
* Copyright 2018-2019 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.
*/
namespace LibSernatur {
namespace DB {
using Postgres;
using Wrapper;
/**
* The ValoresTours class based on the database table
*/
public class ValoresTours : GLib.Object {
/**
* The id of the tour
*/
public uint id_tour { get; set; default = 0; }
/**
* The name of the tour
*/
public string nombre_tour { get; set; default = ""; }
/**
* The total sales value
*/
public uint total_ventas { get; set; default = 0; }
/**
* Initialize the ValoresTours class
* @param id_tour The tour id
* @param nombre_tour The tour name
* @param total_ventas The sales total
*/
public ValoresTours (uint id_tour = 0, string nombre_tour = "", uint total_ventas = 0) {
this.id_tour = id_tour;
this.nombre_tour = nombre_tour;
this.total_ventas = total_ventas;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of ValoresTours
*/
public static List<ValoresTours> get_all_tour_sales (Database conn) {
var res = conn.exec ("
SELECT idT, nombreT, TotalVentas FROM VALORES_TOURS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<ValoresTours> ();
#endif
}
var wra = new ResultWrapper (res);
List<ValoresTours> list = new List<ValoresTours> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var tour_value = new ValoresTours (wra.get_int_n (i, "idT"),
wra.get_string_n (i, "nombreT"),
wra.get_int_n (i, "TotalVentas")
);
list.append (tour_value);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
}
}

View File

@ -57,7 +57,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Vehiculo
*/
public static List<Vehiculo> get_all_vehiculos(Database conn) {
public static List<Vehiculo> get_all_vehiculos (Database conn) {
var res = conn.exec ("
SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo
");

281
lib/db/views.vala Normal file
View File

@ -0,0 +1,281 @@
/*
* Copyright 2018-2019 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.
*/
namespace LibSernatur {
namespace DB {
/**
* The views namespace for the 5 views
*/
namespace Views {
using Postgres;
using Wrapper;
/**
* The Q1 class based on the database table
*/
public class Q1 : GLib.Object {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of RegionesSinDescuento
*/
public static List<RegionesSinDescuento> get_regions_without_discount (Database conn) {
var res = conn.exec ("
SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO))
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<RegionesSinDescuento> ();
#endif
}
var wra = new ResultWrapper (res);
List<RegionesSinDescuento> list = new List<RegionesSinDescuento> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var region_sin_descuento = new RegionesSinDescuento (wra.get_string_n (i, "nombreRegion"),
wra.get_int_n (i, "cantidad")
);
list.append (region_sin_descuento);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
/**
* The Q2 class based on the database table
*/
public class Q2 : GLib.Object {
/**
* The name of the tour
*/
public string nombre_tour { get; set; default = ""; }
/**
* The value received
*/
public uint valor_recibido { get; set; default = 0; }
/**
* Initialize the Q2 class
* @param nombre_tour The name of the tour
* @param valor_recibido The money value received
*/
public Q2 (string nombre_tour = "", uint valor_recibido = 0) {
this.nombre_tour = nombre_tour;
this.valor_recibido = valor_recibido;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of Q2
*/
public static List<Q2> get_value_received (Database conn) {
var res = conn.exec ("
SELECT V.nombreT, (V.TotalVentas - COALESCE(MAX(T.TotalDescuentos), 0)) AS ValorTotalRecibido
FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V.nombreT, V.TotalVentas)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<Q2> ();
#endif
}
var wra = new ResultWrapper (res);
List<Q2> list = new List<Q2> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var values = new Q2 (wra.get_string_n (i, "nombreT"),
wra.get_int_n (i, "ValorTotalRecibido")
);
list.append (values);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
/**
* The Q3 class based on the database table
*/
public class Q3 : GLib.Object {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of TotalCoordinadores
*/
public static List<TotalCoordinadores> get_total_coordinators (Database conn) {
var res = conn.exec ("
SELECT nombreT, TotalCoordinadores
FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinadores) FROM TOTAL_COORDINADORES))
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<TotalCoordinadores> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalCoordinadores> list = new List<TotalCoordinadores> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var total = new TotalCoordinadores (0,
wra.get_string_n (i, "nombreT"),
wra.get_int_n (i, "TotalCoordinadores")
);
list.append (total);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
/**
* The Q4 class based on the database table
*/
public class Q4 : GLib.Object {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of TotalTuristas
*/
public static List<TotalTuristas> get_total_tourists (Database conn) {
var res = conn.exec ("
SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT MAX(TotalTuristas) FROM TOTAL_TURISTAS))
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<TotalTuristas> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalTuristas> list = new List<TotalTuristas> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var total = new TotalTuristas (0,
wra.get_string_n (i, "nombreT"),
wra.get_int_n (i, "TotalTuristas")
);
list.append (total);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
/**
* The Q5 class based on the database table
*/
public class Q5 : GLib.Object {
/**
* The percentage of cars that were rented and used
*/
public float porcentaje { get; set; default = 0; }
/**
* Initialize the Q5 class
* @param porcentaje The percentage of cars that were rented and used
*/
public Q5 (float porcentaje = 0) {
this.porcentaje = porcentaje;
}
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @return Returns a list of Q5
*/
public static List<Q5> get_percentage (Database conn) {
var res = conn.exec ("
SELECT
(cast(T1.totalarriendo AS DECIMAL(3,2)) / cast(T2.totalveh AS DECIMAL(3,2))) AS porcentaje
FROM total_arriendos AS T1, total_vehiculos AS T2
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return new List<Q5> ();
#endif
}
var wra = new ResultWrapper (res);
List<Q5> list = new List<Q5> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var percentage = new Q5 (wra.get_float_n (i, "porcentaje"));
list.append (percentage);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
}
}
}
}

View File

@ -25,9 +25,15 @@ lib_sources = files(
'db/regiones_sin_descuento.vala',
'db/requerir_auto.vala',
'db/tiene_enfermedad.vala',
'db/total_arriendos.vala',
'db/total_coordinadores.vala',
'db/total_turistas.vala',
'db/total_vehiculos.vala',
'db/tour.vala',
'db/turista.vala',
'db/vehiculo.vala')
'db/valores_tours.vala',
'db/vehiculo.vala',
'db/views.vala')
vala_args = ['--vapidir=' + join_paths(meson.source_root(), 'vapi')]

View File

@ -14,7 +14,7 @@
namespace LibSernatur {
/**
* The person name space
* The misc name space
*/
namespace Misc {
@ -36,8 +36,39 @@ namespace LibSernatur {