diff --git a/data/ui/asociado.editor.ui b/data/ui/asociado.editor.ui
new file mode 100644
index 0000000..579d674
--- /dev/null
+++ b/data/ui/asociado.editor.ui
@@ -0,0 +1,156 @@
+
+
+
+
+
+ False
+ popup
+ Curso Editor
+ True
+ center-on-parent
+ True
+ dialog
+ True
+ True
+ False
+
+
+
+
+
+
+
+
diff --git a/data/ui/asociado.gresource.xml b/data/ui/asociado.gresource.xml
new file mode 100644
index 0000000..9ce60d7
--- /dev/null
+++ b/data/ui/asociado.gresource.xml
@@ -0,0 +1,20 @@
+
+
+
+
+ asociado.list.ui
+ asociado.editor.ui
+
+
diff --git a/data/ui/asociado.list.ui b/data/ui/asociado.list.ui
new file mode 100644
index 0000000..8ac7d50
--- /dev/null
+++ b/data/ui/asociado.list.ui
@@ -0,0 +1,175 @@
+
+
+
+
+
+
+ False
+ popup
+ Curso
+ True
+ center-on-parent
+ 240
+ True
+ dialog
+ True
+ True
+ False
+
+
+
+
+
+ True
+ True
+
+
+ True
+ True
+ True
+ True
+ never
+ in
+
+
+ True
+ True
+ True
+ True
+ natural
+ natural
+ liststore1
+ True
+ both
+ True
+
+
+ multiple
+
+
+
+
+
+ fixed
+ Curso
+ True
+
+
+
+
+ 0
+
+
+
+
+
+
+ fixed
+ Asignatura
+ True
+
+
+
+
+ 1
+
+
+
+
+
+
+
+
+ 0
+ 0
+
+
+
+
+ True
+ True
+ 5
+ 5
+ 5
+ 5
+ True
+ 25
+ True
+
+
+ Modificar
+ True
+ False
+ True
+ True
+
+
+
+ 1
+ 0
+
+
+
+
+ Nuevo
+ True
+ True
+ True
+
+
+
+ 0
+ 0
+
+
+
+
+ Eliminar
+ True
+ False
+ True
+ True
+
+
+
+ 2
+ 0
+
+
+
+
+ Cerrar
+ True
+ True
+ True
+
+
+
+ 3
+ 0
+
+
+
+
+ 0
+ 1
+
+
+
+
+
+
diff --git a/data/ui/meson.build b/data/ui/meson.build
index a7f5cac..4851b8c 100644
--- a/data/ui/meson.build
+++ b/data/ui/meson.build
@@ -11,6 +11,12 @@ asignatura_gresource = gnome.compile_resources('asignatura_gresource',
c_name: meson.project_name() + '_resource_asignatura',
export: true,
install_header: true)
+asociado_gresource = gnome.compile_resources('asociado_gresource',
+ 'asociado.gresource.xml',
+ source_dir: '.',
+ c_name: meson.project_name() + '_resource_asociado',
+ export: true,
+ install_header: true)
horario_gresource = gnome.compile_resources('horario_gresource',
'horario.gresource.xml',
source_dir: '.',
diff --git a/src/asociado_editor.vala b/src/asociado_editor.vala
new file mode 100644
index 0000000..1520f8e
--- /dev/null
+++ b/src/asociado_editor.vala
@@ -0,0 +1,351 @@
+/*
+ * 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/asociado.editor.ui")]
+ public class AsociadoEditor : Gtk.ApplicationWindow {
+ private Connection conn;
+ private Asociado asociado;
+ private Asociado? old_asociado = null;
+
+ private List asignaturas;
+ private Gtk.ListStore asignatura_list_store;
+ private List cursos;
+ private Gtk.ListStore curso_list_store;
+
+ public signal void save_asociado ();
+
+ private enum AsignaturaColumn {
+ NAME,
+ ASIGNATURA,
+ N_COLUMNS
+ }
+ private enum CursoColumn {
+ NAME,
+ CURSO,
+ N_COLUMNS
+ }
+
+ [GtkChild]
+ private Gtk.ComboBoxText asignatura;
+
+ [GtkChild]
+ private Gtk.ComboBoxText curso;
+
+ [GtkChild]
+ private Gtk.Button save;
+
+ [GtkChild]
+ private Gtk.Button cancel;
+
+ public AsociadoEditor (Gtk.Application application, Connection conn, Asociado? asociado) {
+ Object (application: application);
+ this.conn = conn;
+ this.asociado = asociado;
+ if (this.asociado != null) {
+ this.old_asociado = new Asociado ();
+ this.old_asociado.copy (asociado);
+ }
+ }
+
+ [GtkCallback]
+ public void on_clicked_button (Gtk.Button button) {
+ if (button == cancel) {
+ this.close ();
+ }
+ else if (button == save) {
+ update_instance ();
+ if (validate_data ()) {
+ if (old_asociado == null) {
+ try {
+ var res = conn.db.exec ("
+INSERT INTO asociado
+(id_asignatura, id_curso)
+VALUES
+(
+'" + asociado.asignatura.id_asignatura.to_string () + "',
+'" + conn.escape (asociado.curso.id_curso) + "'
+)
+ ");
+ if (res.get_status () != ExecStatus.COMMAND_OK) {
+ #if DEBUG
+ error (conn.db.get_error_message ());
+ #else
+ warning (conn.db.get_error_message ());
+ #endif
+ }
+ }
+ catch (PostgresError e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ finally {
+ save_asociado (); // Signal the parent to update itself
+ this.close ();
+ }
+ }
+ else {
+ try {
+ var res = conn.db.exec ("
+UPDATE asociado SET
+ id_asignatura = " + asociado.asignatura.id_asignatura.to_string () + ",
+ id_curso = '" + conn.escape (asociado.curso.id_curso) + "'
+WHERE id_asignatura = " + old_asociado.asignatura.id_asignatura.to_string () + " AND
+id_curso = '" + conn.escape (old_asociado.curso.id_curso) + "'"
+ );
+ if (res.get_status () != ExecStatus.COMMAND_OK) {
+ #if DEBUG
+ error (conn.db.get_error_message ());
+ #else
+ warning (conn.db.get_error_message ());
+ #endif
+ }
+ }
+ catch (PostgresError e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ finally {
+ save_asociado (); // Signal the parent to update itself
+ this.close ();
+ }
+ }
+ }
+ }
+ }
+
+ private bool validate_data () {
+ var res = conn.db.exec ("
+SELECT id_asignatura, id_curso
+FROM asociado
+ ");
+ if (res.get_status () != ExecStatus.TUPLES_OK) {
+ #if DEBUG
+ error (conn.db.get_error_message ());
+ #else
+ warning (conn.db.get_error_message ());
+ return false;
+ #endif
+ }
+ else {
+ var wra = new ResultWrapper (res);
+ int n = res.get_n_tuples ();
+ for (int i = 0; i < n; i++) {
+ try {
+ if (check_old_asociado (wra, i) &&
+ wra.get_int_n (i, "id_asignatura") == asociado.asignatura.id_asignatura &&
+ wra.get_string_n (i, "id_curso") == asociado.curso.id_curso) {
+ var msg = new Gtk.MessageDialog (this,
+ Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.CLOSE,
+ "Error: Un curso \"%s\" con la asignatura \"%s\" ya existe!",
+ asociado.curso.nombre, asociado.asignatura.nombre);
+ msg.response.connect ((response_id) => {
+ msg.destroy ();
+ });
+ msg.set_title ("Error");
+ msg.run ();
+ return false;
+ }
+ }
+ catch (Error e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ }
+ }
+ return true;
+ }
+
+ private bool check_old_asociado (ResultWrapper wra, int i) {
+ try {
+ if (old_asociado == null) {
+ // This is a new asociado
+ return true;
+ }
+ else if (old_asociado.asignatura.id_asignatura != wra.get_int_n (i, "id_asignatura") ||
+ old_asociado.curso.id_curso != wra.get_string_n (i, "id_curso")) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ catch (Error e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ return false;
+ #endif
+ }
+ }
+
+ private void update_instance () {
+ Asignatura new_asignatura = new Asignatura ();
+ Gtk.TreeIter iter;
+ asignatura.get_active_iter (out iter);
+ if (asignatura_list_store.iter_is_valid (iter)) {
+ asignatura_list_store.get (iter,
+ AsignaturaColumn.ASIGNATURA, out new_asignatura);
+ }
+ asociado.asignatura = new_asignatura;
+
+ Curso new_curso = new Curso ();
+ curso.get_active_iter (out iter);
+ if (curso_list_store.iter_is_valid (iter)) {
+ curso_list_store.get (iter,
+ CursoColumn.CURSO, out new_curso);
+ }
+ asociado.curso = new_curso;
+ }
+
+ public void initialize () {
+ var res = conn.db.exec ("
+SELECT id_asignatura, nombre
+FROM asignatura
+ ");
+ 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);
+ asignaturas = new List ();
+ int n = res.get_n_tuples ();
+ for (int i = 0; i < n; i++) {
+ try {
+ var result = new Asignatura (
+ wra.get_int_n (i, "id_asignatura"),
+ wra.get_string_n (i, "nombre")
+ );
+ asignaturas.append (result);
+ }
+ catch (Error e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ }
+ }
+
+ res = conn.db.exec ("
+SELECT id_curso, nombre
+FROM curso
+ ");
+ 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);
+ cursos = new List ();
+ int n = res.get_n_tuples ();
+ for (int i = 0; i < n; i++) {
+ try {
+ var result = new Curso (
+ wra.get_string_n (i, "id_curso"),
+ wra.get_string_n (i, "nombre")
+ );
+ cursos.append (result);
+ }
+ catch (Error e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ }
+ }
+
+ asignaturas.sort_with_data ((a, b) => {
+ return strcmp (a.nombre, b.nombre);
+ });
+
+ cursos.sort_with_data ((a, b) => {
+ return strcmp (a.nombre, b.nombre);
+ });
+
+ asignatura_list_store = new Gtk.ListStore (AsignaturaColumn.N_COLUMNS,
+ typeof (string),
+ typeof (Asignatura));
+
+ curso_list_store = new Gtk.ListStore (CursoColumn.N_COLUMNS,
+ typeof (string),
+ typeof (Curso));
+
+ asignatura.set_model (asignatura_list_store);
+
+ curso.set_model (curso_list_store);
+
+ if (asociado == null) {
+ asociado = new Asociado ();
+ asociado.asignatura = new Asignatura ();
+ asociado.curso = new Curso ();
+ }
+
+ asignaturas.foreach ((entry) => {
+ Gtk.TreeIter iter;
+ asignatura_list_store.append (out iter);
+ asignatura_list_store.set (iter,
+ AsignaturaColumn.NAME, entry.nombre,
+ AsignaturaColumn.ASIGNATURA, entry);
+ if (entry.id_asignatura == asociado.asignatura.id_asignatura) {
+ asignatura.set_active_iter (iter);
+ }
+ });
+
+ cursos.foreach ((entry) => {
+ Gtk.TreeIter iter;
+ curso_list_store.append (out iter);
+ curso_list_store.set (iter,
+ CursoColumn.NAME, entry.id_curso,
+ CursoColumn.CURSO, entry);
+ if (entry.id_curso == asociado.curso.id_curso) {
+ curso.set_active_iter (iter);
+ }
+ });
+
+ if (asociado.asignatura.id_asignatura == 0 && asociado.curso.id_curso.strip () == "") {
+ asignatura.set_active (0);
+ curso.set_active (0);
+ }
+ }
+ }
+}
diff --git a/src/asociado_list.vala b/src/asociado_list.vala
new file mode 100644
index 0000000..a31f017
--- /dev/null
+++ b/src/asociado_list.vala
@@ -0,0 +1,315 @@
+/*
+ * 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/asociado.list.ui")]
+ public class AsociadoList : Gtk.ApplicationWindow {
+ private Connection conn;
+ private enum Column {
+ CURSO,
+ ASIGNATURA,
+ ASOCIADO,
+ N_COLUMNS
+ }
+ private Gtk.ListStore list_store;
+ private List asociado_list;
+
+ [GtkChild]
+ private Gtk.TreeView asociado_tree;
+
+ [GtkChild]
+ private Gtk.Button new_asociado;
+
+ [GtkChild]
+ private Gtk.Button edit_asociado;
+
+ [GtkChild]
+ private Gtk.Button delete_asociado;
+
+ [GtkChild]
+ private Gtk.Button close_asociado;
+
+ [GtkChild]
+ private Gtk.TreeViewColumn curso;
+
+ [GtkChild]
+ private Gtk.TreeViewColumn asignatura;
+
+ [GtkChild]
+ private Gtk.TreeSelection selection;
+
+ public AsociadoList (Gtk.Application application, Connection conn) {
+ Object (application: application);
+ this.conn = conn;
+
+ this.set_visible (true); // This fixes: Gtk-CRITICAL **: 23:58:22.139: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar
+ }
+
+ [GtkCallback]
+ public void on_clicked_button (Gtk.Button button) {
+ if (button == close_asociado) {
+ this.close ();
+ }
+ if (button == new_asociado) {
+ var asociado_editor = new AsociadoEditor (application, conn, null);
+ asociado_editor.set_transient_for (this); // Set this window as the parent of the new window
+ asociado_editor.initialize ();
+ asociado_editor.show_all ();
+ asociado_editor.save_asociado.connect (on_save);
+ }
+ else if (button == edit_asociado) {
+ Gtk.TreeModel model;
+ var path = selection.get_selected_rows (out model);
+ path.foreach ((entry) => {
+ var tree_row_reference = new Gtk.TreeRowReference (model, entry);
+ Gtk.TreeIter iter;
+ list_store.get_iter (out iter, tree_row_reference.get_path ());
+ Asociado asociado;
+ model.get (iter,
+ Column.ASOCIADO, out asociado);
+ var asociado_editor = new AsociadoEditor (application, conn, asociado);
+ asociado_editor.set_transient_for (this); // Set this window as the parent of the new window
+ asociado_editor.initialize ();
+ asociado_editor.show_all ();
+ asociado_editor.save_asociado.connect (on_save);
+ });
+ }
+ else if (button == delete_asociado) {
+ Gtk.MessageDialog msg;
+ if (selection.count_selected_rows () == 1) {
+ msg = new Gtk.MessageDialog (this,
+ Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.YES_NO,
+ "¿Está seguro que quiere eliminar este curso?");
+ }
+ else {
+ msg = new Gtk.MessageDialog (this,
+ Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.YES_NO,
+ "¿Está seguro que quiere eliminar estos cursos?");
+ }
+ msg.response.connect ((response_id) => {
+ switch (response_id) {
+ case Gtk.ResponseType.YES:
+ Gtk.TreeModel model;
+ var path = selection.get_selected_rows (out model);
+ path.foreach ((entry) => {
+ var tree_row_reference = new Gtk.TreeRowReference (model, entry);
+ Gtk.TreeIter iter;
+ list_store.get_iter (out iter, tree_row_reference.get_path ());
+ Asociado asociado;
+ model.get (iter,
+ Column.ASOCIADO, out asociado);
+ try {
+ var res = conn.db.exec ("
+ DELETE FROM asociado
+ WHERE id_curso = '" + conn.escape (asociado.curso.id_curso) + "' AND
+ id_asignatura = " + asociado.asignatura.id_asignatura.to_string ());
+ if (res.get_status () != ExecStatus.COMMAND_OK) {
+ #if DEBUG
+ error (conn.db.get_error_message ());
+ #else
+ warning (conn.db.get_error_message ());
+ #endif
+ }
+ }
+ catch (PostgresError e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ });
+ edit_asociado.sensitive = false;
+ delete_asociado.sensitive = false;
+ reset_columns ();
+
+ list_store.clear ();
+
+ update_list_store ();
+ break;
+ }
+ msg.destroy ();
+ });
+ msg.show ();
+ }
+ }
+
+ [GtkCallback]
+ private void on_changed_selection(Gtk.TreeSelection selection) {
+ if (selection.count_selected_rows () == 1) {
+ edit_asociado.sensitive = true;
+ delete_asociado.sensitive =true;
+ }
+ else if (selection.count_selected_rows () > 1) {
+ edit_asociado.sensitive = false;
+ delete_asociado.sensitive = true;
+ }
+ else {
+ edit_asociado.sensitive = false;
+ delete_asociado.sensitive = false;
+ }
+ }
+
+ [GtkCallback]
+ private void on_clicked_column (Gtk.TreeViewColumn column) {
+ edit_asociado.sensitive = false;
+ delete_asociado.sensitive = false;
+ if (column == asignatura) {
+ if (!asignatura.sort_indicator) {
+ reset_columns ();
+ asignatura.sort_indicator = true;
+ }
+
+ if (asignatura.sort_order == Gtk.SortType.ASCENDING) {
+ asignatura.sort_order = Gtk.SortType.DESCENDING;
+ }
+ else {
+ asignatura.sort_order = Gtk.SortType.ASCENDING;
+ }
+
+ asociado_list.sort_with_data ((a, b) => {
+ if (asignatura.sort_order == Gtk.SortType.ASCENDING) {
+ return strcmp (a.asignatura.nombre, b.asignatura.nombre);
+ }
+ else {
+ return strcmp (b.asignatura.nombre, a.asignatura.nombre);
+ }
+ });
+ }
+ else if (column == curso) {
+ if (!curso.sort_indicator) {
+ reset_columns ();
+ curso.sort_indicator = true;
+ }
+
+ if (curso.sort_order == Gtk.SortType.ASCENDING) {
+ curso.sort_order = Gtk.SortType.DESCENDING;
+ }
+ else {
+ curso.sort_order = Gtk.SortType.ASCENDING;
+ }
+
+ asociado_list.sort_with_data ((a, b) => {
+ if (curso.sort_order == Gtk.SortType.ASCENDING) {
+ return strcmp (a.curso.nombre, b.curso.nombre);
+ }
+ else {
+ return strcmp (b.curso.nombre, a.curso.nombre);
+ }
+ });
+ }
+
+ list_store.clear ();
+ asociado_list.foreach ((entry) => {
+ Gtk.TreeIter iter;
+ list_store.append (out iter);
+ list_store.set (iter,
+ Column.CURSO, entry.curso.nombre,
+ Column.ASIGNATURA, entry.asignatura.nombre,
+ Column.ASOCIADO, entry);
+ });
+ }
+
+ private void reset_columns () {
+ curso.sort_indicator = false;
+ curso.sort_order = Gtk.SortType.DESCENDING;
+ asignatura.sort_indicator = false;
+ asignatura.sort_order = Gtk.SortType.DESCENDING;
+ }
+
+ public void on_save(AsociadoEditor asociado_editor) {
+ edit_asociado.sensitive = false;
+ delete_asociado.sensitive = false;
+ reset_columns ();
+
+ list_store.clear ();
+
+ update_list_store ();
+ }
+
+ private void update_list_store () {
+ var res = conn.db.exec ("
+SELECT C.id_curso, C.nombre AS nombre_curso,
+ A2.id_asignatura, A2.nombre AS nombre_asignatura
+FROM asociado A
+JOIN curso C on (C.id_curso = A.id_curso)
+JOIN asignatura A2 on (A2.id_asignatura = A.id_asignatura)
+ ");
+ 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);
+ asociado_list = new List ();
+ int n = res.get_n_tuples ();
+ for (int i = 0; i < n; i++) {
+ try {
+ var result = new Asociado (
+ new Curso (
+ wra.get_string_n (i, "id_curso"),
+ wra.get_string_n (i, "nombre_curso")
+ ),
+ new Asignatura (
+ wra.get_int_n (i, "id_asignatura"),
+ wra.get_string_n (i, "nombre_asignatura")
+ )
+ );
+ asociado_list.append (result);
+ }
+ catch (Error e) {
+ #if DEBUG
+ error (e.message);
+ #else
+ warning (e.message);
+ #endif
+ }
+ }
+
+ asociado_list.foreach ((entry) => {
+ Gtk.TreeIter iter;
+ list_store.append (out iter);
+ list_store.set (iter,
+ Column.CURSO, entry.curso.id_curso,
+ Column.ASIGNATURA, entry.asignatura.nombre,
+ Column.ASOCIADO, entry);
+ });
+ }
+ }
+
+ public void initialize () {
+ list_store = new Gtk.ListStore (Column.N_COLUMNS,
+ typeof (string),
+ typeof (string),
+ typeof (Asociado));
+
+ update_list_store ();
+
+ asociado_tree.set_model (list_store);
+ }
+ }
+}
diff --git a/src/db/asociado.vala b/src/db/asociado.vala
new file mode 100644
index 0000000..b8609c0
--- /dev/null
+++ b/src/db/asociado.vala
@@ -0,0 +1,20 @@
+namespace Colegio {
+ namespace DB {
+ public class Asociado : Object {
+ public Curso curso { get; set; default = new Curso (); }
+ public Asignatura asignatura { get; set; default = new Asignatura (); }
+
+ public Asociado (Curso curso = new Curso (), Asignatura asignatura = new Asignatura ()) {
+ this.curso = curso;
+ this.asignatura = asignatura;
+ }
+
+ public void copy (Asociado asociado) {
+ this.curso = new Curso ();
+ this.curso.copy (asociado.curso);
+ this.asignatura = new Asignatura ();
+ this.asignatura.copy (asociado.asignatura);
+ }
+ }
+ }
+}
diff --git a/src/db/curso.vala b/src/db/curso.vala
new file mode 100644
index 0000000..dab1adf
--- /dev/null
+++ b/src/db/curso.vala
@@ -0,0 +1,23 @@
+namespace Colegio {
+ namespace DB {
+ public class Curso : Object {
+ public string id_curso { get; set; default = ""; }
+ public string nombre { get; set; default = ""; }
+ public string anyo { get; set; default = ""; }
+ public Profesor profesor { get; set; default = new Profesor (); }
+
+ public Curso (string id_curso = "", string nombre = "", string anyo = "", Profesor profesor = new Profesor ()) {
+ this.id_curso = id_curso;
+ this.nombre = nombre;
+ this.anyo = anyo;
+ this.profesor = profesor;
+ }
+
+ public void copy (Curso curso) {
+ this.id_curso = curso.id_curso;
+ this.nombre = curso.nombre;
+ this.anyo = curso.anyo;
+ }
+ }
+ }
+}
diff --git a/src/horario_list.vala b/src/horario_list.vala
index 4debdc7..06039d5 100644
--- a/src/horario_list.vala
+++ b/src/horario_list.vala
@@ -123,7 +123,7 @@ namespace Colegio {
Horario horario;
model.get (iter,
Column.HORARIO, out horario);
- var res = conn.db.exec ("
+ var res = conn.db.exec ("
DELETE FROM horario
WHERE id_asignatura = " + horario.asignatura.id_asignatura.to_string () + " AND
id_bloque = " + horario.bloque.id_bloque.to_string ());
diff --git a/src/main_window.vala b/src/main_window.vala
index 3f89979..6e96ca0 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -30,6 +30,9 @@ namespace Colegio {
[GtkChild]
private Gtk.MenuItem horarios;
+ [GtkChild]
+ private Gtk.MenuItem curso;
+
[GtkChild]
private Gtk.MenuItem q1;
@@ -70,6 +73,12 @@ namespace Colegio {
horarios_window.initialize ();
horarios_window.show_all ();
}
+ else if (menu_item == curso) {
+ var asociado_window = new AsociadoList (application, conn);
+ asociado_window.set_transient_for (this); // Set this window as the parent of the new window
+ asociado_window.initialize ();
+ asociado_window.show_all ();
+ }
else 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
diff --git a/src/meson.build b/src/meson.build
index 84ae1b2..1d1e1cf 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -16,6 +16,8 @@ config_data_file = configure_file(input: 'config.vala.in',
vala_sources = files(
'asignatura_editor.vala',
'asignatura_list.vala',
+ 'asociado_editor.vala',
+ 'asociado_list.vala',
'colegio.vala',
'db.vala',
'dbwrapper.vala',
@@ -26,8 +28,10 @@ vala_sources = files(
'queries.vala',
'query_window.vala',
'db/asignatura.vala',
+ 'db/asociado.vala',
'db/bloque.vala',
'db/ciudad.vala',
+ 'db/curso.vala',
'db/horario.vala',
'db/profesor.vala',
'db/q1.vala',
@@ -41,6 +45,7 @@ vala_sources = files(
sources = vala_sources
sources += main_gresource
sources += asignatura_gresource
+sources += asociado_gresource
sources += horario_gresource
sources += query_gresource
sources += config_data_file
@@ -52,7 +57,7 @@ inc = include_directories('./')
exe = executable(meson.project_name(),
sources,
vala_args: vala_args,
- include_directories : inc,
+ include_directories: inc,
gui_app: true,
dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep],
install: true)