From d3a7e32108547f7d7bb2f8c0f4b01d31b26d9863 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 14 Oct 2010 11:59:01 +0200 Subject: [PATCH] Gestione nodi della persona. --- data/organigramma/form/Makefile.am | 1 + data/organigramma/form/persona_nodo.form | 54 ++++ data/organigramma/gui/organigramma.gui | 6 +- docs/organigramma.sql | 161 ++++++---- src/Makefile.am | 2 + src/persona.c | 225 ++++++++++++- src/personanodo.c | 383 +++++++++++++++++++++++ src/personanodo.h | 65 ++++ 8 files changed, 825 insertions(+), 72 deletions(-) create mode 100644 data/organigramma/form/persona_nodo.form create mode 100644 src/personanodo.c create mode 100644 src/personanodo.h diff --git a/data/organigramma/form/Makefile.am b/data/organigramma/form/Makefile.am index 5df5284..f3a4a7d 100644 --- a/data/organigramma/form/Makefile.am +++ b/data/organigramma/form/Makefile.am @@ -3,6 +3,7 @@ formdir = $(datadir)/$(PACKAGE)/form form_DATA = \ nodo.form \ persona.form \ + persona_nodo.form \ persona_recapito.form \ persona_ufficio.form \ persona_ufficio_recapito.form \ diff --git a/data/organigramma/form/persona_nodo.form b/data/organigramma/form/persona_nodo.form new file mode 100644 index 0000000..94cba91 --- /dev/null +++ b/data/organigramma/form/persona_nodo.form @@ -0,0 +1,54 @@ + + + + persona_nodi
+ + + + t + t + + + + + + + + + + + f + f + + + + + + entry30 + + SELECT nome FROM nodi WHERE id = ##label115::gint + + + + + + + + + date + %d/%m/%Y + + + + + + date + %d/%m/%Y + + + + + + + +
diff --git a/data/organigramma/gui/organigramma.gui b/data/organigramma/gui/organigramma.gui index 8072204..aab80aa 100644 --- a/data/organigramma/gui/organigramma.gui +++ b/data/organigramma/gui/organigramma.gui @@ -5724,7 +5724,7 @@ True 0 - Nodo superiore + Nodo GTK_FILL @@ -5788,7 +5788,7 @@ - lbl_id_persona + lbl_id_persone 1 @@ -6064,7 +6064,7 @@ - lbl_id_persona + lbl_id_persone 5 diff --git a/docs/organigramma.sql b/docs/organigramma.sql index be8e05d..7dda33b 100644 --- a/docs/organigramma.sql +++ b/docs/organigramma.sql @@ -4,7 +4,7 @@ -- Dumped from database version 8.4.4 -- Dumped by pg_dump version 9.0.0 --- Started on 2010-10-13 13:00:49 +-- Started on 2010-10-14 11:26:02 SET statement_timeout = 0; SET client_encoding = 'UTF8'; @@ -14,7 +14,7 @@ SET client_min_messages = warning; SET escape_string_warning = off; -- --- TOC entry 344 (class 2612 OID 16386) +-- TOC entry 347 (class 2612 OID 16386) -- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: - -- @@ -26,8 +26,8 @@ SET search_path = public, pg_catalog; SET default_with_oids = false; -- --- TOC entry 1531 (class 1259 OID 59279) --- Dependencies: 1824 1825 1826 3 +-- TOC entry 1534 (class 1259 OID 59279) +-- Dependencies: 1828 1829 1830 3 -- Name: nodi; Type: TABLE; Schema: public; Owner: - -- @@ -42,8 +42,25 @@ CREATE TABLE nodi ( -- --- TOC entry 1545 (class 1259 OID 61266) --- Dependencies: 1861 1862 1863 1864 1865 1866 3 +-- TOC entry 1550 (class 1259 OID 61295) +-- Dependencies: 1878 1879 1880 1881 3 +-- Name: persona_nodi; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE persona_nodi ( + id integer NOT NULL, + id_persone integer DEFAULT 0, + id_nodi integer DEFAULT 0, + da_data date, + a_data date, + note text DEFAULT ''::text, + status character varying(1) DEFAULT ''::character varying +); + + +-- +-- TOC entry 1548 (class 1259 OID 61266) +-- Dependencies: 1865 1866 1867 1868 1869 1870 3 -- Name: persona_recapiti; Type: TABLE; Schema: public; Owner: - -- @@ -59,8 +76,8 @@ CREATE TABLE persona_recapiti ( -- --- TOC entry 1544 (class 1259 OID 61243) --- Dependencies: 1859 1860 3 +-- TOC entry 1547 (class 1259 OID 61243) +-- Dependencies: 1863 1864 3 -- Name: persona_uffici; Type: TABLE; Schema: public; Owner: - -- @@ -76,8 +93,8 @@ CREATE TABLE persona_uffici ( -- --- TOC entry 1546 (class 1259 OID 61280) --- Dependencies: 1867 1868 1869 1870 1871 1872 1873 3 +-- TOC entry 1549 (class 1259 OID 61280) +-- Dependencies: 1871 1872 1873 1874 1875 1876 1877 3 -- Name: persona_ufficio_recapiti; Type: TABLE; Schema: public; Owner: - -- @@ -94,8 +111,8 @@ CREATE TABLE persona_ufficio_recapiti ( -- --- TOC entry 1542 (class 1259 OID 61227) --- Dependencies: 1853 1854 1855 1856 3 +-- TOC entry 1545 (class 1259 OID 61227) +-- Dependencies: 1857 1858 1859 1860 3 -- Name: persone; Type: TABLE; Schema: public; Owner: - -- @@ -110,8 +127,8 @@ CREATE TABLE persone ( -- --- TOC entry 1537 (class 1259 OID 59346) --- Dependencies: 1840 1841 1842 3 +-- TOC entry 1540 (class 1259 OID 59346) +-- Dependencies: 1844 1845 1846 3 -- Name: struttura_indirizzi; Type: TABLE; Schema: public; Owner: - -- @@ -126,8 +143,8 @@ CREATE TABLE struttura_indirizzi ( -- --- TOC entry 1535 (class 1259 OID 59327) --- Dependencies: 1834 1835 1836 1837 1838 3 +-- TOC entry 1538 (class 1259 OID 59327) +-- Dependencies: 1838 1839 1840 1841 1842 3 -- Name: strutture; Type: TABLE; Schema: public; Owner: - -- @@ -142,8 +159,8 @@ CREATE TABLE strutture ( -- --- TOC entry 1532 (class 1259 OID 59290) --- Dependencies: 1827 1828 3 +-- TOC entry 1535 (class 1259 OID 59290) +-- Dependencies: 1831 1832 3 -- Name: tipi_nodo; Type: TABLE; Schema: public; Owner: - -- @@ -155,8 +172,8 @@ CREATE TABLE tipi_nodo ( -- --- TOC entry 1543 (class 1259 OID 61236) --- Dependencies: 1857 1858 3 +-- TOC entry 1546 (class 1259 OID 61236) +-- Dependencies: 1861 1862 3 -- Name: tipi_rapporto_lavoro; Type: TABLE; Schema: public; Owner: - -- @@ -168,8 +185,8 @@ CREATE TABLE tipi_rapporto_lavoro ( -- --- TOC entry 1533 (class 1259 OID 59297) --- Dependencies: 1829 1830 3 +-- TOC entry 1536 (class 1259 OID 59297) +-- Dependencies: 1833 1834 3 -- Name: tipi_recapito; Type: TABLE; Schema: public; Owner: - -- @@ -181,8 +198,8 @@ CREATE TABLE tipi_recapito ( -- --- TOC entry 1541 (class 1259 OID 61219) --- Dependencies: 1850 1851 1852 3 +-- TOC entry 1544 (class 1259 OID 61219) +-- Dependencies: 1854 1855 1856 3 -- Name: titoli; Type: TABLE; Schema: public; Owner: - -- @@ -195,8 +212,8 @@ CREATE TABLE titoli ( -- --- TOC entry 1534 (class 1259 OID 59311) --- Dependencies: 1831 1832 1833 3 +-- TOC entry 1537 (class 1259 OID 59311) +-- Dependencies: 1835 1836 1837 3 -- Name: uffici; Type: TABLE; Schema: public; Owner: - -- @@ -210,8 +227,8 @@ CREATE TABLE uffici ( -- --- TOC entry 1538 (class 1259 OID 59357) --- Dependencies: 1843 1844 3 +-- TOC entry 1541 (class 1259 OID 59357) +-- Dependencies: 1847 1848 3 -- Name: ufficio_nodi; Type: TABLE; Schema: public; Owner: - -- @@ -225,8 +242,8 @@ CREATE TABLE ufficio_nodi ( -- --- TOC entry 1539 (class 1259 OID 59399) --- Dependencies: 1845 1846 3 +-- TOC entry 1542 (class 1259 OID 59399) +-- Dependencies: 1849 1850 3 -- Name: ufficio_orari; Type: TABLE; Schema: public; Owner: - -- @@ -253,8 +270,8 @@ CREATE TABLE ufficio_orari ( -- --- TOC entry 1540 (class 1259 OID 59409) --- Dependencies: 1847 1848 1849 3 +-- TOC entry 1543 (class 1259 OID 59409) +-- Dependencies: 1851 1852 1853 3 -- Name: ufficio_recapiti; Type: TABLE; Schema: public; Owner: - -- @@ -270,8 +287,8 @@ CREATE TABLE ufficio_recapiti ( -- --- TOC entry 1536 (class 1259 OID 59340) --- Dependencies: 1839 3 +-- TOC entry 1539 (class 1259 OID 59340) +-- Dependencies: 1843 3 -- Name: vie; Type: TABLE; Schema: public; Owner: - -- @@ -282,8 +299,8 @@ CREATE TABLE vie ( -- --- TOC entry 1875 (class 2606 OID 59289) --- Dependencies: 1531 1531 +-- TOC entry 1883 (class 2606 OID 59289) +-- Dependencies: 1534 1534 -- Name: nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -292,8 +309,18 @@ ALTER TABLE ONLY nodi -- --- TOC entry 1903 (class 2606 OID 61279) --- Dependencies: 1545 1545 +-- TOC entry 1915 (class 2606 OID 61305) +-- Dependencies: 1550 1550 +-- Name: persona_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY persona_nodi + ADD CONSTRAINT persona_nodi_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 1911 (class 2606 OID 61279) +-- Dependencies: 1548 1548 -- Name: persona_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -302,8 +329,8 @@ ALTER TABLE ONLY persona_recapiti -- --- TOC entry 1901 (class 2606 OID 61252) --- Dependencies: 1544 1544 +-- TOC entry 1909 (class 2606 OID 61252) +-- Dependencies: 1547 1547 -- Name: persona_uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -312,8 +339,8 @@ ALTER TABLE ONLY persona_uffici -- --- TOC entry 1905 (class 2606 OID 61294) --- Dependencies: 1546 1546 +-- TOC entry 1913 (class 2606 OID 61294) +-- Dependencies: 1549 1549 -- Name: persona_ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -322,8 +349,8 @@ ALTER TABLE ONLY persona_ufficio_recapiti -- --- TOC entry 1897 (class 2606 OID 61235) --- Dependencies: 1542 1542 +-- TOC entry 1905 (class 2606 OID 61235) +-- Dependencies: 1545 1545 -- Name: persone_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -332,8 +359,8 @@ ALTER TABLE ONLY persone -- --- TOC entry 1887 (class 2606 OID 59356) --- Dependencies: 1537 1537 +-- TOC entry 1895 (class 2606 OID 59356) +-- Dependencies: 1540 1540 -- Name: struttura_indirizzi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -342,8 +369,8 @@ ALTER TABLE ONLY struttura_indirizzi -- --- TOC entry 1883 (class 2606 OID 59339) --- Dependencies: 1535 1535 +-- TOC entry 1891 (class 2606 OID 59339) +-- Dependencies: 1538 1538 -- Name: strutture_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -352,8 +379,8 @@ ALTER TABLE ONLY strutture -- --- TOC entry 1877 (class 2606 OID 59296) --- Dependencies: 1532 1532 +-- TOC entry 1885 (class 2606 OID 59296) +-- Dependencies: 1535 1535 -- Name: tipi_nodo_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -362,8 +389,8 @@ ALTER TABLE ONLY tipi_nodo -- --- TOC entry 1899 (class 2606 OID 61242) --- Dependencies: 1543 1543 +-- TOC entry 1907 (class 2606 OID 61242) +-- Dependencies: 1546 1546 -- Name: tipi_rapporto_lavoro_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -372,8 +399,8 @@ ALTER TABLE ONLY tipi_rapporto_lavoro -- --- TOC entry 1879 (class 2606 OID 59303) --- Dependencies: 1533 1533 +-- TOC entry 1887 (class 2606 OID 59303) +-- Dependencies: 1536 1536 -- Name: tipi_recapito_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -382,8 +409,8 @@ ALTER TABLE ONLY tipi_recapito -- --- TOC entry 1895 (class 2606 OID 61226) --- Dependencies: 1541 1541 +-- TOC entry 1903 (class 2606 OID 61226) +-- Dependencies: 1544 1544 -- Name: titoli_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -392,8 +419,8 @@ ALTER TABLE ONLY titoli -- --- TOC entry 1881 (class 2606 OID 59321) --- Dependencies: 1534 1534 +-- TOC entry 1889 (class 2606 OID 59321) +-- Dependencies: 1537 1537 -- Name: uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -402,8 +429,8 @@ ALTER TABLE ONLY uffici -- --- TOC entry 1889 (class 2606 OID 59366) --- Dependencies: 1538 1538 +-- TOC entry 1897 (class 2606 OID 59366) +-- Dependencies: 1541 1541 -- Name: ufficio_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -412,8 +439,8 @@ ALTER TABLE ONLY ufficio_nodi -- --- TOC entry 1891 (class 2606 OID 59408) --- Dependencies: 1539 1539 +-- TOC entry 1899 (class 2606 OID 59408) +-- Dependencies: 1542 1542 -- Name: ufficio_orari_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -422,8 +449,8 @@ ALTER TABLE ONLY ufficio_orari -- --- TOC entry 1893 (class 2606 OID 59419) --- Dependencies: 1540 1540 +-- TOC entry 1901 (class 2606 OID 59419) +-- Dependencies: 1543 1543 -- Name: ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -432,8 +459,8 @@ ALTER TABLE ONLY ufficio_recapiti -- --- TOC entry 1885 (class 2606 OID 59345) --- Dependencies: 1536 1536 +-- TOC entry 1893 (class 2606 OID 59345) +-- Dependencies: 1539 1539 -- Name: vie_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -441,7 +468,7 @@ ALTER TABLE ONLY vie ADD CONSTRAINT vie_pkey PRIMARY KEY (id); --- Completed on 2010-10-13 13:00:49 +-- Completed on 2010-10-14 11:26:03 -- -- PostgreSQL database dump complete diff --git a/src/Makefile.am b/src/Makefile.am index 34da5c9..da191d0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,8 @@ organigramma_SOURCES = \ persona.h \ persone.c \ persone.h \ + personanodo.c \ + personanodo.h \ personarecapito.c \ personarecapito.h \ personaufficio.c \ diff --git a/src/persona.c b/src/persona.c index cf713e1..056120d 100644 --- a/src/persona.c +++ b/src/persona.c @@ -18,8 +18,10 @@ */ #include +#include #include "persona.h" +#include "personanodo.h" #include "personaufficio.h" #include "personaufficiorecapito.h" #include "personarecapito.h" @@ -30,10 +32,12 @@ static void persona_init (Persona *persona); static void persona_carica (Persona *persona); static void persona_salva (Persona *persona); +static void persona_carica_nodi (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_nodo (Persona *persona); static void persona_ufficio_modifica (Persona *persona); static void persona_ufficio_recapito_modifica (Persona *persona); static void persona_recapito_modifica (Persona *persona); @@ -49,6 +53,7 @@ static void persona_get_property (GObject *object, GValue *value, GParamSpec *pspec); +static void persona_on_nodo_aggiornato (gpointer instance, gpointer user_data); 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); @@ -57,6 +62,19 @@ static gboolean persona_on_w_persona_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data); +static void persona_on_btn_nodo_nuovo_clicked (GtkButton *button, + gpointer user_data); +static void persona_on_btn_nodo_modifica_clicked (GtkButton *button, + gpointer user_data); +static void persona_on_btn_nodo_elimina_clicked (GtkButton *button, + gpointer user_data); +static void persona_on_trv_nodi_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data); +static void persona_on_nodi_sel_changed (GtkTreeSelection *selection, + gpointer user_data); + static void persona_on_btn_ufficio_nuovo_clicked (GtkButton *button, gpointer user_data); static void persona_on_btn_ufficio_modifica_clicked (GtkButton *button, @@ -102,15 +120,27 @@ static void persona_on_btn_salva_clicked (GtkButton *button, enum { LBL_ID, + LSTORE_NODI, LSTORE_UFFICI, LSTORE_UFFICIO_RECAPITI, LSTORE_RECAPITI }; +enum +{ + NODI_COL_ID, + NODI_COL_TIPO, + NODI_COL_NODO, + NODI_COL_DA_DATA, + NODI_COL_A_DATA +}; + enum { UFFICI_COL_ID, - UFFICI_COL_UFFICIO + UFFICI_COL_UFFICIO, + UFFICI_COL_DA_DATA, + UFFICI_COL_A_DATA }; enum @@ -138,6 +168,7 @@ struct _PersonaPrivate GObject **objects; + GtkTreeSelection *sel_nodi; GtkTreeSelection *sel_uffici; GtkTreeSelection *sel_ufficio_recapiti; GtkTreeSelection *sel_recapiti; @@ -201,6 +232,7 @@ Persona gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, g_strsplit (g_strconcat ( "lstore_titoli" + "|lstore_persona_nodi" "|lstore_persona_uffici" "|lstore_persona_ufficio_recapiti" "|lstore_persona_recapiti" @@ -220,6 +252,7 @@ Persona priv->objects = gtk_form_get_objects_by_name (priv->form, "label67", + "lstore_persona_nodi", "lstore_persona_uffici", "lstore_persona_ufficio_recapiti", "lstore_persona_recapiti", @@ -228,6 +261,7 @@ Persona g_signal_connect (priv->w, "delete-event", G_CALLBACK (persona_on_w_persona_delete_event), (gpointer *)a); + priv->sel_nodi = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview13"))); 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"))); @@ -235,6 +269,15 @@ Persona 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, "button70")), + "clicked", G_CALLBACK (persona_on_btn_nodo_nuovo_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button71")), + "clicked", G_CALLBACK (persona_on_btn_nodo_modifica_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button72")), + "clicked", G_CALLBACK (persona_on_btn_nodo_elimina_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview13")), + "row-activated", G_CALLBACK (persona_on_trv_nodi_row_activated), (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")), @@ -305,6 +348,7 @@ persona_carica (Persona *persona) if (gtk_form_fill_from_table (priv->form)) { + persona_carica_nodi (persona); persona_carica_uffici (persona); persona_carica_ufficio_recapiti (persona); persona_carica_recapiti (persona); @@ -375,6 +419,47 @@ persona_salva (Persona *persona) } } +static void +persona_carica_nodi (Persona *persona) +{ + gchar *sql; + GdaDataModel *dm; + guint row; + guint rows; + + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + gtk_list_store_clear (GTK_LIST_STORE (priv->objects[LSTORE_NODI])); + + sql = g_strdup_printf ("SELECT pu.id, tn.nome AS tipo_nodo, u.nome, pu.da_data, pu.a_data" + " FROM persona_nodi AS pu INNER JOIN nodi AS u ON pu.id_nodi = u.id" + " INNER JOIN tipi_nodo AS tn ON u.id_tipi_nodo = tn.id" + " WHERE pu.id_persone = %d" + " AND pu.status <> 'E'", + priv->id); + 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_NODI]), &iter); + gtk_list_store_set (GTK_LIST_STORE (priv->objects[LSTORE_NODI]), &iter, + NODI_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"), + NODI_COL_TIPO, gdaex_data_model_get_field_value_stringify_at (dm, row, "tipo_nodo"), + NODI_COL_NODO, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"), + NODI_COL_DA_DATA, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "da_data"), "%d/%m/%Y"), + NODI_COL_A_DATA, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "a_data"), "%d/%m/%Y"), + -1); + } + + g_object_unref (dm); + } + g_free (sql); +} + static void persona_carica_uffici (Persona *persona) { @@ -387,7 +472,7 @@ persona_carica_uffici (Persona *persona) gtk_list_store_clear (GTK_LIST_STORE (priv->objects[LSTORE_UFFICI])); - sql = g_strdup_printf ("SELECT pu.id, u.nome" + sql = g_strdup_printf ("SELECT pu.id, u.nome, pu.da_data, pu.a_data" " FROM persona_uffici AS pu INNER JOIN uffici AS u ON" " pu.id_uffici = u.id" " WHERE pu.id_persone = %d" @@ -405,6 +490,8 @@ persona_carica_uffici (Persona *persona) gtk_list_store_set (GTK_LIST_STORE (priv->objects[LSTORE_UFFICI]), &iter, UFFICI_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"), UFFICI_COL_UFFICIO, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"), + UFFICI_COL_DA_DATA, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "da_data"), "%d/%m/%Y"), + UFFICI_COL_A_DATA, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "a_data"), "%d/%m/%Y"), -1); } @@ -505,6 +592,44 @@ persona_carica_recapiti (Persona *persona) g_free (sql); } +static void +persona_nodo_modifica (Persona *persona) +{ + GtkTreeIter iter; + GtkWidget *dialog; + + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + if (gtk_tree_selection_get_selected (priv->sel_nodi, NULL, &iter)) + { + guint id; + GtkWidget *w; + + gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_NODI]), &iter, + NODI_COL_ID, &id, + -1); + + PersonaNodo *a = persona_nodo_new (priv->commons, id, 0); + + g_signal_connect (G_OBJECT (a), "aggiornato", + G_CALLBACK (persona_on_nodo_aggiornato), (gpointer)persona); + + w = persona_nodo_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 nodo."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + static void persona_ufficio_modifica (Persona *persona) { @@ -697,6 +822,15 @@ persona_conferma_chiusura (Persona *persona) } /* CALLBACK */ +static void +persona_on_nodo_aggiornato (gpointer instance, gpointer user_data) +{ + Persona *persona = (Persona *)user_data; + PersonaClass *klass = PERSONA_GET_CLASS (persona); + + persona_carica_nodi (persona); +} + static void persona_on_ufficio_aggiornato (gpointer instance, gpointer user_data) { @@ -732,6 +866,93 @@ persona_on_w_persona_delete_event (GtkWidget *widget, return !persona_conferma_chiusura ((Persona *)user_data); } +static void +persona_on_btn_nodo_nuovo_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + Persona *persona = (Persona *)user_data; + + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + PersonaNodo *a = persona_nodo_new (priv->commons, 0, priv->id); + + g_signal_connect (G_OBJECT (a), "aggiornato", + G_CALLBACK (persona_on_nodo_aggiornato), (gpointer)persona); + + w = persona_nodo_get_widget (a); + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w)); + gtk_widget_show (w); +} + +static void +persona_on_btn_nodo_modifica_clicked (GtkButton *button, + gpointer user_data) +{ + persona_nodo_modifica ((Persona *)user_data); +} + +static void +persona_on_btn_nodo_elimina_clicked (GtkButton *button, + gpointer user_data) +{ + GtkTreeIter iter; + GtkWidget *dialog; + guint risp; + + 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_nodi, 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 nodo 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_NODI]), &iter, + NODI_COL_ID, &id, + -1); + + gdaex_execute (priv->commons->gdaex, + g_strdup_printf ("UPDATE persona_nodi" + " SET status = 'E'" + " WHERE id = %d", + id)); + + persona_carica_nodi (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 nodo"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +persona_on_trv_nodi_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + persona_nodo_modifica ((Persona *)user_data); +} + static void persona_on_btn_ufficio_nuovo_clicked (GtkButton *button, gpointer user_data) diff --git a/src/personanodo.c b/src/personanodo.c new file mode 100644 index 0000000..1c7ff4d --- /dev/null +++ b/src/personanodo.c @@ -0,0 +1,383 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * 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 +#endif + +#include + +#include "personanodo.h" +#include "nodi.h" + +static void persona_nodo_class_init (PersonaNodoClass *klass); +static void persona_nodo_init (PersonaNodo *persona_nodo); + +static void persona_nodo_carica (PersonaNodo *persona_nodo); +static void persona_nodo_salva (PersonaNodo *persona_nodo); + +static void persona_nodo_carica_nodo (PersonaNodo *indirizzo); + +static gboolean persona_nodo_conferma_chiusura (PersonaNodo *persona_nodo); + +static void persona_nodo_on_nodo_selezionato (gpointer instance, + guint id, gpointer user_data); + +static void persona_nodo_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void persona_nodo_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean persona_nodo_on_w_persona_nodo_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); + +static void persona_nodo_on_btn_ricerca_via_clicked (GtkButton *button, + gpointer user_data); +static void persona_nodo_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void persona_nodo_on_btn_salva_clicked (GtkButton *button, + gpointer user_data); + + +#define PERSONA_NODO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PERSONA_NODO, PersonaNodoPrivate)) + +enum +{ + LBL_ID, + LBL_ID_PERSONE +}; + +typedef struct _PersonaNodoPrivate PersonaNodoPrivate; +struct _PersonaNodoPrivate + { + Commons *commons; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + guint id; + }; + +G_DEFINE_TYPE (PersonaNodo, persona_nodo, G_TYPE_OBJECT) + +static void +persona_nodo_class_init (PersonaNodoClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (PersonaNodoPrivate)); + + object_class->set_property = persona_nodo_set_property; + object_class->get_property = persona_nodo_get_property; + + /** + * PersonaNodo::aggiornato: + * @persona_nodo: + * + */ + 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_nodo_init (PersonaNodo *persona_nodo) +{ + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); +} + +/** + * persona_nodo_new: + * @commons: + * @id: + * @id_persone: + * + * Returns: the newly created #PersonaNodo object. + */ +PersonaNodo +*persona_nodo_new (Commons *commons, guint id, guint id_persone) +{ + GError *error; + + PersonaNodo *a = PERSONA_NODO (g_object_new (persona_nodo_get_type (), NULL)); + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (a); + + priv->commons = commons; + + error = NULL; + + gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, + g_strsplit ("w_persona_nodo", "|", -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_nodo.form", NULL), priv->commons->gtkbuilder); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_nodo")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "label116", + "label117", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (persona_nodo_on_w_persona_nodo_delete_event), (gpointer *)a); + + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button90")), + "clicked", G_CALLBACK (persona_nodo_on_btn_ricerca_via_clicked), (gpointer *)a); + + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button91")), + "clicked", G_CALLBACK (persona_nodo_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button92")), + "clicked", G_CALLBACK (persona_nodo_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_form_set_as_origin (priv->form); + } + else + { + gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", priv->id)); + + persona_nodo_carica (a); + } + + return a; +} + +/** + * persona_nodo_get_widget: + * @persona_nodo: + * + */ +GtkWidget +*persona_nodo_get_widget (PersonaNodo *persona_nodo) +{ + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + return priv->w; +} + +/* PRIVATE */ +static void +persona_nodo_carica (PersonaNodo *persona_nodo) +{ + gchar *sql; + GdaDataModel *dm; + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + if (gtk_form_fill_from_table (priv->form)) + { + } +} + +static void +persona_nodo_salva (PersonaNodo *persona_nodo) +{ + gchar *sql; + GtkWidget *dialog; + + PersonaNodoClass *klass = PERSONA_NODO_GET_CLASS (persona_nodo); + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + 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_nodo, 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_nodo_on_nodo_selezionato (gpointer instance, guint id, gpointer user_data) +{ + PersonaNodo *ia = (PersonaNodo *)user_data; + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (ia); + + gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "label115"), g_strdup_printf ("%d", id)); +} + +static void +persona_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + PersonaNodo *persona_nodo = PERSONA_NODO (object); + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +persona_nodo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + PersonaNodo *persona_nodo = PERSONA_NODO (object); + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +persona_nodo_conferma_chiusura (PersonaNodo *persona_nodo) +{ + GtkWidget *dialog; + + gboolean ret; + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + 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_nodo_on_w_persona_nodo_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return !persona_nodo_conferma_chiusura ((PersonaNodo *)user_data); +} + +static void +persona_nodo_on_btn_ricerca_via_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + PersonaNodo *ia = (PersonaNodo *)user_data; + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (ia); + + Nodi *v = nodi_new (priv->commons, TRUE); + + g_signal_connect (G_OBJECT (v), "selezionato", + G_CALLBACK (persona_nodo_on_nodo_selezionato), (gpointer)ia); + + w = nodi_get_widget (v); + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w)); + gtk_widget_show (w); +} + +static void +persona_nodo_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + PersonaNodo *persona_nodo = (PersonaNodo *)user_data; + + PersonaNodoPrivate *priv = PERSONA_NODO_GET_PRIVATE (persona_nodo); + + if (persona_nodo_conferma_chiusura (persona_nodo)) gtk_widget_destroy (priv->w); +} + +static void +persona_nodo_on_btn_salva_clicked (GtkButton *button, + gpointer user_data) +{ + persona_nodo_salva ((PersonaNodo *)user_data); +} diff --git a/src/personanodo.h b/src/personanodo.h new file mode 100644 index 0000000..988fd67 --- /dev/null +++ b/src/personanodo.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * 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_NODO_H__ +#define __PERSONA_NODO_H__ + +#include +#include + +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_PERSONA_NODO (persona_nodo_get_type ()) +#define PERSONA_NODO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PERSONA_NODO, PersonaNodo)) +#define PERSONA_NODO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PERSONA_NODO, PersonaNodoClass)) +#define IS_PERSONA_NODO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PERSONA_NODO)) +#define IS_PERSONA_NODO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PERSONA_NODO)) +#define PERSONA_NODO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PERSONA_NODO, PersonaNodoClass)) + + +typedef struct _PersonaNodo PersonaNodo; +typedef struct _PersonaNodoClass PersonaNodoClass; + +struct _PersonaNodo + { + GObject parent; + }; + +struct _PersonaNodoClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType persona_nodo_get_type (void) G_GNUC_CONST; + +PersonaNodo *persona_nodo_new (Commons *commons, guint id, guint id_persone); + +GtkWidget *persona_nodo_get_widget (PersonaNodo *persona_nodo); + + +G_END_DECLS + +#endif /* __PERSONA_NODO_H__ */ -- 2.49.0