persona.form \
persona_recapito.form \
persona_ufficio.form \
+ persona_ufficio_recapito.form \
struttura.form \
struttura_indirizzo.form \
tipo_nodo.form \
--- /dev/null
+<?xml version="1.0"?>
+<gtkform>
+
+ <table>persona_ufficio_recapiti</table>
+
+ <widget type="label" name="label96">
+ <field type="integer" name="id">
+ <is-key>t</is-key>
+ <auto-increment>t</auto-increment>
+ </field>
+ </widget>
+
+ <widget type="label" name="label100">
+ <field type="integer" name="id_persone">
+ </field>
+ </widget>
+
+ <widget type="label" name="label97">
+ <field type="integer" name="id_uffici">
+ </field>
+ </widget>
+
+ <widget type="combobox" name="combobox5" label="label95">
+ <column-field>0</column-field>
+ <sql with-empty-entry="t">
+ SELECT id, nome FROM tipi_recapito WHERE status <> 'E' ORDER BY nome
+ </sql>
+ <field type="integer" name="id_tipi_recapito">
+ </field>
+ </widget>
+
+ <widget type="entry" name="entry24" label="label98">
+ <field type="text" name="recapito">
+ </field>
+ </widget>
+
+ <widget type="textview" name="textview10" label="label94">
+ <field type="text" name="note" />
+ </widget>
+
+ <widget type="checkbox" name="checkbutton9" label="label99">
+ <field type="boolean" name="privato">
+ </field>
+ </widget>
+
+</gtkform>
</child>
<child>
<object class="GtkLabel" id="label100">
- <property name="label" translatable="yes">lbl_id_persona</property>
+ <property name="label" translatable="yes">lbl_id_persone</property>
</object>
<packing>
<property name="top_attach">5</property>
-- Dumped from database version 8.4.4
-- Dumped by pg_dump version 9.0.0
--- Started on 2010-10-13 12:04:21
+-- Started on 2010-10-13 13:00:49
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET escape_string_warning = off;
--
--- TOC entry 341 (class 2612 OID 16386)
+-- TOC entry 344 (class 2612 OID 16386)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: -
--
SET default_with_oids = false;
--
--- TOC entry 1528 (class 1259 OID 59279)
--- Dependencies: 1820 1821 1822 3
+-- TOC entry 1531 (class 1259 OID 59279)
+-- Dependencies: 1824 1825 1826 3
-- Name: nodi; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1542 (class 1259 OID 61266)
--- Dependencies: 1857 1858 1859 1860 1861 1862 3
+-- TOC entry 1545 (class 1259 OID 61266)
+-- Dependencies: 1861 1862 1863 1864 1865 1866 3
-- Name: persona_recapiti; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1541 (class 1259 OID 61243)
--- Dependencies: 1855 1856 3
+-- TOC entry 1544 (class 1259 OID 61243)
+-- Dependencies: 1859 1860 3
-- Name: persona_uffici; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1539 (class 1259 OID 61227)
--- Dependencies: 1849 1850 1851 1852 3
+-- TOC entry 1546 (class 1259 OID 61280)
+-- Dependencies: 1867 1868 1869 1870 1871 1872 1873 3
+-- Name: persona_ufficio_recapiti; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE persona_ufficio_recapiti (
+ id integer NOT NULL,
+ id_persone integer DEFAULT 0,
+ id_uffici integer DEFAULT 0,
+ id_tipi_recapito integer DEFAULT 0,
+ recapito character varying(100) DEFAULT ''::character varying,
+ note text DEFAULT ''::text,
+ privato boolean DEFAULT false,
+ status character varying(1) DEFAULT ''::character varying
+);
+
+
+--
+-- TOC entry 1542 (class 1259 OID 61227)
+-- Dependencies: 1853 1854 1855 1856 3
-- Name: persone; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1534 (class 1259 OID 59346)
--- Dependencies: 1836 1837 1838 3
+-- TOC entry 1537 (class 1259 OID 59346)
+-- Dependencies: 1840 1841 1842 3
-- Name: struttura_indirizzi; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1532 (class 1259 OID 59327)
--- Dependencies: 1830 1831 1832 1833 1834 3
+-- TOC entry 1535 (class 1259 OID 59327)
+-- Dependencies: 1834 1835 1836 1837 1838 3
-- Name: strutture; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1529 (class 1259 OID 59290)
--- Dependencies: 1823 1824 3
+-- TOC entry 1532 (class 1259 OID 59290)
+-- Dependencies: 1827 1828 3
-- Name: tipi_nodo; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1540 (class 1259 OID 61236)
--- Dependencies: 1853 1854 3
+-- TOC entry 1543 (class 1259 OID 61236)
+-- Dependencies: 1857 1858 3
-- Name: tipi_rapporto_lavoro; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1530 (class 1259 OID 59297)
--- Dependencies: 1825 1826 3
+-- TOC entry 1533 (class 1259 OID 59297)
+-- Dependencies: 1829 1830 3
-- Name: tipi_recapito; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1538 (class 1259 OID 61219)
--- Dependencies: 1846 1847 1848 3
+-- TOC entry 1541 (class 1259 OID 61219)
+-- Dependencies: 1850 1851 1852 3
-- Name: titoli; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1531 (class 1259 OID 59311)
--- Dependencies: 1827 1828 1829 3
+-- TOC entry 1534 (class 1259 OID 59311)
+-- Dependencies: 1831 1832 1833 3
-- Name: uffici; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1535 (class 1259 OID 59357)
--- Dependencies: 1839 1840 3
+-- TOC entry 1538 (class 1259 OID 59357)
+-- Dependencies: 1843 1844 3
-- Name: ufficio_nodi; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1536 (class 1259 OID 59399)
--- Dependencies: 1841 1842 3
+-- TOC entry 1539 (class 1259 OID 59399)
+-- Dependencies: 1845 1846 3
-- Name: ufficio_orari; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1537 (class 1259 OID 59409)
--- Dependencies: 1843 1844 1845 3
+-- TOC entry 1540 (class 1259 OID 59409)
+-- Dependencies: 1847 1848 1849 3
-- Name: ufficio_recapiti; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1533 (class 1259 OID 59340)
--- Dependencies: 1835 3
+-- TOC entry 1536 (class 1259 OID 59340)
+-- Dependencies: 1839 3
-- Name: vie; Type: TABLE; Schema: public; Owner: -
--
--
--- TOC entry 1864 (class 2606 OID 59289)
--- Dependencies: 1528 1528
+-- TOC entry 1875 (class 2606 OID 59289)
+-- Dependencies: 1531 1531
-- Name: nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1892 (class 2606 OID 61279)
--- Dependencies: 1542 1542
+-- TOC entry 1903 (class 2606 OID 61279)
+-- Dependencies: 1545 1545
-- Name: persona_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1890 (class 2606 OID 61252)
--- Dependencies: 1541 1541
+-- TOC entry 1901 (class 2606 OID 61252)
+-- Dependencies: 1544 1544
-- Name: persona_uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1886 (class 2606 OID 61235)
--- Dependencies: 1539 1539
+-- TOC entry 1905 (class 2606 OID 61294)
+-- Dependencies: 1546 1546
+-- Name: persona_ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY persona_ufficio_recapiti
+ ADD CONSTRAINT persona_ufficio_recapiti_pkey PRIMARY KEY (id);
+
+
+--
+-- TOC entry 1897 (class 2606 OID 61235)
+-- Dependencies: 1542 1542
-- Name: persone_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1876 (class 2606 OID 59356)
--- Dependencies: 1534 1534
+-- TOC entry 1887 (class 2606 OID 59356)
+-- Dependencies: 1537 1537
-- Name: struttura_indirizzi_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1872 (class 2606 OID 59339)
--- Dependencies: 1532 1532
+-- TOC entry 1883 (class 2606 OID 59339)
+-- Dependencies: 1535 1535
-- Name: strutture_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1866 (class 2606 OID 59296)
--- Dependencies: 1529 1529
+-- TOC entry 1877 (class 2606 OID 59296)
+-- Dependencies: 1532 1532
-- Name: tipi_nodo_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1888 (class 2606 OID 61242)
--- Dependencies: 1540 1540
+-- TOC entry 1899 (class 2606 OID 61242)
+-- Dependencies: 1543 1543
-- Name: tipi_rapporto_lavoro_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1868 (class 2606 OID 59303)
--- Dependencies: 1530 1530
+-- TOC entry 1879 (class 2606 OID 59303)
+-- Dependencies: 1533 1533
-- Name: tipi_recapito_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1884 (class 2606 OID 61226)
--- Dependencies: 1538 1538
+-- TOC entry 1895 (class 2606 OID 61226)
+-- Dependencies: 1541 1541
-- Name: titoli_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1870 (class 2606 OID 59321)
--- Dependencies: 1531 1531
+-- TOC entry 1881 (class 2606 OID 59321)
+-- Dependencies: 1534 1534
-- Name: uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1878 (class 2606 OID 59366)
--- Dependencies: 1535 1535
+-- TOC entry 1889 (class 2606 OID 59366)
+-- Dependencies: 1538 1538
-- Name: ufficio_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1880 (class 2606 OID 59408)
--- Dependencies: 1536 1536
+-- TOC entry 1891 (class 2606 OID 59408)
+-- Dependencies: 1539 1539
-- Name: ufficio_orari_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1882 (class 2606 OID 59419)
--- Dependencies: 1537 1537
+-- TOC entry 1893 (class 2606 OID 59419)
+-- Dependencies: 1540 1540
-- Name: ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
--
--- TOC entry 1874 (class 2606 OID 59345)
--- Dependencies: 1533 1533
+-- TOC entry 1885 (class 2606 OID 59345)
+-- Dependencies: 1536 1536
-- Name: vie_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ADD CONSTRAINT vie_pkey PRIMARY KEY (id);
--- Completed on 2010-10-13 12:04:21
+-- Completed on 2010-10-13 13:00:49
--
-- PostgreSQL database dump complete
personarecapito.h \
personaufficio.c \
personaufficio.h \
+ personaufficiorecapito.c \
+ personaufficiorecapito.h \
struttura.c \
struttura.h \
strutturaindirizzo.c \
#include "persona.h"
#include "personaufficio.h"
+#include "personaufficiorecapito.h"
#include "personarecapito.h"
static void persona_class_init (PersonaClass *klass);
static void persona_salva (Persona *persona);
static void persona_carica_uffici (Persona *persona);
+static void persona_carica_ufficio_recapiti (Persona *persona);
static void persona_carica_recapiti (Persona *persona);
static void persona_ufficio_modifica (Persona *persona);
+static void persona_ufficio_recapito_modifica (Persona *persona);
static void persona_recapito_modifica (Persona *persona);
static gboolean persona_conferma_chiusura (Persona *persona);
GParamSpec *pspec);
static void persona_on_ufficio_aggiornato (gpointer instance, gpointer user_data);
+static void persona_on_ufficio_recapito_aggiornato (gpointer instance, gpointer user_data);
static void persona_on_recapito_aggiornato (gpointer instance, gpointer user_data);
static gboolean persona_on_w_persona_delete_event (GtkWidget *widget,
GtkTreePath *tree_path,
GtkTreeViewColumn *column,
gpointer user_data);
+static void persona_on_uffici_sel_changed (GtkTreeSelection *selection,
+ gpointer user_data);
+
+static void persona_on_btn_ufficio_recapito_nuovo_clicked (GtkButton *button,
+ gpointer user_data);
+static void persona_on_btn_ufficio_recapito_modifica_clicked (GtkButton *button,
+ gpointer user_data);
+static void persona_on_btn_ufficio_recapito_elimina_clicked (GtkButton *button,
+ gpointer user_data);
+static void persona_on_trv_ufficio_recapiti_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *tree_path,
+ GtkTreeViewColumn *column,
+ gpointer user_data);
static void persona_on_btn_recapito_nuovo_clicked (GtkButton *button,
gpointer user_data);
{
LBL_ID,
LSTORE_UFFICI,
+ LSTORE_UFFICIO_RECAPITI,
LSTORE_RECAPITI
};
UFFICI_COL_UFFICIO
};
+enum
+{
+ UFFICIO_RECAPITI_COL_ID,
+ UFFICIO_RECAPITI_COL_TIPO,
+ UFFICIO_RECAPITI_COL_RECAPITO
+};
+
enum
{
RECAPITI_COL_ID,
GObject **objects;
GtkTreeSelection *sel_uffici;
+ GtkTreeSelection *sel_ufficio_recapiti;
GtkTreeSelection *sel_recapiti;
gint id;
g_strsplit (g_strconcat (
"lstore_titoli"
"|lstore_persona_uffici"
+ "|lstore_persona_ufficio_recapiti"
"|lstore_persona_recapiti"
"|w_persona", NULL), "|", -1),
&error);
priv->objects = gtk_form_get_objects_by_name (priv->form,
"label67",
"lstore_persona_uffici",
+ "lstore_persona_ufficio_recapiti",
"lstore_persona_recapiti",
NULL);
"delete-event", G_CALLBACK (persona_on_w_persona_delete_event), (gpointer *)a);
priv->sel_uffici = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview11")));
+ priv->sel_ufficio_recapiti = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview12")));
priv->sel_recapiti = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview15")));
+ g_signal_connect (priv->sel_uffici,
+ "changed", G_CALLBACK (persona_on_uffici_sel_changed), (gpointer)a);
+
g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button62")),
"clicked", G_CALLBACK (persona_on_btn_ufficio_nuovo_clicked), (gpointer *)a);
g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button63")),
g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview11")),
"row-activated", G_CALLBACK (persona_on_trv_uffici_row_activated), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button67")),
+ "clicked", G_CALLBACK (persona_on_btn_ufficio_recapito_nuovo_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button68")),
+ "clicked", G_CALLBACK (persona_on_btn_ufficio_recapito_modifica_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button69")),
+ "clicked", G_CALLBACK (persona_on_btn_ufficio_recapito_elimina_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview12")),
+ "row-activated", G_CALLBACK (persona_on_trv_ufficio_recapiti_row_activated), (gpointer *)a);
+
g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button76")),
"clicked", G_CALLBACK (persona_on_btn_recapito_nuovo_clicked), (gpointer *)a);
g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button77")),
if (gtk_form_fill_from_table (priv->form))
{
persona_carica_uffici (persona);
+ persona_carica_ufficio_recapiti (persona);
persona_carica_recapiti (persona);
}
}
g_free (sql);
}
+static void
+persona_carica_ufficio_recapiti (Persona *persona)
+{
+ gchar *sql;
+ GdaDataModel *dm;
+ guint row;
+ guint rows;
+
+ GtkTreeIter iter;
+ guint id_uffici;
+
+ PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+ gtk_list_store_clear (GTK_LIST_STORE (priv->objects[LSTORE_UFFICIO_RECAPITI]));
+
+ if (gtk_tree_selection_get_selected (priv->sel_uffici, NULL, &iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICI]), &iter,
+ UFFICI_COL_ID, &id_uffici,
+ -1);
+ }
+
+ sql = g_strdup_printf ("SELECT pur.id, tr.nome, pur.recapito"
+ " FROM persona_ufficio_recapiti AS pur INNER JOIN tipi_recapito AS tr ON"
+ " pur.id_tipi_recapito = tr.id"
+ " WHERE pur.id_persone = %d"
+ " AND pur.id_uffici = %d"
+ " AND pur.status <> 'E'"
+ " ORDER BY tr.nome, pur.recapito",
+ priv->id,
+ id_uffici);
+ dm = gdaex_query (priv->commons->gdaex, sql);
+ if (dm != NULL)
+ {
+ GtkTreeIter iter;
+
+ rows = gda_data_model_get_n_rows (dm);
+ for (row = 0; row < rows; row++)
+ {
+ gtk_list_store_append (GTK_LIST_STORE (priv->objects[LSTORE_UFFICIO_RECAPITI]), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (priv->objects[LSTORE_UFFICIO_RECAPITI]), &iter,
+ UFFICIO_RECAPITI_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
+ UFFICIO_RECAPITI_COL_TIPO, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
+ UFFICIO_RECAPITI_COL_RECAPITO, gdaex_data_model_get_field_value_stringify_at (dm, row, "recapito"),
+ -1);
+ }
+
+ g_object_unref (dm);
+ }
+ g_free (sql);
+}
+
static void
persona_carica_recapiti (Persona *persona)
{
}
}
+static void
+persona_ufficio_recapito_modifica (Persona *persona)
+{
+ GtkTreeIter iter;
+ GtkWidget *dialog;
+
+ PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+ guint id_uffici;
+ if (gtk_tree_selection_get_selected (priv->sel_uffici, NULL, &iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICI]), &iter,
+ UFFICI_COL_ID, &id_uffici,
+ -1);
+ }
+
+ if (id_uffici == 0)
+ {
+ GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un ufficio");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ if (gtk_tree_selection_get_selected (priv->sel_ufficio_recapiti, NULL, &iter))
+ {
+ guint id;
+ GtkWidget *w;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICIO_RECAPITI]), &iter,
+ UFFICIO_RECAPITI_COL_ID, &id,
+ -1);
+
+ PersonaUfficioRecapito *a = persona_ufficio_recapito_new (priv->commons, id, 0, 0);
+
+ g_signal_connect (G_OBJECT (a), "aggiornato",
+ G_CALLBACK (persona_on_ufficio_recapito_aggiornato), (gpointer)persona);
+
+ w = persona_ufficio_recapito_get_widget (a);
+ gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+ gtk_widget_show (w);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un recapito.");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
static void
persona_recapito_modifica (Persona *persona)
{
persona_carica_uffici (persona);
}
+static void
+persona_on_ufficio_recapito_aggiornato (gpointer instance, gpointer user_data)
+{
+ Persona *persona = (Persona *)user_data;
+ PersonaClass *klass = PERSONA_GET_CLASS (persona);
+
+ persona_carica_ufficio_recapiti (persona);
+}
+
static void
persona_on_recapito_aggiornato (gpointer instance, gpointer user_data)
{
persona_ufficio_modifica ((Persona *)user_data);
}
+static void
+persona_on_uffici_sel_changed (GtkTreeSelection *selection,
+ gpointer user_data)
+{
+ persona_carica_ufficio_recapiti ((Persona *)user_data);
+}
+
+static void
+persona_on_btn_ufficio_recapito_nuovo_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkWidget *w;
+ GtkTreeIter iter;
+
+ Persona *persona = (Persona *)user_data;
+
+ PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+ guint id_uffici;
+ if (gtk_tree_selection_get_selected (priv->sel_uffici, NULL, &iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICI]), &iter,
+ UFFICI_COL_ID, &id_uffici,
+ -1);
+ }
+
+ if (id_uffici == 0)
+ {
+ GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un ufficio");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ PersonaUfficioRecapito *a = persona_ufficio_recapito_new (priv->commons, 0, priv->id, id_uffici);
+
+ g_signal_connect (G_OBJECT (a), "aggiornato",
+ G_CALLBACK (persona_on_ufficio_recapito_aggiornato), (gpointer)persona);
+
+ w = persona_ufficio_recapito_get_widget (a);
+ gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+ gtk_widget_show (w);
+}
+
+static void
+persona_on_btn_ufficio_recapito_modifica_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ persona_ufficio_recapito_modifica ((Persona *)user_data);
+}
+
+static void
+persona_on_btn_ufficio_recapito_elimina_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkWidget *dialog;
+ guint risp;
+ guint id_uffici;
+
+ Persona *persona = (Persona *)user_data;
+
+ PersonaClass *klass = PERSONA_GET_CLASS (persona);
+ PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+ if (gtk_tree_selection_get_selected (priv->sel_uffici, NULL, &iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICI]), &iter,
+ UFFICI_COL_ID, &id_uffici,
+ -1);
+ }
+
+ if (id_uffici == 0)
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un ufficio");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ if (gtk_tree_selection_get_selected (priv->sel_ufficio_recapiti, NULL, &iter))
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ "Sicuro di voler eliminare il recapito selezionato?");
+ risp = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (risp == GTK_RESPONSE_YES)
+ {
+ guint id;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICIO_RECAPITI]), &iter,
+ UFFICIO_RECAPITI_COL_ID, &id,
+ -1);
+
+ gdaex_execute (priv->commons->gdaex,
+ g_strdup_printf ("UPDATE persona_ufficio_recapiti"
+ " SET status = 'E'"
+ " WHERE id = %d",
+ id));
+
+ persona_carica_ufficio_recapiti (persona);
+ }
+ gtk_widget_destroy (dialog);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un recapito");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+persona_on_trv_ufficio_recapiti_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *tree_path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
+{
+ persona_ufficio_recapito_modifica ((Persona *)user_data);
+}
+
static void
persona_on_btn_recapito_nuovo_clicked (GtkButton *button,
gpointer user_data)
--- /dev/null
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <libgtkform/form.h>
+
+#include "personaufficiorecapito.h"
+
+static void persona_ufficio_recapito_class_init (PersonaUfficioRecapitoClass *klass);
+static void persona_ufficio_recapito_init (PersonaUfficioRecapito *persona_ufficio_recapito);
+
+static void persona_ufficio_recapito_carica (PersonaUfficioRecapito *persona_ufficio_recapito);
+static void persona_ufficio_recapito_salva (PersonaUfficioRecapito *persona_ufficio_recapito);
+
+static gboolean persona_ufficio_recapito_conferma_chiusura (PersonaUfficioRecapito *persona_ufficio_recapito);
+
+static void persona_ufficio_recapito_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void persona_ufficio_recapito_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static gboolean persona_ufficio_recapito_on_w_persona_ufficio_recapito_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data);
+
+static void persona_ufficio_recapito_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data);
+static void persona_ufficio_recapito_on_btn_salva_clicked (GtkButton *button,
+ gpointer user_data);
+
+
+#define PERSONA_UFFICIO_RECAPITO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PERSONA_UFFICIO_RECAPITO, PersonaUfficioRecapitoPrivate))
+
+enum
+{
+ LBL_ID,
+ LBL_ID_PERSONE,
+ LBL_ID_UFFICI
+};
+
+typedef struct _PersonaUfficioRecapitoPrivate PersonaUfficioRecapitoPrivate;
+struct _PersonaUfficioRecapitoPrivate
+ {
+ Commons *commons;
+
+ GtkForm *form;
+
+ GtkWidget *w;
+
+ GObject **objects;
+
+ guint id;
+ };
+
+G_DEFINE_TYPE (PersonaUfficioRecapito, persona_ufficio_recapito, G_TYPE_OBJECT)
+
+static void
+persona_ufficio_recapito_class_init (PersonaUfficioRecapitoClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (PersonaUfficioRecapitoPrivate));
+
+ object_class->set_property = persona_ufficio_recapito_set_property;
+ object_class->get_property = persona_ufficio_recapito_get_property;
+
+ /**
+ * PersonaUfficioRecapito::aggiornato:
+ * @persona_ufficio_recapito:
+ *
+ */
+ klass->aggiornato_signal_id = g_signal_new ("aggiornato",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+}
+
+static void
+persona_ufficio_recapito_init (PersonaUfficioRecapito *persona_ufficio_recapito)
+{
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+}
+
+/**
+ * persona_ufficio_recapito_new:
+ * @commons:
+ * @id:
+ * @id_persone:
+ * @id_uffici:
+ *
+ * Returns: the newly created #PersonaUfficioRecapito object.
+ */
+PersonaUfficioRecapito
+*persona_ufficio_recapito_new (Commons *commons, guint id, guint id_persone, guint id_uffici)
+{
+ GError *error;
+
+ PersonaUfficioRecapito *a = PERSONA_UFFICIO_RECAPITO (g_object_new (persona_ufficio_recapito_get_type (), NULL));
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (a);
+
+ priv->commons = commons;
+
+ error = NULL;
+
+ gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+ g_strsplit ("lstore_tipi_recapito|w_persona_ufficio_recapito", "|", -1),
+ &error);
+ if (error != NULL)
+ {
+ g_fprintf (stderr, "Errore: %s\n", error->message);
+ return NULL;
+ }
+
+ priv->form = gtk_form_new ();
+ g_object_set (G_OBJECT (priv->form), "gdaex", priv->commons->gdaex, NULL);
+ gtk_form_load_from_file (priv->form, g_build_filename (priv->commons->formdir, "persona_ufficio_recapito.form", NULL), priv->commons->gtkbuilder);
+
+ priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_ufficio_recapito"));
+
+ priv->objects = gtk_form_get_objects_by_name (priv->form,
+ "label96",
+ "label100",
+ "label97",
+ NULL);
+
+ g_signal_connect (priv->w,
+ "delete-event", G_CALLBACK (persona_ufficio_recapito_on_w_persona_ufficio_recapito_delete_event), (gpointer *)a);
+
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button85")),
+ "clicked", G_CALLBACK (persona_ufficio_recapito_on_btn_annulla_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button86")),
+ "clicked", G_CALLBACK (persona_ufficio_recapito_on_btn_salva_clicked), (gpointer *)a);
+
+ priv->id = id;
+ if (priv->id == 0)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
+ gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID_PERSONE]), g_strdup_printf ("%d", id_persone));
+ gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID_UFFICI]), g_strdup_printf ("%d", id_uffici));
+
+ gtk_form_set_as_origin (priv->form);
+ }
+ else
+ {
+ gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", priv->id));
+
+ persona_ufficio_recapito_carica (a);
+ }
+
+ return a;
+}
+
+/**
+ * persona_ufficio_recapito_get_widget:
+ * @persona_ufficio_recapito:
+ *
+ */
+GtkWidget
+*persona_ufficio_recapito_get_widget (PersonaUfficioRecapito *persona_ufficio_recapito)
+{
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ return priv->w;
+}
+
+/* PRIVATE */
+static void
+persona_ufficio_recapito_carica (PersonaUfficioRecapito *persona_ufficio_recapito)
+{
+ gchar *sql;
+ GdaDataModel *dm;
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ if (gtk_form_fill_from_table (priv->form))
+ {
+ }
+}
+
+static void
+persona_ufficio_recapito_salva (PersonaUfficioRecapito *persona_ufficio_recapito)
+{
+ gchar *sql;
+ GtkWidget *dialog;
+
+ PersonaUfficioRecapitoClass *klass = PERSONA_UFFICIO_RECAPITO_GET_CLASS (persona_ufficio_recapito);
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ if (!gtk_form_check (priv->form, FALSE, NULL, TRUE, priv->w, TRUE))
+ {
+ return;
+ }
+
+ if (priv->id == 0)
+ {
+ sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
+ }
+ else
+ {
+ sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
+ }
+
+ if (gdaex_execute (priv->commons->gdaex, sql) == 1)
+ {
+ g_signal_emit (persona_ufficio_recapito, klass->aggiornato_signal_id, 0);
+
+ if (priv->id == 0)
+ {
+ priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
+ }
+
+ gtk_form_set_as_origin (priv->form);
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ "Salvataggio eseguito con successo.");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Errore durante il salvataggio.");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+persona_ufficio_recapito_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ PersonaUfficioRecapito *persona_ufficio_recapito = PERSONA_UFFICIO_RECAPITO (object);
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+persona_ufficio_recapito_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ PersonaUfficioRecapito *persona_ufficio_recapito = PERSONA_UFFICIO_RECAPITO (object);
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static gboolean
+persona_ufficio_recapito_conferma_chiusura (PersonaUfficioRecapito *persona_ufficio_recapito)
+{
+ GtkWidget *dialog;
+
+ gboolean ret;
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ ret = TRUE;
+
+ if (gtk_form_is_changed (priv->form))
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ "Sicuro di voler chiudere senza salvare?");
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_NO)
+ {
+ ret = FALSE;
+ }
+ gtk_widget_destroy (dialog);
+ }
+
+ return ret;
+}
+
+/* CALLBACK */
+static gboolean
+persona_ufficio_recapito_on_w_persona_ufficio_recapito_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ return !persona_ufficio_recapito_conferma_chiusura ((PersonaUfficioRecapito *)user_data);
+}
+
+static void
+persona_ufficio_recapito_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ PersonaUfficioRecapito *persona_ufficio_recapito = (PersonaUfficioRecapito *)user_data;
+
+ PersonaUfficioRecapitoPrivate *priv = PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (persona_ufficio_recapito);
+
+ if (persona_ufficio_recapito_conferma_chiusura (persona_ufficio_recapito)) gtk_widget_destroy (priv->w);
+}
+
+static void
+persona_ufficio_recapito_on_btn_salva_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ persona_ufficio_recapito_salva ((PersonaUfficioRecapito *)user_data);
+}
--- /dev/null
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __PERSONA_UFFICIO_RECAPITO_H__
+#define __PERSONA_UFFICIO_RECAPITO_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_PERSONA_UFFICIO_RECAPITO (persona_ufficio_recapito_get_type ())
+#define PERSONA_UFFICIO_RECAPITO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PERSONA_UFFICIO_RECAPITO, PersonaUfficioRecapito))
+#define PERSONA_UFFICIO_RECAPITO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PERSONA_UFFICIO_RECAPITO, PersonaUfficioRecapitoClass))
+#define IS_PERSONA_UFFICIO_RECAPITO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PERSONA_UFFICIO_RECAPITO))
+#define IS_PERSONA_UFFICIO_RECAPITO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PERSONA_UFFICIO_RECAPITO))
+#define PERSONA_UFFICIO_RECAPITO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PERSONA_UFFICIO_RECAPITO, PersonaUfficioRecapitoClass))
+
+
+typedef struct _PersonaUfficioRecapito PersonaUfficioRecapito;
+typedef struct _PersonaUfficioRecapitoClass PersonaUfficioRecapitoClass;
+
+struct _PersonaUfficioRecapito
+ {
+ GObject parent;
+ };
+
+struct _PersonaUfficioRecapitoClass
+ {
+ GObjectClass parent_class;
+
+ guint aggiornato_signal_id;
+ };
+
+GType persona_ufficio_recapito_get_type (void) G_GNUC_CONST;
+
+PersonaUfficioRecapito *persona_ufficio_recapito_new (Commons *commons, guint id, guint id_persone, guint id_uffici);
+
+GtkWidget *persona_ufficio_recapito_get_widget (PersonaUfficioRecapito *persona_ufficio_recapito);
+
+
+G_END_DECLS
+
+#endif /* __PERSONA_UFFICIO_RECAPITO_H__ */