restructuring and queries

This commit is contained in:
2019-01-14 11:38:38 -03:00
parent d0508ab4ca
commit 0f6ddb8075
10 changed files with 682 additions and 266 deletions

View File

@@ -39,10 +39,30 @@ namespace Sernatur {
[GtkChild]
private Gtk.MenuItem tours;
/**
* The q1 menu item
* The Q1 menu item
*/
[GtkChild]
private Gtk.MenuItem q1;
/**
* The Q2 menu item
*/
[GtkChild]
private Gtk.MenuItem q2;
/**
* The Q3 menu item
*/
[GtkChild]
private Gtk.MenuItem q3;
/**
* The Q4 menu item
*/
[GtkChild]
private Gtk.MenuItem q4;
/**
* The Q5 menu item
*/
[GtkChild]
private Gtk.MenuItem q5;
/**
* The quit menu item
*/
@@ -111,7 +131,31 @@ namespace Sernatur {
tour_list.show_all ();
}
else if (menu_item == q1) {
var query_window = new QueryWindow (application, conn);
var query_window = new QueryWindow (application, conn, Query.Q1);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q2) {
var query_window = new QueryWindow (application, conn, Query.Q2);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q3) {
var query_window = new QueryWindow (application, conn, Query.Q3);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q4) {
var query_window = new QueryWindow (application, conn, Query.Q4);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q5) {
var query_window = new QueryWindow (application, conn, Query.Q5);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
@@ -169,7 +213,7 @@ namespace Sernatur {
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
e.message);
dgettext(null, "Error: Could not connect to the database!"));
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.CLOSE:

View File

@@ -17,13 +17,25 @@ namespace Sernatur {
/**
* The Q1 statement
*/
public const string Q1_STATEMENT = "Genere la vista REGIONES SINDESCUENTO(nombreRegion, cantidad) que contiene el nombre
de cada región y la cantidad de personas a las que no se les ha aplicado descuento y que han
visitado algún lugar de la región en algún tour, durante el mes de noviembre del presente año.
Luego utilizando la vista, muestre las regiones que han recibido la mayor cantidad de turistas
sin descuento.";
public const string Q1_STATEMENT = "Genere la vista REGIONES_SINDESCUENTO(nombreRegion, cantidad) que contiene el nombre de cada región y la cantidad de personas a las que no se les ha aplicado descuento y que han visitado algún lugar de la región en algún tour, durante el mes de noviembre del presente año. Luego utilizando la vista, muestre las regiones que han recibido la mayor cantidad de turistas sin descuento.";
/**
* The Q1 sql
* The Q2 statement
*/
public const string Q2_STATEMENT = "Genere la vista VALORES_TOURS(idT, nombreT, TotalVentas) que contiene el identificador y nombre de cada tour, además del total de ventas de cada tour. Par ello debe considerar todas las ventas realizadas del tour. Genere la vista TOUR_DESCUENTOS(idT, nombreT, TotalDescuentos) que contiene el identificador y nombre de cada tour, además del total de descuentos aplicados en todas las ventas de cada tour. Luego utilizando las vistas, muestre el nombre de los tours y valor total recibido, considerando el dinero recibido menos los descuentos.";
/**
* The Q3 statement
*/
public const string Q3_STATEMENT = "Genere la vista TOTAL_COORDINADORES(idT, nombreT, TotalCoordinadores) que almacena el identificador y nombre de los tour que poseen guı́as coordinadores con más de tres especialidades y que han participado en tours que visitan lugares con nivel de esfuerzo medio. Luego, utilizando la vista, muestre los tours que poseen la mayor cantidad de coordinadores con las caracterı́sticas mencionadas.";
/**
* The Q4 statement
*/
public const string Q4_STATEMENT = "Genere la vista TOTAL_TURISTAS(idT, nombreT, TotalTuristas) que contiene el identificador y nombre de los tours, y la cantidad de turistas que no tienen enfermedades cardı́acas ni respiratorias y que han visitado lugares cuyo nivel de exigencia es experto durante el mes de octubre del presente año. Luego, utilizando la vista, muestre los tours que poseen la mayor cantidad de turistas que han visitado lugares con exigencia experto y que cumplan el requisito de no tener las enfermedades mencionadas.";
/**
* The Q5 statement
*/
public const string Q5_STATEMENT = "Genere la vista TOTAL_ARRIENDOS(TotalArriendo) que almacena el total de arriendos de vehı́culos (no precio) realizados por SERNATUR durante los meses de Enero y Febrero del presente año y la vista TOTAL_VEHICULOS(TotalVeh) que contiene el total de vehı́culos que posee SERNATUR. Luego, utilizando las vistas muestre el porcentaje de arriendo de vehı́culos realizados por SERNATUR (número de vehı́culos arrendados/número total de vehı́culos).";
/**
* The Q1 SQL
*/
public const string Q1_SQL = "CREATE VIEW REGIONES_SINDESCUENTO(nombreRegion, cantidad)
AS (
@@ -40,5 +52,21 @@ AS (
GROUP BY (R.nombre_region)
);
SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO));";
/**
* The Q2 SQL
*/
public const string Q2_SQL = "";
/**
* The Q3 SQL
*/
public const string Q3_SQL = "";
/**
* The Q4 SQL
*/
public const string Q4_SQL = "";
/**
* The Q5 SQL
*/
public const string Q5_SQL = "";
}
}

View File

