finish assignment for vehicles
This commit is contained in:
@@ -69,6 +69,10 @@ namespace Sernatur {
|
||||
* A list of the vehicles from the database
|
||||
*/
|
||||
private List<Vehiculo> vehicles;
|
||||
/**
|
||||
* A vehicle required object from the database
|
||||
*/
|
||||
private RequerirAuto require_vehicle;
|
||||
/**
|
||||
* The list that stores the vehicles for the combo box
|
||||
*/
|
||||
@@ -76,19 +80,19 @@ namespace Sernatur {
|
||||
/**
|
||||
* This signal is called when a vehicle is assigned
|
||||
*/
|
||||
public signal void save_vehicle (Vehiculo vehicle);
|
||||
public signal void save_vehicle (RequerirAuto? requerir_auto);
|
||||
|
||||
/**
|
||||
* Validate the car data before trying to insert it into the database
|
||||
* Validate the vehicle data before trying to insert it into the database
|
||||
* @return Returns true if the data is valid
|
||||
*/
|
||||
private bool validate_car_data () {
|
||||
/*if (tour.nombre_tour.strip () == "") {
|
||||
private bool validate_vehicle_data () {
|
||||
if (require_vehicle.chofer.strip () == "") {
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: Tour name cannot be left blank!"));
|
||||
_ ("Error: The chofer's name cannot be left blank!"));
|
||||
msg.response.connect ((response_id) => {
|
||||
msg.destroy ();
|
||||
});
|
||||
@@ -96,34 +100,6 @@ namespace Sernatur {
|
||||
msg.run ();
|
||||
return false;
|
||||
}
|
||||
bool list_success = true;
|
||||
try {
|
||||
List<Tour> list = Tour.get_all_tours (conn);
|
||||
list.foreach ((entry) => {
|
||||
if (tour.nombre_tour.down () == entry.nombre_tour.down () && tour.id_tour != entry.id_tour) {
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: A tour named \"%s\" already exists!"), entry.nombre_tour);
|
||||
msg.response.connect ((response_id) => {
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.set_title (_ ("Error"));
|
||||
msg.run ();
|
||||
list_success = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
return list_success;*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -140,9 +116,10 @@ namespace Sernatur {
|
||||
Vehiculo temp_vehicle;
|
||||
vehicle_list_store.get (iter,
|
||||
Column.VEHICLE, out temp_vehicle);
|
||||
chofer.sensitive = true;
|
||||
}
|
||||
else {
|
||||
// Unassigned
|
||||
chofer.sensitive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,26 +131,21 @@ namespace Sernatur {
|
||||
[GtkCallback]
|
||||
public void on_clicked_button (Gtk.Button button) {
|
||||
if (button == save) {
|
||||
/*if (update_tour_instance () && validate_tour_data ()) {
|
||||
if (tour.id_tour == 0) {
|
||||
if (update_vehicle_instance ()) {
|
||||
if (require_vehicle.tour.id_tour != 0) {
|
||||
try {
|
||||
Tour.insert_tour (conn, tour);
|
||||
if (list_asociado != null) {
|
||||
// Insert all the pending associations
|
||||
list_asociado.foreach ((entry) => {
|
||||
try {
|
||||
Asociado.insert_asociado (conn, entry);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
if (require_vehicle.chofer.strip () == "") {
|
||||
RequerirAuto.delete_require_vehicle (conn, tour);
|
||||
}
|
||||
save_tour (); // Signal the parent to update itself
|
||||
else {
|
||||
if (RequerirAuto.get_requerir_auto_by_tour (conn, require_vehicle.tour) == null) {
|
||||
RequerirAuto.insert_require_vehicle (conn, require_vehicle);
|
||||
}
|
||||
else {
|
||||
RequerirAuto.update_require_vehicle (conn, require_vehicle);
|
||||
}
|
||||
}
|
||||
save_vehicle (null); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
catch (Error e) {
|
||||
@@ -185,22 +157,11 @@ namespace Sernatur {
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Tour.update_tour (conn, tour);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
finally {
|
||||
save_tour (); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
// Send it to the parent, only insert tuple if tour gets created
|
||||
save_vehicle (require_vehicle); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
else if (button == cancel) {
|
||||
this.close ();
|
||||
@@ -209,44 +170,25 @@ namespace Sernatur {
|
||||
|
||||
/**
|
||||
* Update the the vehicle object with new info from the editor
|
||||
* @return Returns false if the data is invalid
|
||||
*/
|
||||
private bool update_vehicle_instance () {
|
||||
/*tour.nombre_tour = tour_name.get_text ().strip ();
|
||||
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 ();
|
||||
if (region.get_active () == -1) {
|
||||
Region new_region = new Region (0, region.get_active_text ().strip ());
|
||||
try {
|
||||
if (validate_region_data (new_region)) {
|
||||
new_region.id_region = Region.insert_region (conn, new_region);
|
||||
return update_tour_instance_city (new_region);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
if (vehicle.get_active () > 0) {
|
||||
require_vehicle.chofer = chofer.get_text ().strip ();
|
||||
Vehiculo new_vehicle;
|
||||
Gtk.TreeIter iter;
|
||||
vehicle.get_active_iter (out iter);
|
||||
vehicle_list_store.get (iter,
|
||||
Column.VEHICLE, out new_vehicle);
|
||||
if (!validate_vehicle_data ()) {
|
||||
return false;
|
||||
}
|
||||
require_vehicle.vehiculo = new_vehicle;
|
||||
}
|
||||
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 ();
|
||||
}
|
||||
return update_tour_instance_city (new_region);
|
||||
}*/
|
||||
require_vehicle.vehiculo = new Vehiculo ();
|
||||
require_vehicle.chofer = "";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -268,6 +210,10 @@ namespace Sernatur {
|
||||
public void initialize () {
|
||||
try {
|
||||
vehicles = Vehiculo.get_all_vehiculos (conn);
|
||||
require_vehicle = RequerirAuto.get_requerir_auto_by_tour (conn, tour);
|
||||
if (require_vehicle == null) {
|
||||
require_vehicle = new RequerirAuto ("", tour, new Vehiculo ());
|
||||
}
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
@@ -278,7 +224,15 @@ namespace Sernatur {
|
||||
}
|
||||
|
||||
vehicles.sort_with_data ((a, b) => {
|
||||
return strcmp (a.patente, b.patente);
|
||||
if (a.capacidad < b.capacidad) {
|
||||
return -1;
|
||||
}
|
||||
else if (a.capacidad == b.capacidad) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
vehicle_list_store = new Gtk.ListStore (Column.N_COLUMNS,
|
||||
@@ -298,9 +252,11 @@ namespace Sernatur {
|
||||
vehicle_list_store.set (iter,
|
||||
Column.VEHICLE_DETAILS, entry.patente + " " + entry.marca + " " + entry.ano_vehiculo.to_string () + " " + entry.capacidad.to_string (),
|
||||
Column.VEHICLE, entry);
|
||||
/*if (entry.patente == assigned_vehicle.patente) {
|
||||
if (require_vehicle.vehiculo.patente.strip () != "" && entry.patente == require_vehicle.vehiculo.patente) {
|
||||
vehicle.set_active_iter (iter);
|
||||
}*/
|
||||
chofer.set_text (require_vehicle.chofer);
|
||||
chofer.sensitive = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -140,7 +140,7 @@ namespace Sernatur {
|
||||
/**
|
||||
* The vehicle to be inserted if the new tour is saved
|
||||
*/
|
||||
private Vehiculo vehiculo = null;
|
||||
private RequerirAuto requerir_auto = null;
|
||||
/**
|
||||
* This signal is called when a tour is saved
|
||||
*/
|
||||
@@ -386,6 +386,18 @@ namespace Sernatur {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (requerir_auto != null) {
|
||||
try {
|
||||
RequerirAuto.insert_require_vehicle (conn, requerir_auto);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
save_tour (); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
@@ -447,14 +459,18 @@ namespace Sernatur {
|
||||
/**
|
||||
* Called when a vehcile is assigned to the tour, and the tour is not in the database yet
|
||||
* @param tour_assign_vehicle The TourAssignVehicle instance that called this signal
|
||||
* @param vehicle The vehicle to assign to this tour
|
||||
* @param requerir_auto The vehicle to assign to this tour
|
||||
*/
|
||||
private void on_save_vehicle (TourAssignVehicle tour_assign_vehicle, Vehiculo vehiculo) {
|
||||
this.vehiculo = vehiculo;
|
||||
private void on_save_vehicle (TourAssignVehicle tour_assign_vehicle, RequerirAuto? requerir_auto) {
|
||||
if (requerir_auto != null) {
|
||||
this.requerir_auto = requerir_auto;
|
||||
vehicle.sensitive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the the tour object with new info from the editor
|
||||
* @return Returns false if the information is not valid
|
||||
*/
|
||||
private bool update_tour_instance () {
|
||||
tour.nombre_tour = tour_name.get_text ().strip ();
|
||||
@@ -499,6 +515,7 @@ namespace Sernatur {
|
||||
/**
|
||||
* This method updates the city part of the tour instance
|
||||
* @param new_region The region to insert into the city object
|
||||
* @return Returns false if the information is not valid
|
||||
*/
|
||||
private bool update_tour_instance_city (Region new_region) {
|
||||
Ciudad ciudad;
|
||||
|
Reference in New Issue
Block a user