]> saetta.ns0.it Git - solipa/territorio/commitdiff
Migrato il form regione a zakform.
authorAndrea Zagli <azagli@libero.it>
Sat, 21 Dec 2019 09:08:22 +0000 (10:08 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 21 Dec 2019 09:08:22 +0000 (10:08 +0100)
data/territorio/form/regione.form
src/regione.c

index 247ebc0683a247ea86cff00b0e53625602fcde09..bb6f07e1c4d389d6310784dc9a8073e3870d0f52 100644 (file)
@@ -1,25 +1,25 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>regioni</table>
-
-       <widget type="label" name="label11" label="label10">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry5" label="label12">
-               <field type="text" name="nome">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry8" label="label15">
-               <field type="text" name="cod_istat">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <label>label10</label>
+    <is-key>TRUE</is-key>
+    <widget>label11</widget>
+    <format thousands_separator="" />
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>nome</name>
+    <type>string</type>
+    <label>label12</label>
+    <widget>entry5</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>cod_istat</name>
+    <type>string</type>
+    <label>label15</label>
+    <widget>entry8</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+</zakform>
index 671cb0e193fa3d6e9d51ff924dfbad09580c0abc..97c0c3713b9db1f7ebf73a2ebeb703f11fb5c0bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2018 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2019 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
@@ -17,7 +17,9 @@
  *
  */
 
-#include <libgtkform/form.h>
+#include <libzakform/libzakform.h>
+#include <libzakformgtk/libzakformgtk.h>
+#include <libzakformgdaex/libzakformgdaex.h>
 #include <libzakautho/autho.h>
 #include <libsolipa/libsolipa.h>
 
@@ -63,7 +65,8 @@ struct _TerritorioRegionePrivate
        {
                TerritorioCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -135,13 +138,15 @@ TerritorioRegione
                        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, "regione.form", NULL), priv->commons->gtkbuilder);
+       priv->form = zak_form_gtk_form_new ();
+       zak_form_gtk_form_set_gtkbuilder (priv->form, priv->commons->gtkbuilder);
+       zak_form_form_load_from_file (ZAK_FORM_FORM (priv->form), g_build_filename (priv->commons->formdir, "regione.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "regioni");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_regione"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label11",
                                                      NULL);
 
@@ -155,13 +160,14 @@ TerritorioRegione
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button72"),
                          "clicked", G_CALLBACK (territorio_regione_on_btn_salva_chiudi_clicked), (gpointer *)a);
 
-       priv->id = id;
+       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
 
+       priv->id = id;
        if (priv->id == 0)
                {
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
                }
        else
                {
@@ -218,7 +224,7 @@ territorio_regione_carica (TerritorioRegione *territorio_regione)
 {
        TerritorioRegionePrivate *priv = TERRITORIO_REGIONE_GET_PRIVATE (territorio_regione);
 
-       if (gtk_form_fill_from_table (priv->form))
+       if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
                }
 }
@@ -226,31 +232,42 @@ territorio_regione_carica (TerritorioRegione *territorio_regione)
 static void
 territorio_regione_salva (TerritorioRegione *territorio_regione, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        TerritorioRegioneClass *klass = TERRITORIO_REGIONE_GET_CLASS (territorio_regione);
 
        TerritorioRegionePrivate *priv = TERRITORIO_REGIONE_GET_PRIVATE (territorio_regione);
 
-       if (!gtk_form_check (priv->form, (priv->id != 0), NULL, TRUE, priv->w, TRUE))
+       if (!zak_form_gtk_form_is_valid (priv->form, priv->w))
                {
                        return;
                }
 
+       success = FALSE;
+
        if (priv->id == 0)
                {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
+                       guint new_id;
+
+                       new_id = gdaex_get_new_id (priv->commons->gdaex,
+                                                  "regioni",
+                                                  "id",
+                                                  NULL);
+
+                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", new_id));
+
+                       success = zak_form_form_insert (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider));
                }
        else
                {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
+                       success = zak_form_form_update (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider));
                }
 
-       if (gdaex_execute (priv->commons->gdaex, sql) == 1)
+       if (success)
                {
                        g_signal_emit (territorio_regione, klass->aggiornato_signal_id, 0);
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
 
                        if (priv->id == 0)
                                {
@@ -319,7 +336,7 @@ territorio_regione_conferma_chiusura (TerritorioRegione *territorio_regione)
 
        ret = TRUE;
        if (gtk_widget_get_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button14")))
-           && gtk_form_is_changed (priv->form))
+           && zak_form_form_is_changed (ZAK_FORM_FORM (priv->form)))
                {
                        if (solipa_message_dialog (priv->w,
                                                   GTK_MESSAGE_QUESTION,