@@ -27,15 +27,29 @@ namespace Sernatur {
*/
private Connection conn;
/**
* The columns of the tree view
* The queries that can be called
*/
private enum Column {
public enum Query {
Q1,
Q2,
Q3,
Q4,
Q5
}
/**
* The query to use in the object
*/
private Query query;
/**
* The columns of the Q1 tree view
*/
private enum Q1Column {
/**
* The tour name
* The region name
*/
REGION_NAME,
/**
* The individual cost
* The quantity
*/
QUANTITY,
/**
@@ -43,6 +57,70 @@ namespace Sernatur {
*/
N_COLUMNS
}
/**
* The columns of the Q2 tree view
*/
private enum Q2Column {
/**
* The tour name
*/
TOUR_NAME,
/**
* The total value
*/
TOTAL_VALUE,
/**
* The number of colums in this enum
*/
N_COLUMNS
}
/**
* The columns of the Q3 tree view
*/
private enum Q3Column {
/**
* The tour name
*/
TOUR_NAME,
/**
* The total of coordinators
*/
COORDINATOR_TOTAL,
/**
* The number of colums in this enum
*/
N_COLUMNS
}
/**
* The columns of the Q4 tree view
*/
private enum Q4Column {
/**
* The tour name
*/
TOUR_NAME,
/**
* The total of turists
*/
TOURIST_TOTAL,
/**
* The number of colums in this enum
*/
N_COLUMNS
}
/**
* The columns of the Q5 tree view
*/
private enum Q5Column {
/**
* The percentage
*/
PERCENTAGE,
/**
* The number of colums in this enum
*/
N_COLUMNS
}
/**
* The list that stores the contents in the tree view
*/
@@ -52,14 +130,29 @@ namespace Sernatur {
*/
[GtkChild]
private Gtk.ScrolledWindow scroll_window;
/**
* The statement label
*/
[GtkChild]
private Gtk.Label statement;
/**
* The sql label
*/
[GtkChild]
private Gtk.Label sql;
/**
* The run button
*/
[GtkChild]
private Gtk.Button run_query;
/**
* The close button
*/
[GtkChild]
private Gtk.Button close_query;
/**
* The query tree
*/
private Gtk.TreeView query_tree;
/**
@@ -70,15 +163,17 @@ namespace Sernatur {
public void on_clicked_button (Gtk.Button button) {
if (button == run_query) {
list_store.clear ();
var region_list = RegionesSinDescuento.get_regions (conn.db);
if (query == Query.Q1) {
var region_list = RegionesSinDescuento.get_regions (conn.db);
region_list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Column.REGION_NAME, entry.nombre_region,
Column.QUANTITY, entry.cantidad);
});
region_list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Q1Column.REGION_NAME, entry.nombre_region,
Q1Column.QUANTITY, entry.cantidad);
});
}
}
else if (button == close_query) {
this.close ();
@@ -89,17 +184,33 @@ namespace Sernatur {
* Initialize the tour list class
* @param application The application used to make the GLib object
* @param conn The database connection to use
* @param query The query to show
*/
public QueryWindow (Gtk.Application application, Connection conn) {
public QueryWindow (Gtk.Application application, Connection conn, Query query) {
GLib.Object (application: application);
this.conn = conn;
this.query = query;
// Load scroll window's content
var builder = new Gtk.Builder ();
try {
builder.add_from_resource ("/cl/cromer/ubb/sernatur/query.1.ui");
builder.add_from_resource ("/cl/cromer/ubb/sernatur/query.tree.ui");
builder.connect_signals (null);
query_tree = builder.get_object ("query_tree") as Gtk.TreeView;
if (query == Query.Q1) {
query_tree = builder.get_object ("query_tree_q1") as Gtk.TreeView;
}
else if (query == Query.Q2) {
query_tree = builder.get_object ("query_tree_q2") as Gtk.TreeView;
}
else if (query == Query.Q3) {
query_tree = builder.get_object ("query_tree_q3") as Gtk.TreeView;
}
else if (query == Query.Q4) {
query_tree = builder.get_object ("query_tree_q4") as Gtk.TreeView;
}
else if (query == Query.Q5) {
query_tree = builder.get_object ("query_tree_q5") as Gtk.TreeView;
}
query_tree.set_visible (true);
// Add logo to scroll window
@@ -117,17 +228,70 @@ namespace Sernatur {
* Initialize what is needed for this window
*/
public void initialize () {
this.set_title ("Test");
if (query == Query.Q1) {
this.set_title (dgettext (null, "(Q1) Regions with discounts"));
list_store = new Gtk.ListStore (Column.N_COLUMNS,
typeof (string),
typeof (uint));
list_store = new Gtk.ListStore (Q1Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
query_tree.set_model (list_store);
statement.set_text (Q1_STATEMENT);
statement.set_text (Q1_STATEMENT);
sql.set_text (Q1_SQL);
sql.set_text (Q1_SQL);
}
else if (query == Query.Q2) {
this.set_title (dgettext (null, "(Q2) Tour values"));
list_store = new Gtk.ListStore (Q2Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q2_STATEMENT);
sql.set_text (Q2_SQL);
}
else if (query == Query.Q3) {
this.set_title (dgettext (null, "(Q3) Coordinator total"));
list_store = new Gtk.ListStore (Q3Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q3_STATEMENT);
sql.set_text (Q3_SQL);
}
else if (query == Query.Q4) {
this.set_title (dgettext (null, "(Q4) Tourist total"));
list_store = new Gtk.ListStore (Q4Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q4_STATEMENT);
sql.set_text (Q4_SQL);
}
else if (query == Query.Q5) {
this.set_title (dgettext (null, "(Q5) Vehicle total"));
list_store = new Gtk.ListStore (Q5Column.N_COLUMNS,
typeof (float));
query_tree.set_model (list_store);
statement.set_text (Q5_STATEMENT);
sql.set_text (Q5_SQL);
}
}
}
}