finish asignatura editor
This commit is contained in:
parent
1d603d7d5d
commit
ab1dce854c
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.1
|
<!-- Generated with glade 3.22.1
|
||||||
|
|
||||||
Copyright 2018-2019 Chris Cromer
|
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:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
@ -16,17 +16,10 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
-->
|
-->
|
||||||
<interface domain="sernatur">
|
<interface domain="sernatur">
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkAdjustment" id="minimum_people_adjustment">
|
<template class="ColegioAsignaturaEditor" parent="GtkApplicationWindow">
|
||||||
<property name="lower">1</property>
|
|
||||||
<property name="upper">1000</property>
|
|
||||||
<property name="value">1</property>
|
|
||||||
<property name="step_increment">1</property>
|
|
||||||
<property name="page_increment">10</property>
|
|
||||||
</object>
|
|
||||||
<template class="SernaturTourEditor" parent="GtkApplicationWindow">
|
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="type">popup</property>
|
<property name="type">popup</property>
|
||||||
<property name="title" translatable="yes">Tour Editor</property>
|
<property name="title" translatable="yes">Asignatura Editor</property>
|
||||||
<property name="modal">True</property>
|
<property name="modal">True</property>
|
||||||
<property name="window_position">center-on-parent</property>
|
<property name="window_position">center-on-parent</property>
|
||||||
<property name="destroy_with_parent">True</property>
|
<property name="destroy_with_parent">True</property>
|
||||||
@ -50,7 +43,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<property name="margin_right">5</property>
|
<property name="margin_right">5</property>
|
||||||
<property name="margin_top">5</property>
|
<property name="margin_top">5</property>
|
||||||
<property name="margin_bottom">5</property>
|
<property name="margin_bottom">5</property>
|
||||||
<property name="label" translatable="yes">Tour Name</property>
|
<property name="label" translatable="yes">Nombre </property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">0</property>
|
<property name="left_attach">0</property>
|
||||||
@ -58,7 +51,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEntry" id="tour_name">
|
<object class="GtkEntry" id="asignatura_name">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="margin_left">5</property>
|
<property name="margin_left">5</property>
|
||||||
@ -83,193 +76,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<property name="margin_right">5</property>
|
<property name="margin_right">5</property>
|
||||||
<property name="margin_top">5</property>
|
<property name="margin_top">5</property>
|
||||||
<property name="margin_bottom">5</property>
|
<property name="margin_bottom">5</property>
|
||||||
<property name="label" translatable="yes">Individual Cost</property>
|
<property name="label" translatable="yes">Profesor</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">0</property>
|
<property name="left_attach">0</property>
|
||||||
<property name="top_attach">1</property>
|
<property name="top_attach">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">end</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="label" translatable="yes">Group Cost</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">2</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">end</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="label" translatable="yes">Minimum People</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">end</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="label" translatable="yes">Region</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">4</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkEntry" id="indiv_cost">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="max_length">10</property>
|
|
||||||
<property name="caps_lock_warning">False</property>
|
|
||||||
<property name="input_purpose">number</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkEntry" id="group_cost">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="max_length">10</property>
|
|
||||||
<property name="caps_lock_warning">False</property>
|
|
||||||
<property name="input_purpose">number</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">2</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">end</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="label" translatable="yes">City</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">5</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSpinButton" id="minimum_people">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="max_length">4</property>
|
|
||||||
<property name="width_chars">4</property>
|
|
||||||
<property name="caps_lock_warning">False</property>
|
|
||||||
<property name="input_purpose">digits</property>
|
|
||||||
<property name="adjustment">minimum_people_adjustment</property>
|
|
||||||
<property name="snap_to_ticks">True</property>
|
|
||||||
<property name="numeric">True</property>
|
|
||||||
<property name="update_policy">if-valid</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkComboBoxText" id="region">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="focus_on_click">False</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="has_entry">True</property>
|
|
||||||
<property name="popup_fixed_width">False</property>
|
|
||||||
<signal name="changed" handler="on_changed_combobox" swapped="no"/>
|
|
||||||
<child internal-child="entry">
|
|
||||||
<object class="GtkEntry">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="tooltip_text" translatable="yes">Create a new region by typing here.</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="max_length">50</property>
|
|
||||||
<property name="caps_lock_warning">False</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">4</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkComboBoxText" id="city">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="focus_on_click">False</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="has_entry">True</property>
|
|
||||||
<property name="popup_fixed_width">False</property>
|
|
||||||
<child internal-child="entry">
|
|
||||||
<object class="GtkEntry" id="city_entry">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="tooltip_text" translatable="yes">Create a new city by typing here.</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="max_length">50</property>
|
|
||||||
<property name="caps_lock_warning">False</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">5</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -283,7 +96,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<property name="homogeneous">True</property>
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="cancel">
|
<object class="GtkButton" id="cancel">
|
||||||
<property name="label" translatable="yes">Cancel</property>
|
<property name="label" translatable="yes">Cerrar</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
@ -300,47 +113,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="places">
|
|
||||||
<property name="label" translatable="yes">Places</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">True</property>
|
|
||||||
<property name="tooltip_text" translatable="yes">Add or edit places.</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="vehicle">
|
|
||||||
<property name="label" translatable="yes">Vehicle</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">True</property>
|
|
||||||
<property name="tooltip_text" translatable="yes">Assign a vehicle to this tour.</property>
|
|
||||||
<property name="margin_left">5</property>
|
|
||||||
<property name="margin_right">5</property>
|
|
||||||
<property name="margin_top">5</property>
|
|
||||||
<property name="margin_bottom">5</property>
|
|
||||||
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">2</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="save">
|
<object class="GtkButton" id="save">
|
||||||
<property name="label" translatable="yes">Save</property>
|
<property name="label" translatable="yes">Guardar</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
@ -360,10 +135,25 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">0</property>
|
<property name="left_attach">0</property>
|
||||||
<property name="top_attach">6</property>
|
<property name="top_attach">2</property>
|
||||||
<property name="width">2</property>
|
<property name="width">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkComboBoxText" id="profesor">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.1
|
<!-- Generated with glade 3.22.1
|
||||||
|
|
||||||
Copyright 2018-2019 Chris Cromer
|
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:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
265
src/asignatura_editor.vala
Normal file
265
src/asignatura_editor.vala
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
/*
|
||||||
|
* 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/asignatura.editor.ui")]
|
||||||
|
public class AsignaturaEditor : Gtk.ApplicationWindow {
|
||||||
|
private Connection conn;
|
||||||
|
private Asignatura asignatura;
|
||||||
|
|
||||||
|
private List<Profesor> profesores;
|
||||||
|
|
||||||
|
private Gtk.ListStore profesor_list_store;
|
||||||
|
public signal void save_asignatura ();
|
||||||
|
|
||||||
|
private enum ProfesorColumn {
|
||||||
|
PROFESOR_NAME,
|
||||||
|
PROFESOR,
|
||||||
|
N_COLUMNS
|
||||||
|
}
|
||||||
|
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Entry asignatura_name;
|
||||||
|
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.ComboBoxText profesor;
|
||||||
|
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Button save;
|
||||||
|
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Button cancel;
|
||||||
|
|
||||||
|
public AsignaturaEditor (Gtk.Application application, Connection conn, Asignatura? asignatura) {
|
||||||
|
Object (application: application);
|
||||||
|
this.conn = conn;
|
||||||
|
this.asignatura = asignatura;
|
||||||
|
}
|
||||||
|
|
||||||
|
[GtkCallback]
|
||||||
|
public void on_clicked_button (Gtk.Button button) {
|
||||||
|
if (button == cancel) {
|
||||||
|
this.close ();
|
||||||
|
}
|
||||||
|
else if (button == save) {
|
||||||
|
update_instance ();
|
||||||
|
if (validate_data ()) {
|
||||||
|
if (asignatura.id_asignatura == 0) {
|
||||||
|
try {
|
||||||
|
var res = conn.db.exec ("
|
||||||
|
INSERT INTO asignatura
|
||||||
|
(nombre, rut_profesor)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
'" + conn.escape (asignatura.nombre) + "',
|
||||||
|
" + conn.escape (asignatura.profesor.rut_profesor) + "
|
||||||
|
)
|
||||||
|
RETURNING 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PostgresError e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
save_asignatura (); // Signal the parent to update itself
|
||||||
|
this.close ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
var res = conn.db.exec ("
|
||||||
|
UPDATE asignatura SET
|
||||||
|
nombre = '" + conn.escape (asignatura.nombre) + "',
|
||||||
|
rut_profesor = " + conn.escape (asignatura.profesor.rut_profesor) + "
|
||||||
|
WHERE id_asignatura = " + 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
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
save_asignatura (); // Signal the parent to update itself
|
||||||
|
this.close ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool validate_data () {
|
||||||
|
if (asignatura.nombre.strip () == "") {
|
||||||
|
var msg = new Gtk.MessageDialog (this,
|
||||||
|
Gtk.DialogFlags.MODAL,
|
||||||
|
Gtk.MessageType.ERROR,
|
||||||
|
Gtk.ButtonsType.CLOSE,
|
||||||
|
"Error: No se puede dejar el nombre de la asignatura en blanco!");
|
||||||
|
msg.response.connect ((response_id) => {
|
||||||
|
msg.destroy ();
|
||||||
|
});
|
||||||
|
msg.set_title ("Error");
|
||||||
|
msg.run ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var res = conn.db.exec ("
|
||||||
|
SELECT id_asignatura, nombre, rut_profesor
|
||||||
|
FROM asignatura
|
||||||
|
");
|
||||||
|
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 (wra.get_int_n (i, "id_asignatura") != asignatura.id_asignatura &&
|
||||||
|
wra.get_string_n (i, "nombre").down () == asignatura.nombre.down () &&
|
||||||
|
wra.get_string_n (i, "rut_profesor") == asignatura.profesor.rut_profesor) {
|
||||||
|
var msg = new Gtk.MessageDialog (this,
|
||||||
|
Gtk.DialogFlags.MODAL,
|
||||||
|
Gtk.MessageType.ERROR,
|
||||||
|
Gtk.ButtonsType.CLOSE,
|
||||||
|
"Error: Una asignatura \"%s\" con el profesor \"%s\" ya existe!",
|
||||||
|
asignatura.nombre, asignatura.profesor.nombres + " " + asignatura.profesor.apellidos);
|
||||||
|
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 void update_instance () {
|
||||||
|
asignatura.nombre = asignatura_name.get_text ().strip ();
|
||||||
|
Profesor new_profesor = new Profesor();
|
||||||
|
Gtk.TreeIter iter;
|
||||||
|
profesor.get_active_iter (out iter);
|
||||||
|
if (profesor_list_store.iter_is_valid (iter)) {
|
||||||
|
profesor_list_store.get (iter,
|
||||||
|
ProfesorColumn.PROFESOR, out new_profesor);
|
||||||
|
}
|
||||||
|
asignatura.profesor = new_profesor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize () {
|
||||||
|
var res = conn.db.exec ("
|
||||||
|
SELECT rut_profesor, nombres, apellidos
|
||||||
|
FROM profesor
|
||||||
|
");
|
||||||
|
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);
|
||||||
|
profesores = new List<Profesor> ();
|
||||||
|
int n = res.get_n_tuples ();
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
try {
|
||||||
|
var result = new Profesor (
|
||||||
|
wra.get_string_n (i, "rut_profesor"),
|
||||||
|
wra.get_string_n (i, "nombres"),
|
||||||
|
wra.get_string_n (i, "apellidos")
|
||||||
|
);
|
||||||
|
profesores.append (result);
|
||||||
|
}
|
||||||
|
catch (Error e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
profesores.sort_with_data ((a, b) => {
|
||||||
|
return strcmp (a.nombres, b.nombres);
|
||||||
|
});
|
||||||
|
|
||||||
|
profesor_list_store = new Gtk.ListStore (ProfesorColumn.N_COLUMNS,
|
||||||
|
typeof (string),
|
||||||
|
typeof (Profesor));
|
||||||
|
|
||||||
|
profesor.set_model (profesor_list_store);
|
||||||
|
|
||||||
|
if (asignatura != null) {
|
||||||
|
asignatura_name.set_text (asignatura.nombre);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
asignatura = new Asignatura ();
|
||||||
|
asignatura.profesor = new Profesor ();
|
||||||
|
}
|
||||||
|
|
||||||
|
profesores.foreach ((entry) => {
|
||||||
|
Gtk.TreeIter iter;
|
||||||
|
profesor_list_store.append (out iter);
|
||||||
|
profesor_list_store.set (iter,
|
||||||
|
ProfesorColumn.PROFESOR_NAME, entry.nombres + " " + entry.apellidos,
|
||||||
|
ProfesorColumn.PROFESOR, entry);
|
||||||
|
if (entry.rut_profesor == asignatura.profesor.rut_profesor) {
|
||||||
|
profesor.set_active_iter (iter);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,9 @@ namespace Colegio {
|
|||||||
[GtkChild]
|
[GtkChild]
|
||||||
private Gtk.TreeView asignatura_tree;
|
private Gtk.TreeView asignatura_tree;
|
||||||
|
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Button new_asignatura;
|
||||||
|
|
||||||
[GtkChild]
|
[GtkChild]
|
||||||
private Gtk.Button edit_asignatura;
|
private Gtk.Button edit_asignatura;
|
||||||
|
|
||||||
@ -64,6 +67,30 @@ namespace Colegio {
|
|||||||
if (button == close_asignatura) {
|
if (button == close_asignatura) {
|
||||||
this.close ();
|
this.close ();
|
||||||
}
|
}
|
||||||
|
if (button == new_asignatura) {
|
||||||
|
var asignatura_editor = new AsignaturaEditor (application, conn, null);
|
||||||
|
asignatura_editor.set_transient_for (this); // Set this window as the parent of the new window
|
||||||
|
asignatura_editor.initialize ();
|
||||||
|
asignatura_editor.show_all ();
|
||||||
|
asignatura_editor.save_asignatura.connect (on_save);
|
||||||
|
}
|
||||||
|
else if (button == edit_asignatura) {
|
||||||
|
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 ());
|
||||||
|
Asignatura asignatura;
|
||||||
|
model.get (iter,
|
||||||
|
Column.ASIGNATURA, out asignatura);
|
||||||
|
var asignatura_editor = new AsignaturaEditor (application, conn, asignatura);
|
||||||
|
asignatura_editor.set_transient_for (this); // Set this window as the parent of the new window
|
||||||
|
asignatura_editor.initialize ();
|
||||||
|
asignatura_editor.show_all ();
|
||||||
|
asignatura_editor.save_asignatura.connect (on_save);
|
||||||
|
});
|
||||||
|
}
|
||||||
else if (button == delete_asignatura) {
|
else if (button == delete_asignatura) {
|
||||||
Gtk.MessageDialog msg;
|
Gtk.MessageDialog msg;
|
||||||
if (selection.count_selected_rows () == 1) {
|
if (selection.count_selected_rows () == 1) {
|
||||||
@ -102,7 +129,7 @@ WHERE id_asignatura = " + asignatura.id_asignatura.to_string ());
|
|||||||
Gtk.DialogFlags.MODAL,
|
Gtk.DialogFlags.MODAL,
|
||||||
Gtk.MessageType.ERROR,
|
Gtk.MessageType.ERROR,
|
||||||
Gtk.ButtonsType.CLOSE,
|
Gtk.ButtonsType.CLOSE,
|
||||||
"Error: No se puede eleminar la asignatura \"%s\" porque todavia está asociado a cursos, alumnos y actividades!", asignatura.nombre);
|
"Error: No se puede eleminar la asignatura \"%s\" porque todavia está asociado a cursos, alumnos y horarios!", asignatura.nombre);
|
||||||
msg2.response.connect ((response_id) => {
|
msg2.response.connect ((response_id) => {
|
||||||
msg2.destroy ();
|
msg2.destroy ();
|
||||||
});
|
});
|
||||||
@ -209,6 +236,16 @@ WHERE id_asignatura = " + asignatura.id_asignatura.to_string ());
|
|||||||
teacher.sort_order = Gtk.SortType.DESCENDING;
|
teacher.sort_order = Gtk.SortType.DESCENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void on_save(AsignaturaEditor asignatura_editor) {
|
||||||
|
edit_asignatura.sensitive = false;
|
||||||
|
delete_asignatura.sensitive = false;
|
||||||
|
reset_columns ();
|
||||||
|
|
||||||
|
list_store.clear ();
|
||||||
|
|
||||||
|
update_list_store ();
|
||||||
|
}
|
||||||
|
|
||||||
private void update_list_store () {
|
private void update_list_store () {
|
||||||
var res = conn.db.exec ("
|
var res = conn.db.exec ("
|
||||||
SELECT A.id_asignatura, A.nombre,
|
SELECT A.id_asignatura, A.nombre,
|
||||||
|
@ -14,6 +14,7 @@ config_data_file = configure_file(input: 'config.vala.in',
|
|||||||
configuration: config_data)
|
configuration: config_data)
|
||||||
|
|
||||||
vala_sources = files(
|
vala_sources = files(
|
||||||
|
'asignatura_editor.vala',
|
||||||
'asignatura_list.vala',
|
'asignatura_list.vala',
|
||||||
'colegio.vala',
|
'colegio.vala',
|
||||||
'db.vala',
|
'db.vala',
|
||||||
|
Loading…
Reference in New Issue
Block a user