finish city and region text entry

This commit is contained in:
2019-01-19 17:42:43 -03:00
parent 5bd896b153
commit 9ff7178ed5
12 changed files with 460 additions and 252 deletions

View File

@@ -213,7 +213,7 @@ namespace Sernatur {
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
dgettext(null, "Error: Could not connect to the database!"));
_ ("Error: Could not connect to the database!"));
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.CLOSE:

View File

@@ -140,6 +140,7 @@ namespace Sernatur {
region.get_active_iter (out iter);
Region temp_region;
if (region_list_store.iter_is_valid (iter)) {
// The region is from the list, not typed
region_list_store.get (iter,
RegionColumn.REGION, out temp_region);
tour.ciudad.region = temp_region;
@@ -147,9 +148,6 @@ namespace Sernatur {
reset_city ();
}
}
else {
// New region to be created
}
}
}
@@ -195,9 +193,6 @@ namespace Sernatur {
public void on_clicked_button (Gtk.Button button) {
if (button == save) {
if (tour.id_tour == 0) {
// This is if they typed a new city, TODO
/*print (city.get_active_text () + "\n");*/
update_tour_instance ();
try {
Tour.insert_tour (conn, tour);
@@ -243,25 +238,77 @@ namespace Sernatur {
}
}
/**
* Update the the tour object with new info from the editor
*/
private void update_tour_instance () {
tour.nombre_tour = tour_name.get_text ();
tour.costo_indiv = (uint) int.parse (indiv_cost.get_text ());
tour.costo_grupal = (uint) int.parse (group_cost.get_text ());
tour.minima_personas = (uint) minimum_people.get_value_as_int ();
Gtk.TreeIter iter;
Ciudad ciudad;
city.get_active_iter (out iter);
if (city_list_store.iter_is_valid (iter)) {
city_list_store.get (iter,
CityColumn.CITY, out ciudad);
tour.ciudad = ciudad;
if (region.get_active () == -1) {
Region new_region = new Region (0, region.get_active_text ());
try {
new_region.id_region = Region.insert_region (conn, new_region);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
finally {
update_tour_instance_city (new_region);
}
}
Region new_region;
region.get_active_iter (out iter);
if (region_list_store.iter_is_valid (iter)) {
region_list_store.get (iter,
RegionColumn.REGION, out new_region);
tour.ciudad.region = new_region;
else {
Region new_region;
Gtk.TreeIter iter;
region.get_active_iter (out iter);
if (region_list_store.iter_is_valid (iter)) {
region_list_store.get (iter,
RegionColumn.REGION, out new_region);
}
else {
new_region = new Region ();
}
update_tour_instance_city (new_region);
}
}
/**
* This method updates the city part of the tour instance
* @param new_region The region to insert into the city object
*/
private void update_tour_instance_city (Region new_region) {
Ciudad ciudad;
if (city.get_active () == -1) {
ciudad = new Ciudad (0, city.get_active_text ());
ciudad.region = new_region;
try {
ciudad.id_ciudad = Ciudad.insert_city (conn, ciudad);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
finally {
tour.ciudad = ciudad;
}
}
else {
Gtk.TreeIter iter;
city.get_active_iter (out iter);
if (city_list_store.iter_is_valid (iter)) {
city_list_store.get (iter,
CityColumn.CITY, out ciudad);
ciudad.region = new_region;
tour.ciudad = ciudad;
}
}
}

View File

@@ -207,7 +207,7 @@ namespace Sernatur {
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.YES_NO,
dgettext(null, "Are you sure you wish to delete this tour?"));
_ ("Are you sure you wish to delete this tour?"));
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.YES:
@@ -227,7 +227,7 @@ namespace Sernatur {
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
dgettext(null, "Error: Could not delete tour because there are still associated arrival and departure dates and times!"));
_ ("Error: Could not delete tour because there are still associated arrival and departure dates and times!"));
msg2.response.connect ((response_id) => {
msg2.destroy ();
});