initial commit
This commit is contained in:
45
src/colegio.vala
Normal file
45
src/colegio.vala
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
using Constants;
|
||||
|
||||
public class Application : global::Gtk.Application {
|
||||
public Application () {
|
||||
application_id = "cl.cromer.ubb.colegio";
|
||||
}
|
||||
|
||||
public override void activate () {
|
||||
var window = new MainWindow (this);
|
||||
|
||||
window.set_default_size (640, 480);
|
||||
window.maximize ();
|
||||
|
||||
window.icon = new Gtk.Image.from_resource ("/cl/cromer/ubb/colegio/pixdata/icon-colegio.png").get_pixbuf ();
|
||||
window.show_all ();
|
||||
window.initialize ();
|
||||
}
|
||||
|
||||
public override void startup () {
|
||||
base.startup ();
|
||||
}
|
||||
}
|
||||
|
||||
public static int main (string[] args) {
|
||||
Intl.setlocale (LocaleCategory.ALL, ""); // Even though this isn't a multilanguage program, this is needed so that spanish works
|
||||
print ("Versión: " + VERSION + "\n");
|
||||
var application = new Application ();
|
||||
return application.run (args);
|
||||
}
|
||||
}
|
26
src/config.vala.in
Normal file
26
src/config.vala.in
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
namespace Constants {
|
||||
public const string VERSION = "@VERSION@";
|
||||
public const string HOST = "localhost";
|
||||
public const string PORT = "5432";
|
||||
public const string OPTIONS = "";
|
||||
public const string TTY = "";
|
||||
public const string DATABASE = "bdd";
|
||||
public const string USERNAME = "bdd";
|
||||
public const string PASSWORD = "bdd";
|
||||
}
|
||||
}
|
54
src/db.vala
Normal file
54
src/db.vala
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
namespace DB {
|
||||
using Postgres;
|
||||
|
||||
public errordomain PostgresError {
|
||||
CONNECT,
|
||||
ESCAPE
|
||||
}
|
||||
|
||||
public errordomain DBError {
|
||||
INVALID_VALUE,
|
||||
FOREIGN_KEY_CONSTAINT
|
||||
}
|
||||
|
||||
public class Connection : Object {
|
||||
public Database db;
|
||||
|
||||
public Connection (string host, string port, string options, string tty, string database, string username, string password) throws PostgresError {
|
||||
db = set_db_login (host, port, options, tty, database, username, password);
|
||||
if (db.get_status () != Postgres.ConnectionStatus.OK) {
|
||||
throw new PostgresError.CONNECT (db.get_error_message ());
|
||||
}
|
||||
GLib.print ("Versión de servidor de Postgresql:" + " %d\n", db.get_server_version ());
|
||||
}
|
||||
|
||||
public string escape (string str) throws PostgresError {
|
||||
string* to = malloc ((sizeof (string) * str.length * 2) + 1); // to has to be double the size of str + 1
|
||||
int error_code;
|
||||
db.escape_string_conn (to, str, str.length, out error_code);
|
||||
if (error_code != 0) {
|
||||
throw new PostgresError.ESCAPE (db.get_error_message ());
|
||||
}
|
||||
|
||||
string result = to;
|
||||
free (to);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
src/db/q1.vala
Normal file
19
src/db/q1.vala
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Colegio {
|
||||
namespace DB {
|
||||
public class Q1 : Object {
|
||||
public string alumno { get; set; default = ""; }
|
||||
public string apoderado { get; set; default = ""; }
|
||||
public string curso { get; set; default = ""; }
|
||||
public string jefe { get; set; default = ""; }
|
||||
public string asistente { get; set; default = ""; }
|
||||
|
||||
public Q1 (string alumno = "", string apoderado = "", string curso = "", string jefe = "", string asistente = "") {
|
||||
this.alumno = alumno;
|
||||
this.apoderado = apoderado;
|
||||
this.curso = curso;
|
||||
this.jefe = jefe;
|
||||
this.asistente = asistente;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
src/db/q2.vala
Normal file
11
src/db/q2.vala
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Colegio {
|
||||
namespace DB {
|
||||
public class Q2 : Object {
|
||||
public string profesor { get; set; default = ""; }
|
||||
|
||||
public Q2 (string profesor = "") {
|
||||
this.profesor = profesor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
72
src/dbwrapper.vala
Normal file
72
src/dbwrapper.vala
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
namespace DB {
|
||||
namespace Wrapper {
|
||||
using Postgres;
|
||||
|
||||
public errordomain Field {
|
||||
NOTFOUND
|
||||
}
|
||||
|
||||
public class ResultWrapper : 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 ("El campo %s no estaba en los resultados de la consulta!", name);
|
||||
}
|
||||
return field_num;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
137
src/main_window.vala
Normal file
137
src/main_window.vala
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
using Constants;
|
||||
using DB;
|
||||
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/colegio/main.window.ui")]
|
||||
public class MainWindow : Gtk.ApplicationWindow {
|
||||
private Connection conn;
|
||||
private Gtk.Grid content;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Box mainbox;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem q1;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem q2;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem q3;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem q4;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem q5;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem quit;
|
||||
|
||||
[GtkCallback]
|
||||
private void on_destroy(Gtk.Widget widget) {
|
||||
application.quit ();
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_activate_menu(Gtk.MenuItem menu_item) {
|
||||
if (menu_item == q1) {
|
||||
var query_window = new QueryWindow (application, conn, QueryWindow.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, QueryWindow.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, QueryWindow.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, QueryWindow.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, QueryWindow.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 ();
|
||||
}
|
||||
else if (menu_item == quit) {
|
||||
application.quit ();
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindow (Gtk.Application application) {
|
||||
Object (application: application);
|
||||
|
||||
// Load logo
|
||||
var builder = new Gtk.Builder ();
|
||||
try {
|
||||
builder.add_from_resource ("/cl/cromer/ubb/colegio/main.splash.ui");
|
||||
builder.connect_signals (null);
|
||||
content = builder.get_object ("content_grid") as Gtk.Grid;
|
||||
|
||||
// Add logo to main box
|
||||
mainbox.pack_start (content, true, false, 0);
|
||||
}
|
||||
catch (Error e) {
|
||||
// This error is not fatal, so let's keep going
|
||||
warning (e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize () {
|
||||
try {
|
||||
conn = new Connection (HOST, PORT, OPTIONS, TTY, DATABASE, USERNAME, PASSWORD);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
"Error: No se puede conectar al base de datos!");
|
||||
msg.response.connect ((response_id) => {
|
||||
switch (response_id) {
|
||||
case Gtk.ResponseType.CLOSE:
|
||||
application.quit ();
|
||||
break;
|
||||
case Gtk.ResponseType.DELETE_EVENT:
|
||||
application.quit ();
|
||||
break;
|
||||
}
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.set_title ("Error");
|
||||
msg.run ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
src/meson.build
Normal file
42
src/meson.build
Normal file
@@ -0,0 +1,42 @@
|
||||
glib_dep = dependency('glib-2.0')
|
||||
gobject_dep = dependency('gobject-2.0')
|
||||
gtk_dep = dependency('gtk+-3.0', version: '>=3.0.0')
|
||||
# gmodule-export-2.0 is needed to connect the handlers
|
||||
gmodule_dep = dependency('gmodule-2.0', version: '>=2.0')
|
||||
pq_dep = dependency('libpq', version: '>=9.0')
|
||||
|
||||
config_data = configuration_data()
|
||||
config_data.set('VERSION', meson.project_version())
|
||||
config_data.set('GETTEXT_PACKAGE', meson.project_name())
|
||||
|
||||
config_data_file = configure_file(input: 'config.vala.in',
|
||||
output: 'config.vala',
|
||||
configuration: config_data)
|
||||
|
||||
vala_sources = files(
|
||||
'colegio.vala',
|
||||
'db.vala',
|
||||
'dbwrapper.vala',
|
||||
'misc.vala',
|
||||
'main_window.vala',
|
||||
'queries.vala',
|
||||
'query_window.vala',
|
||||
'db/q1.vala',
|
||||
'db/q2.vala')
|
||||
|
||||
sources = vala_sources
|
||||
sources += main_gresource
|
||||
sources += query_gresource
|
||||
sources += config_data_file
|
||||
|
||||
vala_args = ['--vapidir=' + join_paths(meson.source_root(), 'vapi')]
|
||||
|
||||
inc = include_directories('./')
|
||||
|
||||
exe = executable(meson.project_name(),
|
||||
sources,
|
||||
vala_args: vala_args,
|
||||
include_directories : inc,
|
||||
gui_app: true,
|
||||
dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep],
|
||||
install: true)
|
167
src/misc.vala
Normal file
167
src/misc.vala
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
namespace Misc {
|
||||
|
||||
public errordomain InvalidRut {
|
||||
INVALID,
|
||||
TOOLARGE,
|
||||
INVALIDVERIFIER
|
||||
}
|
||||
|
||||
public class Percentage : Object {
|
||||
public static string format_float (float value) {
|
||||
return (value * 100).to_string () + "%";
|
||||
}
|
||||
|
||||
public static string format_double (double value) {
|
||||
// Remove the double precision by converting to float
|
||||
return ((float) (value * (double) 100)).to_string () + "%";
|
||||
}
|
||||
}
|
||||
|
||||
public class Rut : 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 ("El RUT %s contiene un carácter inválido!", rut);
|
||||
}
|
||||
}
|
||||
catch (RegexError 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 ("El RUT %s es demasiado largo!", 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 ("El verificador %C es inválido!", this.verifier);
|
||||
}
|
||||
pretty();
|
||||
}
|
||||
catch (RegexError 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) {
|
||||
if (i != rut_length - 1) {
|
||||
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 {
|
||||
// Add the '0' to convert from int to unichar
|
||||
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 > 50000000 && rut < 100000000) {
|
||||
// Company
|
||||
return Type.RUT;
|
||||
}
|
||||
else {
|
||||
// Person
|
||||
return Type.RUN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
146
src/queries.vala
Normal file
146
src/queries.vala
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 Colegio {
|
||||
namespace Constants {
|
||||
/**
|
||||
* The Q1 statement
|
||||
*/
|
||||
public const string Q1_STATEMENT = "Mostrar el nombre de los alumnos, el nombre del apoderado, el nombre del curso cursando a la fecha, nombre del profesor jefe y profesor asistente, para aquellos alumnos que provienen de la Región del Bı́obio o Ñuble.";
|
||||
/**
|
||||
* The Q2 statement
|
||||
*/
|
||||
public const string Q2_STATEMENT = "Mostrar el nombre de los profesores que son profesores jefes de algún curso y no tienen asignada alguna actividad extraprogramática para los niveles primero o segundo.";
|
||||
/**
|
||||
* The Q3 statement
|
||||
*/
|
||||
public const string Q3_STATEMENT = "Mostrar el nombre de las actividades extraprogramáticas y la cantidad de alumnos inscritos, considerando alumnos que hayan nacido entre los años 2006 y 2008. Considere solo aquellas actividades extraprogramáticas que tengan más de 5 alumnos inscritos.";
|
||||
/**
|
||||
* The Q4 statement
|
||||
*/
|
||||
public const string Q4_STATEMENT = "Mostrar los cursos del año 2019 que tengan la menor cantidad de alumnos matriculados. TIP: Genere vistas.";
|
||||
/**
|
||||
* The Q5 statement
|
||||
*/
|
||||
public const string Q5_STATEMENT = "Muestre el nombre de las asignaturas y el promedio de notas para cada asignatura de los alumnos del curso 6A-2018 cuyos alumnos no participan en la actividad extraprogramática “Rugby”.";
|
||||
/**
|
||||
* The Q6 statement
|
||||
*/
|
||||
public const string Q6_STATEMENT = "Muestre el nombre de las asignaturas del curso 1A-2018 que tienen un nivel de aprobación menor a 50 %. Una asignatura es aprobada si la nota es mayor o igual a 4,0. TIP: utilice vistas.";
|
||||
/**
|
||||
* The Q1 SQL
|
||||
*/
|
||||
public const string Q1_SQL = "SELECT CONCAT_WS(' ', AL.nombres, AL.apellidos) AS alumno,
|
||||
CONCAT_WS(' ', AP.nombres, AP.apellidos) AS apoderado,
|
||||
CO.nombre curso,
|
||||
CONCAT_WS(' ', PJ.nombres, PJ.apellidos) AS jefe,
|
||||
CONCAT_WS(' ', PA.nombres, PA.apellidos) AS asistente
|
||||
FROM alumno AL
|
||||
JOIN apoderado AP ON (AP.rut_apoderado = AL.rut_apoderado)
|
||||
JOIN cursar CU ON (CU.rut_alumno = AL.rut_alumno)
|
||||
JOIN curso CO ON (CO.id_curso = CU.id_curso)
|
||||
JOIN profesor PJ ON (PJ.rut_profesor = CO.rut_profesor)
|
||||
JOIN asistente ASI ON (ASI.id_curso = CO.id_curso)
|
||||
JOIN profesor PA ON (PA.rut_profesor = ASI.rut_profesor)
|
||||
JOIN ciudad C ON (C.id_ciudad = AL.id_ciudad)
|
||||
JOIN region R ON (R.id_region = C.id_region)
|
||||
WHERE (
|
||||
CO.anyo = 2019 AND (
|
||||
R.nombre_region = 'Bío Bío' OR R.nombre_region = 'Ñuble'
|
||||
)
|
||||
);";
|
||||
/**
|
||||
* The Q2 SQL
|
||||
*/
|
||||
public const string Q2_SQL = "SELECT CONCAT_WS(' ', P.nombres, P.apellidos) AS profesor FROM profesor P
|
||||
JOIN curso C ON (C.rut_profesor = P.rut_profesor)
|
||||
WHERE P.rut_profesor NOT IN (
|
||||
SELECT P2.rut_profesor FROM profesor P2
|
||||
JOIN actividad A ON (A.rut_profesor = P2.rut_profesor)
|
||||
JOIN actividad_nivel A2 ON (A2.id_actividad = A.id_actividad)
|
||||
JOIN nivel N ON (N.id_nivel = A2.id_nivel)
|
||||
WHERE (N.nombre = 'Primero' OR N.nombre = 'Segundo')
|
||||
);";
|
||||
/**
|
||||
* The Q3 SQL
|
||||
*/
|
||||
public const string Q3_SQL = "SELECT A.nombre, COUNT(*) FROM actividad A
|
||||
JOIN participar P ON (P.id_actividad = A.id_actividad)
|
||||
JOIN alumno A2 ON (A2.rut_alumno = P.rut_alumno)
|
||||
WHERE (A2.fecha_nacimiento >= '2006-01-01'
|
||||
AND A2.fecha_nacimiento <= '2008-12-31')
|
||||
GROUP BY (A.nombre)
|
||||
HAVING COUNT(*) > 5;";
|
||||
/**
|
||||
* The Q4 SQL
|
||||
*/
|
||||
public const string Q4_SQL = "CREATE VIEW matriculados(curso, cantidad) AS (
|
||||
SELECT C1.nombre, COUNT(*) FROM curso C1
|
||||
JOIN cursar C2 ON (C2.id_curso = C1.id_curso)
|
||||
WHERE (C1.anyo = 2019)
|
||||
GROUP BY (C1.nombre)
|
||||
);
|
||||
|
||||
SELECT M.curso, M.cantidad FROM matriculados M
|
||||
WHERE (
|
||||
M.cantidad = (
|
||||
SELECT MIN(M2.cantidad) FROM matriculados M2
|
||||
)
|
||||
);";
|
||||
/**
|
||||
* The Q5 SQL
|
||||
*/
|
||||
public const string Q5_SQL = "SELECT A.nombre, AVG(r.nota) FROM asignatura A
|
||||
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
|
||||
JOIN asociado A2 ON (A2.id_asignatura = A.id_asignatura)
|
||||
JOIN alumno A3 ON (A3.rut_alumno = R.rut_alumno)
|
||||
WHERE (
|
||||
A2.id_curso = '6A-2018'
|
||||
AND R.rut_alumno NOT IN (
|
||||
SELECT A4.rut_alumno FROM alumno A4
|
||||
JOIN participar P ON (P.rut_alumno = A4.rut_alumno)
|
||||
JOIN actividad A5 ON (A5.id_actividad = P.id_actividad)
|
||||
WHERE (A5.nombre = 'Rugby' AND A4.rut_alumno = A3.rut_alumno)
|
||||
)
|
||||
)
|
||||
GROUP BY (A.nombre);";
|
||||
/**
|
||||
* The Q6 SQL
|
||||
*/
|
||||
public const string Q6_SQL = "CREATE VIEW total_alumnos(asignatura, cantidad) AS (
|
||||
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
|
||||
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
|
||||
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
|
||||
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
|
||||
WHERE (A3.id_curso = '1A-2018')
|
||||
GROUP BY (A.id_asignatura)
|
||||
);
|
||||
|
||||
CREATE VIEW total_aprobados(asignatura, cantidad) AS (
|
||||
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
|
||||
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
|
||||
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
|
||||
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
|
||||
WHERE (A3.id_curso = '1A-2018' AND R.nota >= 4)
|
||||
GROUP BY (A.id_asignatura)
|
||||
);
|
||||
|
||||
SELECT A2.nombre, TRUNC(CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2)),2) AS porcentaje
|
||||
FROM total_aprobados T1
|
||||
JOIN total_alumnos T2 ON (T2.asignatura = T1.asignatura)
|
||||
JOIN asociado A ON (T1.asignatura = A.id_asignatura AND T2.asignatura = A.id_asignatura)
|
||||
JOIN asignatura A2 ON (A2.id_asignatura = A.id_asignatura)
|
||||
WHERE ((CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2))) < 50);";
|
||||
}
|
||||
}
|
349
src/query_window.vala
Normal file
349
src/query_window.vala
Normal file
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Copyright 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 Colegio {
|
||||
using Constants;
|
||||
using Misc;
|
||||
using DB;
|
||||
using DB.Wrapper;
|
||||
using Postgres;
|
||||
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/colegio/query.window.ui")]
|
||||
public class QueryWindow : Gtk.ApplicationWindow {
|
||||
private Connection conn;
|
||||
public enum Query {
|
||||
Q1,
|
||||
Q2,
|
||||
Q3,
|
||||
Q4,
|
||||
Q5,
|
||||
Q6
|
||||
}
|
||||
private Query query;
|
||||
private enum Q1Column {
|
||||
ALUMNO,
|
||||
APODERADO,
|
||||
CURSO,
|
||||
JEFE,
|
||||
ASISTENTE,
|
||||
N_COLUMNS
|
||||
}
|
||||
private enum Q2Column {
|
||||
PROFESOR,
|
||||
N_COLUMNS
|
||||
}
|
||||
private enum Q3Column {
|
||||
NOMBRE,
|
||||
CANTIDAD,
|
||||
N_COLUMNS
|
||||
}
|
||||
private enum Q4Column {
|
||||
CURSO,
|
||||
CANTIDAD,
|
||||
N_COLUMNS
|
||||
}
|
||||
private enum Q5Column {
|
||||
NOMBRE,
|
||||
PROMEDIO,
|
||||
N_COLUMNS
|
||||
}
|
||||
private enum Q6Column {
|
||||
NOMBRE,
|
||||
PORCENTAJE,
|
||||
N_COLUMNS
|
||||
}
|
||||
private Gtk.ListStore list_store;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.ScrolledWindow scroll_window;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Label statement;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Label sql;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Button run_query;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Button close_query;
|
||||
|
||||
private Gtk.TreeView query_tree;
|
||||
|
||||
[GtkCallback]
|
||||
public void on_clicked_button (Gtk.Button button) {
|
||||
if (button == run_query) {
|
||||
list_store.clear ();
|
||||
if (query == Query.Q1) {
|
||||
var res = conn.db.exec ("
|
||||
SELECT CONCAT_WS(' ', AL.nombres, AL.apellidos) AS alumno,
|
||||
CONCAT_WS(' ', AP.nombres, AP.apellidos) AS apoderado,
|
||||
CO.nombre curso,
|
||||
CONCAT_WS(' ', PJ.nombres, PJ.apellidos) AS jefe,
|
||||
CONCAT_WS(' ', PA.nombres, PA.apellidos) AS asistente
|
||||
FROM alumno AL
|
||||
JOIN apoderado AP ON (AP.rut_apoderado = AL.rut_apoderado)
|
||||
JOIN cursar CU ON (CU.rut_alumno = AL.rut_alumno)
|
||||
JOIN curso CO ON (CO.id_curso = CU.id_curso)
|
||||
JOIN profesor PJ ON (PJ.rut_profesor = CO.rut_profesor)
|
||||
JOIN asistente ASI ON (ASI.id_curso = CO.id_curso)
|
||||
JOIN profesor PA ON (PA.rut_profesor = ASI.rut_profesor)
|
||||
JOIN ciudad C ON (C.id_ciudad = AL.id_ciudad)
|
||||
JOIN region R ON (R.id_region = C.id_region)
|
||||
WHERE (
|
||||
CO.anyo = 2019 AND (
|
||||
R.nombre_region = 'Bío Bío' OR R.nombre_region = 'Ñuble'
|
||||
)
|
||||
);
|
||||
");
|
||||
if (res.get_status () != ExecStatus.TUPLES_OK) {
|
||||
#if DEBUG
|
||||
error (conn.db.get_error_message ());
|
||||
#else
|
||||
warning (conn.db.get_error_message ());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
var wra = new ResultWrapper (res);
|
||||
List<Q1> list = new List<Q1> ();
|
||||
int n = res.get_n_tuples ();
|
||||
for (int i = 0; i < n; i++) {
|
||||
try {
|
||||
var result = new Q1 (wra.get_string_n (i, "alumno"),
|
||||
wra.get_string_n (i, "apoderado"),
|
||||
wra.get_string_n (i, "curso"),
|
||||
wra.get_string_n (i, "jefe"),
|
||||
wra.get_string_n (i, "asistente")
|
||||
);
|
||||
list.append (result);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
list_store.set (iter,
|
||||
Q1Column.ALUMNO, entry.alumno,
|
||||
Q1Column.APODERADO, entry.apoderado,
|
||||
Q1Column.CURSO, entry.curso,
|
||||
Q1Column.JEFE, entry.jefe,
|
||||
Q1Column.ASISTENTE, entry.asistente);
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (query == Query.Q2) {
|
||||
list_store.clear ();
|
||||
var res = conn.db.exec ("
|
||||
SELECT CONCAT_WS(' ', P.nombres, P.apellidos) AS profesor FROM profesor P
|
||||
JOIN curso C ON (C.rut_profesor = P.rut_profesor)
|
||||
WHERE P.rut_profesor NOT IN (
|
||||
SELECT P2.rut_profesor FROM profesor P2
|
||||
JOIN actividad A ON (A.rut_profesor = P2.rut_profesor)
|
||||
JOIN actividad_nivel A2 ON (A2.id_actividad = A.id_actividad)
|
||||
JOIN nivel N ON (N.id_nivel = A2.id_nivel)
|
||||
WHERE (N.nombre = 'Primero' OR N.nombre = 'Segundo')
|
||||
);
|
||||
");
|
||||
if (res.get_status () != ExecStatus.TUPLES_OK) {
|
||||
#if DEBUG
|
||||
error (conn.db.get_error_message ());
|
||||
#else
|
||||
warning (conn.db.get_error_message ());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
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 result = new Q2 (wra.get_string_n (i, "profesor"));
|
||||
list.append (result);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
list_store.set (iter,
|
||||
Q2Column.PROFESOR, entry.profesor);
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (query == Query.Q3) {
|
||||
|
||||
}
|
||||
else if (query == Query.Q4) {
|
||||
|
||||
}
|
||||
else if (query == Query.Q5) {
|
||||
|
||||
}
|
||||
else if (query == Query.Q6) {
|
||||
|
||||
}
|
||||
else {
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
else if (button == close_query) {
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
|
||||
public QueryWindow (Gtk.Application application, Connection conn, Query query) {
|
||||
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/colegio/query.tree.ui");
|
||||
builder.connect_signals (null);
|
||||
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;
|
||||
}
|
||||
else if (query == Query.Q6) {
|
||||
query_tree = builder.get_object ("query_tree_q6") as Gtk.TreeView;
|
||||
}
|
||||
else {
|
||||
this.close ();
|
||||
}
|
||||
query_tree.set_visible (true);
|
||||
|
||||
scroll_window.add (query_tree);
|
||||
}
|
||||
catch (Error e) {
|
||||
// This error is not fatal, so let's keep going
|
||||
warning (e.message);
|
||||
}
|
||||
|
||||
this.set_visible (true); // This fixes: Gtk-CRITICAL **: 23:58:22.139: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar
|
||||
}
|
||||
|
||||
public void initialize () {
|
||||
if (query == Query.Q1) {
|
||||
this.set_title ("(Q1) Alumnos de Bı́obio o Ñuble");
|
||||
|
||||
list_store = new Gtk.ListStore (Q1Column.N_COLUMNS,
|
||||
typeof (string),
|
||||
typeof (string),
|
||||
typeof (string),
|
||||
typeof (string),
|
||||
typeof (string));
|
||||
|
||||
query_tree.set_model (list_store);
|
||||
|
||||
statement.set_text (Q1_STATEMENT);
|
||||
|
||||
sql.set_text (Q1_SQL);
|
||||
}
|
||||
else if (query == Query.Q2) {
|
||||
this.set_title ("(Q2) Tour values");
|
||||
|
||||
list_store = new Gtk.ListStore (Q2Column.N_COLUMNS,
|
||||
typeof (string));
|
||||
|
||||
query_tree.set_model (list_store);
|
||||
|
||||
statement.set_text (Q2_STATEMENT);
|
||||
|
||||
sql.set_text (Q2_SQL);
|
||||
}
|
||||
else if (query == Query.Q3) {
|
||||
this.set_title ("(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 ("(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 ("(Q5) Vehicle total");
|
||||
|
||||
list_store = new Gtk.ListStore (Q5Column.N_COLUMNS,
|
||||
typeof (string),
|
||||
typeof (uint));
|
||||
|
||||
query_tree.set_model (list_store);
|
||||
|
||||
statement.set_text (Q5_STATEMENT);
|
||||
|
||||
sql.set_text (Q5_SQL);
|
||||
}
|
||||
else if (query == Query.Q6) {
|
||||
this.set_title ("(Q6) Vehicle total");
|
||||
|
||||
list_store = new Gtk.ListStore (Q6Column.N_COLUMNS,
|
||||
typeof (string),
|
||||
typeof (uint));
|
||||
|
||||
query_tree.set_model (list_store);
|
||||
|
||||
statement.set_text (Q6_STATEMENT);
|
||||
|
||||
sql.set_text (Q6_SQL);
|
||||
}
|
||||
else {
|
||||
GLib.print ("Consulta inválida!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user