Browse Source

start the 3rd assignment

Chris Cromer 6 months ago
parent
commit
18dafc38e1
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
63 changed files with 1811 additions and 226 deletions
  1. 1
    0
      data/ui/sernatur.gresource.xml
  2. 39
    110
      data/ui/sernatur.window.ui
  3. 55
    0
      data/ui/splash.ui
  4. 0
    0
      doc/Enunciados/trabajoSemestral(E1).pdf
  5. 0
    0
      doc/Enunciados/trabajoSemestral(E2).pdf
  6. BIN
      doc/Enunciados/trabajoSemestral(E3).pdf
  7. 0
    0
      doc/Informes/Informe1.pdf
  8. 0
    0
      doc/Informes/Informe1.tex
  9. 0
    0
      doc/Informes/Informe1_creartablas.sql
  10. 0
    0
      doc/Informes/Informe1_insertarduplas.sql
  11. 0
    0
      doc/Informes/Informe1corregido.pdf
  12. 0
    0
      doc/Informes/Informe1corregido.tex
  13. 0
    0
      doc/Informes/Informe1corregido_creartablas.sql
  14. 0
    0
      doc/Informes/Informe1corregido_insertarduplas.sql
  15. 0
    0
      doc/Informes/Informe2.pdf
  16. 0
    0
      doc/Informes/Informe2.tex
  17. 0
    0
      doc/Informes/Informe2_Q1.png
  18. 0
    0
      doc/Informes/Informe2_Q2.png
  19. 0
    0
      doc/Informes/Informe2_Q3.png
  20. 0
    0
      doc/Informes/Informe2_Q4.png
  21. 0
    0
      doc/Informes/Informe2_Q5.png
  22. 0
    0
      doc/Informes/Informe2_vistaQ1.sql
  23. 0
    0
      doc/Informes/Informe2_vistaQ2.sql
  24. 0
    0
      doc/Informes/Informe2_vistaQ3.sql
  25. 0
    0
      doc/Informes/Informe2_vistaQ4.sql
  26. 0
    0
      doc/Informes/Informe2_vistaQ5.sql
  27. 0
    0
      doc/Informes/MER.dia
  28. 0
    0
      doc/Informes/MER.png
  29. 0
    0
      doc/Informes/MERcorregido.dia
  30. 0
    0
      doc/Informes/MERcorregido.png
  31. 0
    0
      doc/Informes/ubblogo.png
  32. 11
    5
      doc/meson.build
  33. 69
    0
      lib/db/arrienda.vala
  34. 94
    0
      lib/db/asociado.vala
  35. 50
    0
      lib/db/categoria.vala
  36. 58
    0
      lib/db/ciudad.vala
  37. 51
    0
      lib/db/contacto_emergencia.vala
  38. 53
    0
      lib/db/descuento.vala
  39. 56
    0
      lib/db/empresa.vala
  40. 50
    0
      lib/db/enfermedad.vala
  41. 50
    0
      lib/db/especialidad.vala
  42. 69
    0
      lib/db/guia.vala
  43. 69
    0
      lib/db/lugar.vala
  44. 90
    0
      lib/db/participa.vala
  45. 74
    0
      lib/db/posee.vala
  46. 87
    0
      lib/db/realiza.vala
  47. 50
    0
      lib/db/region.vala
  48. 77
    0
      lib/db/requerir_auto.vala
  49. 66
    0
      lib/db/tiene_enfermedad.vala
  50. 72
    0
      lib/db/tour.vala
  51. 62
    0
      lib/db/turista.vala
  52. 56
    0
      lib/db/vehiculo.vala
  53. 64
    0
      lib/dbwrapper.vala
  54. 44
    0
      lib/meson.build
  55. 139
    0
      lib/rut.vala
  56. 9
    1
      meson.build
  57. 4
    0
      meson_options.txt
  58. 2
    0
      po/POTFILES
  59. 28
    22
      po/es.po
  60. 18
    15
      po/sernatur.pot
  61. 5
    17
      src/meson.build
  62. 86
    53
      src/sernatur-window.vala
  63. 3
    3
      src/sernatur.vala

+ 1
- 0
data/ui/sernatur.gresource.xml View File

@@ -15,6 +15,7 @@
15 15
 <gresources>
16 16
 	<gresource prefix="/cl/cromer/ubb/sernatur">
17 17
 		<file preprocess="xml-stripblanks">sernatur.window.ui</file>
18
+		<file preprocess="xml-stripblanks">splash.ui</file>
18 19
 		<file preprocess="to-pixdata">pixdata/logo-sernatur.svg</file>
19 20
 	</gresource>
20 21
 </gresources>

+ 39
- 110
data/ui/sernatur.window.ui View File

@@ -14,8 +14,8 @@ Redistribution and use in source and binary forms, with or without modification,
14 14
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 15
 
16 16
 -->
17
-<interface>
18
-  <requires lib="gtk+" version="3.10"/>
17
+<interface domain="sernatur">
18
+  <requires lib="gtk+" version="3.20"/>
19 19
   <template class="SernaturMainWindow" parent="GtkApplicationWindow">
20 20
     <property name="can_focus">False</property>
21 21
     <property name="title">SERNATUR</property>
@@ -31,6 +31,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31 31
         <property name="visible">True</property>
32 32
         <property name="can_focus">False</property>
33 33
         <property name="orientation">vertical</property>
34
+        <property name="baseline_position">top</property>
34 35
         <child>
35 36
           <object class="GtkMenuBar" id="menubar">
36 37
             <property name="visible">True</property>
@@ -39,46 +40,64 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
39 40
               <object class="GtkMenuItem">
40 41
                 <property name="visible">True</property>
41 42
                 <property name="can_focus">False</property>
42
-                <property name="label" translatable="yes">_File</property>
43
+                <property name="label" translatable="yes">_Menu</property>
43 44
                 <property name="use_underline">True</property>
44 45
                 <child type="submenu">
45 46
                   <object class="GtkMenu">
46 47
                     <property name="visible">True</property>
47 48
                     <property name="can_focus">False</property>
48 49
                     <child>
49
-                      <object class="GtkImageMenuItem">
50
-                        <property name="label">gtk-new</property>
50
+                      <object class="GtkMenuItem">
51 51
                         <property name="visible">True</property>
52 52
                         <property name="can_focus">False</property>
53
-                        <property name="use_underline">True</property>
54
-                        <property name="use_stock">True</property>
53
+                        <property name="right_justified">True</property>
54
+                        <property name="label" translatable="yes">Tours</property>
55 55
                       </object>
56 56
                     </child>
57 57
                     <child>
58
-                      <object class="GtkImageMenuItem">
59
-                        <property name="label">gtk-open</property>
58
+                      <object class="GtkMenuItem">
60 59
                         <property name="visible">True</property>
61 60
                         <property name="can_focus">False</property>
61
+                        <property name="label" translatable="yes">Guides and Staff</property>
62 62
                         <property name="use_underline">True</property>
63
-                        <property name="use_stock">True</property>
64 63
                       </object>
65 64
                     </child>
66 65
                     <child>
67
-                      <object class="GtkImageMenuItem">
68
-                        <property name="label">gtk-save</property>
66
+                      <object class="GtkMenuItem">
69 67
                         <property name="visible">True</property>
70 68
                         <property name="can_focus">False</property>
69
+                        <property name="label" translatable="yes">Tourists</property>
71 70
                         <property name="use_underline">True</property>
72
-                        <property name="use_stock">True</property>
71
+                        <child type="submenu">
72
+                          <object class="GtkMenu">
73
+                            <property name="visible">True</property>
74
+                            <property name="can_focus">False</property>
75
+                            <child>
76
+                              <object class="GtkMenuItem">
77
+                                <property name="visible">True</property>
78
+                                <property name="can_focus">False</property>
79
+                                <property name="label" translatable="yes">Illnesses</property>
80
+                                <property name="use_underline">True</property>
81
+                              </object>
82
+                            </child>
83
+                            <child>
84
+                              <object class="GtkMenuItem">
85
+                                <property name="visible">True</property>
86
+                                <property name="can_focus">False</property>
87
+                                <property name="label" translatable="yes">Tour</property>
88
+                                <property name="use_underline">True</property>
89
+                              </object>
90
+                            </child>
91
+                          </object>
92
+                        </child>
73 93
                       </object>
74 94
                     </child>
75 95
                     <child>
76
-                      <object class="GtkImageMenuItem">
77
-                        <property name="label">gtk-save-as</property>
96
+                      <object class="GtkMenuItem">
78 97
                         <property name="visible">True</property>
79 98
                         <property name="can_focus">False</property>
99
+                        <property name="label" translatable="yes">Vehicles</property>
80 100
                         <property name="use_underline">True</property>
81
-                        <property name="use_stock">True</property>
82 101
                       </object>
83 102
                     </child>
84 103
                     <child>
@@ -88,93 +107,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
88 107
                       </object>
89 108
                     </child>
90 109
                     <child>
91
-                      <object class="GtkImageMenuItem">
92
-                        <property name="label">gtk-quit</property>
93
-                        <property name="visible">True</property>
94
-                        <property name="can_focus">False</property>
95
-                        <property name="use_underline">True</property>
96
-                        <property name="use_stock">True</property>
97
-                      </object>
98
-                    </child>
99
-                  </object>
100
-                </child>
101
-              </object>
102
-            </child>
103
-            <child>
104
-              <object class="GtkMenuItem">
105
-                <property name="visible">True</property>
106
-                <property name="can_focus">False</property>
107
-                <property name="label" translatable="yes">_Edit</property>
108
-                <property name="use_underline">True</property>
109
-                <child type="submenu">
110
-                  <object class="GtkMenu">
111
-                    <property name="visible">True</property>
112
-                    <property name="can_focus">False</property>
113
-                    <child>
114
-                      <object class="GtkImageMenuItem">
115
-                        <property name="label">gtk-cut</property>
116
-                        <property name="visible">True</property>
117
-                        <property name="can_focus">False</property>
118
-                        <property name="use_underline">True</property>
119
-                        <property name="use_stock">True</property>
120
-                      </object>
121
-                    </child>
122
-                    <child>
123
-                      <object class="GtkImageMenuItem">
124
-                        <property name="label">gtk-copy</property>
125
-                        <property name="visible">True</property>
126
-                        <property name="can_focus">False</property>
127
-                        <property name="use_underline">True</property>
128
-                        <property name="use_stock">True</property>
129
-                      </object>
130
-                    </child>
131
-                    <child>
132
-                      <object class="GtkImageMenuItem">
133
-                        <property name="label">gtk-paste</property>
134
-                        <property name="visible">True</property>
135
-                        <property name="can_focus">False</property>
136
-                        <property name="use_underline">True</property>
137
-                        <property name="use_stock">True</property>
138
-                      </object>
139
-                    </child>
140
-                    <child>
141
-                      <object class="GtkImageMenuItem">
142
-                        <property name="label">gtk-delete</property>
110
+                      <object class="GtkMenuItem">
143 111
                         <property name="visible">True</property>
144 112
                         <property name="can_focus">False</property>
113
+                        <property name="label" translatable="yes">Quit</property>
145 114
                         <property name="use_underline">True</property>
146
-                        <property name="use_stock">True</property>
147
-                      </object>
148
-                    </child>
149
-                  </object>
150
-                </child>
151
-              </object>
152
-            </child>
153
-            <child>
154
-              <object class="GtkMenuItem">
155
-                <property name="visible">True</property>
156
-                <property name="can_focus">False</property>
157
-                <property name="label" translatable="yes">_View</property>
158
-                <property name="use_underline">True</property>
159
-              </object>
160
-            </child>
161
-            <child>
162
-              <object class="GtkMenuItem">
163
-                <property name="visible">True</property>
164
-                <property name="can_focus">False</property>
165
-                <property name="label" translatable="yes">_Help</property>
166
-                <property name="use_underline">True</property>
167
-                <child type="submenu">
168
-                  <object class="GtkMenu">
169
-                    <property name="visible">True</property>
170
-                    <property name="can_focus">False</property>
171
-                    <child>
172
-                      <object class="GtkImageMenuItem">
173
-                        <property name="label">gtk-about</property>
174
-                        <property name="visible">True</property>
175
-                        <property name="can_focus">False</property>
176
-                        <property name="use_underline">True</property>
177
-                        <property name="use_stock">True</property>
115
+                        <signal name="activate" handler="menu_quit" swapped="no"/>
178 116
                       </object>
179 117
                     </child>
180 118
                   </object>
@@ -189,16 +127,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
189 127
           </packing>
190 128
         </child>
191 129
         <child>
192
-          <object class="GtkImage" id="logo">
193
-            <property name="visible">True</property>
194
-            <property name="can_focus">False</property>
195
-            <property name="resource">/cl/cromer/ubb/sernatur/pixdata/logo-sernatur.svg</property>
196
-          </object>
197
-          <packing>
198
-            <property name="expand">True</property>
199
-            <property name="fill">True</property>
200
-            <property name="position">1</property>
201
-          </packing>
130
+          <placeholder/>
202 131
         </child>
203 132
       </object>
204 133
     </child>

+ 55
- 0
data/ui/splash.ui View File

@@ -0,0 +1,55 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!-- Generated with glade 3.22.1 
3
+
4
+Copyright 2018 Chris Cromer
5
+
6
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
10
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13
+
14
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+
16
+-->
17
+<interface domain="sernatur">
18
+  <requires lib="gtk+" version="3.20"/>
19
+  <object class="GtkGrid" id="content_grid">
20
+    <property name="visible">True</property>
21
+    <property name="can_focus">False</property>
22
+    <property name="margin_left">5</property>
23
+    <property name="margin_right">5</property>
24
+    <property name="margin_top">5</property>
25
+    <property name="margin_bottom">5</property>
26
+    <property name="column_homogeneous">True</property>
27
+    <child>
28
+      <object class="GtkImage">
29
+        <property name="visible">True</property>
30
+        <property name="can_focus">False</property>
31
+        <property name="halign">center</property>
32
+        <property name="valign">end</property>
33
+        <property name="resource">/cl/cromer/ubb/sernatur/pixdata/logo-sernatur.svg</property>
34
+      </object>
35
+      <packing>
36
+        <property name="left_attach">0</property>
37
+        <property name="top_attach">0</property>
38
+      </packing>
39
+    </child>
40
+    <child>
41
+      <object class="GtkLabel">
42
+        <property name="visible">True</property>
43
+        <property name="can_focus">False</property>
44
+        <property name="halign">center</property>
45
+        <property name="valign">center</property>
46
+        <property name="label" translatable="yes">Christopher Cromer</property>
47
+        <property name="justify">center</property>
48
+      </object>
49
+      <packing>
50
+        <property name="left_attach">0</property>
51
+        <property name="top_attach">1</property>
52
+      </packing>
53
+    </child>
54
+  </object>
55
+</interface>

doc/trabajoSemestral(E1).pdf → doc/Enunciados/trabajoSemestral(E1).pdf View File


doc/trabajoSemestral(E2).pdf → doc/Enunciados/trabajoSemestral(E2).pdf View File


BIN
doc/Enunciados/trabajoSemestral(E3).pdf View File


doc/Informe1.pdf → doc/Informes/Informe1.pdf View File


doc/Informe1.tex → doc/Informes/Informe1.tex View File


doc/Informe1_creartablas.sql → doc/Informes/Informe1_creartablas.sql View File


doc/Informe1_insertarduplas.sql → doc/Informes/Informe1_insertarduplas.sql View File


doc/Informe1corregido.pdf → doc/Informes/Informe1corregido.pdf View File


doc/Informe1corregido.tex → doc/Informes/Informe1corregido.tex View File


doc/Informe1corregido_creartablas.sql → doc/Informes/Informe1corregido_creartablas.sql View File


doc/Informe1corregido_insertarduplas.sql → doc/Informes/Informe1corregido_insertarduplas.sql View File


doc/Informe2.pdf → doc/Informes/Informe2.pdf View File


doc/Informe2.tex → doc/Informes/Informe2.tex View File


doc/Informe2_Q1.png → doc/Informes/Informe2_Q1.png View File


doc/Informe2_Q2.png → doc/Informes/Informe2_Q2.png View File


doc/Informe2_Q3.png → doc/Informes/Informe2_Q3.png View File


doc/Informe2_Q4.png → doc/Informes/Informe2_Q4.png View File


doc/Informe2_Q5.png → doc/Informes/Informe2_Q5.png View File


doc/Informe2_vistaQ1.sql → doc/Informes/Informe2_vistaQ1.sql View File


doc/Informe2_vistaQ2.sql → doc/Informes/Informe2_vistaQ2.sql View File


doc/Informe2_vistaQ3.sql → doc/Informes/Informe2_vistaQ3.sql View File


doc/Informe2_vistaQ4.sql → doc/Informes/Informe2_vistaQ4.sql View File


doc/Informe2_vistaQ5.sql → doc/Informes/Informe2_vistaQ5.sql View File


doc/MER.dia → doc/Informes/MER.dia View File


doc/MER.png → doc/Informes/MER.png View File


doc/MERcorregido.dia → doc/Informes/MERcorregido.dia View File


doc/MERcorregido.png → doc/Informes/MERcorregido.png View File


doc/ubblogo.png → doc/Informes/ubblogo.png View File


+ 11
- 5
doc/meson.build View File

@@ -1,6 +1,7 @@
1 1
 docs_enabled = get_option('valadocs')
2 2
 valadoc = find_program('valadoc', required: docs_enabled)
3 3
 vala_doc_sources = vala_sources
4
+vala_doc_sources += lib_sources
4 5
 if docs_enabled
5 6
 	valadocs_deps = get_option('valadocs_deps')
6 7
 	docs_deps = ['--pkg=gtk+-3.0']
@@ -29,10 +30,15 @@ if docs_enabled
29 30
 	)
30 31
 endif
31 32
 
32
-install_data('trabajoSemestral(E1).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
33
-install_data('trabajoSemestral(E2).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
34
-install_data('Informe1.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
35
-install_data('MER.dia', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
36
-install_data('MER.png', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
33
+install_data('Enunciados/trabajoSemestral(E1).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
34
+install_data('Enunciados/trabajoSemestral(E2).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
35
+install_data('Enunciados/trabajoSemestral(E3).pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
36
+install_data('Informes/Informe1.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
37
+install_data('Informes/Informe1corregido.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
38
+install_data('Informes/Informe2.pdf', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
39
+install_data('Informes/MER.dia', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
40
+install_data('Informes/MER.png', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
41
+install_data('Informes/MERcorregido.dia', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
42
+install_data('Informes/MERcorregido.png', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
37 43
 install_data('../LICENSE', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))
38 44
 install_data('../README.md', install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()))

+ 69
- 0
lib/db/arrienda.vala View File

@@ -0,0 +1,69 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Arrienda : GLib.Object {
7
+			public uint precio { get; set; default = 0; }
8
+			public string fecha_devolucion { get; set; default = ""; }
9
+			public Vehiculo vehiculo { get; set; default = null; }
10
+			public Empresa empresa { get; set; default = null; }
11
+
12
+			public Arrienda (uint precio = 0, string fecha_devolucion = "", Vehiculo? vehiculo = null, Empresa? empresa = null) {
13
+				this.precio = precio;
14
+				this.fecha_devolucion = fecha_devolucion;
15
+				this.vehiculo = vehiculo;
16
+				this.empresa = empresa;
17
+			}
18
+
19
+			public static Arrienda[]? get_all_arriendas(Database conn) {
20
+				var res = conn.exec ("
21
+SELECT A.precio, A.fecha_devolucion,
22
+V.patente, V.ano_vehiculo, V.marca, V.capacidad,
23
+E.rut_empresa, E.nombre_empresa, E.contacto, E.telefono
24
+FROM arrienda A
25
+JOIN vehiculo V ON (A.patente = V.patente)
26
+JOIN empresa E ON (A.rut_empresa = E.rut_empresa)
27
+				");
28
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
29
+					#if DEBUG
30
+						error (conn.get_error_message ());
31
+					#else
32
+						warning (conn.get_error_message ());
33
+						return null;
34
+					#endif
35
+				}
36
+
37
+				var wra = new ResultWrapper (res);
38
+				Arrienda[] arriendas = {};
39
+				int n = res.get_n_tuples ();
40
+				for (int i = 0; i < n; i++) {
41
+					try {
42
+						var arrienda = new Arrienda (wra.get_int_n (i, "precio"),
43
+							wra.get_string_n (i, "fecha_devolucion"),
44
+							new Vehiculo (wra.get_string_n (i, "patente"),
45
+								wra.get_int_n (i, "ano_vehiculo"),
46
+								wra.get_string_n (i, "marca"),
47
+								wra.get_int_n (i, "capacidad")
48
+							),
49
+							new Empresa (wra.get_string_n (i, "rut_empresa"),
50
+								wra.get_string_n (i, "nombre_empresa"),
51
+								wra.get_string_n (i, "contacto"),
52
+								wra.get_int_n (i, "telefono")
53
+							)
54
+						);
55
+						arriendas += arrienda;
56
+					}
57
+					catch (Error e) {
58
+						#if DEBUG
59
+							error (e.message);
60
+						#else
61
+							warning (e.message);
62
+						#endif
63
+					}
64
+				}
65
+				return arriendas;
66
+			}
67
+		}
68
+	}
69
+}

+ 94
- 0
lib/db/asociado.vala View File

@@ -0,0 +1,94 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Asociado : GLib.Object {
7
+			public string fecha_llegada { get; set; default = ""; }
8
+			public string hora_llegada { get; set; default = ""; }
9
+			public string fecha_salida { get; set; default = ""; }
10
+			public string hora_salida { get; set; default = ""; }
11
+			public Tour tour { get; set; default = null; }
12
+			public Lugar lugar { get; set; default = null; }
13
+
14
+			public Asociado (string fecha_llegada = "", string hora_llegada = "", string fecha_salida = "", string hora_salida = "", Tour? tour = null, Lugar? lugar = null) {
15
+				this.fecha_llegada = fecha_llegada;
16
+				this.hora_llegada = hora_llegada;
17
+				this.fecha_salida = fecha_salida;
18
+				this.hora_salida = hora_salida;
19
+			}
20
+
21
+			public static Asociado[]? get_all_asociados(Database conn) {
22
+				var res = conn.exec ("
23
+SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida
24
+T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
25
+C.id_ciudad, C.nombre_ciudad,
26
+R.id_region, R.nombre_region,
27
+L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel
28
+C2.id_ciudad AS id_ciudad_lugar, C2.nombre_ciudad AS nombre_ciudad_lugar,
29
+R2.id_region AS id_region_lugar, R2.nombre_region AS nombre_region_lugar
30
+FROM asociado A
31
+JOIN tour T ON (A.id_tour = T.id_tour)
32
+JOIN ciudad C ON (T.id_cuidad = C.id_ciudad)
33
+JOIN region R ON (C.id_region = R.id_region)
34
+JOIN lugar L ON (A.id_lugar = L.id_lugar)
35
+JOIN ciudad C2 ON (L.id_ciudad = C2.id_ciudad)
36
+JOIN region R2 ON (C2.id_region = R2.id_region)
37
+				");
38
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
39
+					#if DEBUG
40
+						error (conn.get_error_message ());
41
+					#else
42
+						warning (conn.get_error_message ());
43
+						return null;
44
+					#endif
45
+				}
46
+
47
+				var wra = new ResultWrapper (res);
48
+				Asociado[] asociados = {};
49
+				int n = res.get_n_tuples ();
50
+				for (int i = 0; i < n; i++) {
51
+					try {
52
+						var asociado = new Asociado (wra.get_string_n (i, "fecha_llegada"),
53
+							wra.get_string_n (i, "hora_llegada"),
54
+							wra.get_string_n (i, "fecha_salida"),
55
+							wra.get_string_n (i, "hora_salida"),
56
+							new Tour (wra.get_int_n (i, "id_tour"),
57
+								wra.get_string_n (i, "nombre_tour"),
58
+								wra.get_int_n (i, "costo_indiv"),
59
+								wra.get_int_n (i, "costo_grupal"),
60
+								wra.get_int_n (i, "minima_personas"),
61
+								new Ciudad (wra.get_int_n (i, "id_ciudad"),
62
+									wra.get_string_n (i, "nombre_ciudad"),
63
+									new Region (wra.get_int_n (i, "id_region"),
64
+										wra.get_string_n (i, "nombre_region")
65
+									)
66
+								)
67
+							),
68
+							new Lugar (wra.get_int_n (i, "id_lugar"),
69
+								wra.get_string_n (i, "nombre_tour"),
70
+								wra.get_int_n (i, "valor_entrada"),
71
+								wra.get_int_n (i, "nivel"),
72
+								new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"),
73
+									wra.get_string_n (i, "nombre_ciudad_lugar"),
74
+									new Region (wra.get_int_n (i, "id_region_lugar"),
75
+										wra.get_string_n (i, "nombre_region_lugar")
76
+									)
77
+								)
78
+							)
79
+						);
80
+						asociados += asociado;
81
+					}
82
+					catch (Error e) {
83
+						#if DEBUG
84
+							error (e.message);
85
+						#else
86
+							warning (e.message);
87
+						#endif
88
+					}
89
+				}
90
+				return asociados;
91
+			}
92
+		}
93
+	}
94
+}

+ 50
- 0
lib/db/categoria.vala View File

@@ -0,0 +1,50 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Categoria : GLib.Object {
7
+			public uint id_categoria { get; set; default = 0; }
8
+			public string descripcion_categoria { get; set; default = ""; }
9
+
10
+			public Categoria (uint id_categoria = 0, string descripcion_categoria = "") {
11
+				this.id_categoria = id_categoria;
12
+				this.descripcion_categoria = descripcion_categoria;
13
+			}
14
+
15
+			public static Categoria[]? get_all_categorias(Database conn) {
16
+				var res = conn.exec ("
17
+SELECT id_categoria, descripcion_categoria FROM categoria
18
+				");
19
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
20
+					#if DEBUG
21
+						error (conn.get_error_message ());
22
+					#else
23
+						warning (conn.get_error_message ());
24
+						return null;
25
+					#endif
26
+				}
27
+
28
+				var wra = new ResultWrapper (res);
29
+				Categoria[] categorias = {};
30
+				int n = res.get_n_tuples ();
31
+				for (int i = 0; i < n; i++) {
32
+					try {
33
+						var categoria = new Categoria (wra.get_int_n (i, "id_categoria"),
34
+							wra.get_string_n (i, "descripcion_categoria")
35
+						);
36
+						categorias += categoria;
37
+					}
38
+					catch (Error e) {
39
+						#if DEBUG
40
+							error (e.message);
41
+						#else
42
+							warning (e.message);
43
+						#endif
44
+					}
45
+				}
46
+				return categorias;
47
+			}
48
+		}
49
+	}
50
+}

+ 58
- 0
lib/db/ciudad.vala View File

@@ -0,0 +1,58 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Ciudad : GLib.Object {
7
+			public uint id_ciudad { get; set; default = 0; }
8
+			public string nombre_ciudad { get; set; default = ""; }
9
+			public Region region { get; set; default = null; }
10
+
11
+			public Ciudad (uint id_ciudad = 0, string nombre_ciudad = "", Region? region = null) {
12
+				this.id_ciudad = id_ciudad;
13
+				this.nombre_ciudad = nombre_ciudad;
14
+				this.region = region;
15
+			}
16
+
17
+			public static Ciudad[]? get_all_ciudades(Database conn) {
18
+				var res = conn.exec ("
19
+SELECT C.id_ciudad, C.nombre_ciudad,
20
+R.id_region, R.nombre_region
21
+FROM ciudad C
22
+JOIN region R ON (C.id_region = R.id_region)
23
+				");
24
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
25
+					#if DEBUG
26
+						error (conn.get_error_message ());
27
+					#else
28
+						warning (conn.get_error_message ());
29
+						return null;
30
+					#endif
31
+				}
32
+
33
+				var wra = new ResultWrapper (res);
34
+				Ciudad[] ciudades = {};
35
+				int n = res.get_n_tuples ();
36
+				for (int i = 0; i < n; i++) {
37
+					try {
38
+						var ciudad = new Ciudad (wra.get_int_n (i, "id_ciudad"),
39
+							wra.get_string_n (i, "nombre_ciudad"),
40
+							new Region (wra.get_int_n (i, "id_region"),
41
+								wra.get_string_n (i, "nombre_region")
42
+							)
43
+						);
44
+						ciudades += ciudad;
45
+					}
46
+					catch (Error e) {
47
+						#if DEBUG
48
+							error (e.message);
49
+						#else
50
+							warning (e.message);
51
+						#endif
52
+					}
53
+				}
54
+				return ciudades;
55
+			}
56
+		}
57
+	}
58
+}

+ 51
- 0
lib/db/contacto_emergencia.vala View File

@@ -0,0 +1,51 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class ContactoEmergencia : GLib.Object {
7
+			public uint id_contacto { get; set; default = 0; }
8
+			public uint telefono_emergencia { get; set; default = 0; }
9
+			public string nombre_emergencia { get; set; default = ""; }
10
+
11
+			public ContactoEmergencia (uint id_contacto = 0, uint telefono_emergencia = 0, string nombre_emergencia = "") {
12
+				this.id_contacto = id_contacto;
13
+				this.telefono_emergencia = telefono_emergencia;
14
+				this.nombre_emergencia = nombre_emergencia;
15
+			}
16
+
17
+			public static ContactoEmergencia[]? get_all_contactos(Database conn) {
18
+				var res = conn.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia");
19
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
20
+					#if DEBUG
21
+						error (conn.get_error_message ());
22
+					#else
23
+						warning (conn.get_error_message ());
24
+						return null;
25
+					#endif
26
+				}
27
+
28
+				var wra = new ResultWrapper (res);
29
+				ContactoEmergencia[] contactos = {};
30
+				int n = res.get_n_tuples ();
31
+				for (int i = 0; i < n; i++) {
32
+					try {
33
+						var contacto = new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
34
+							wra.get_int_n (i, "telefono_emergencia"),
35
+							wra.get_string_n (i, "nombre_emergencia")
36
+						);
37
+						contactos += contacto;
38
+					}
39
+					catch (Error e) {
40
+						#if DEBUG
41
+							error (e.message);
42
+						#else
43
+							warning (e.message);
44
+						#endif
45
+					}
46
+				}
47
+				return contactos;
48
+			}
49
+		}
50
+	}
51
+}

+ 53
- 0
lib/db/descuento.vala View File

@@ -0,0 +1,53 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Descuento : GLib.Object {
7
+			public uint id_descuento { get; set; default = 0; }
8
+			public string descripcion_descuento { get; set; default = ""; }
9
+			public float porcentaje { get; set; default = 0; }
10
+
11
+			public Descuento (uint id_descuento = 0, string descripcion_descuento = "", float porcentaje = 0) {
12
+				this.id_descuento = id_descuento;
13
+				this.descripcion_descuento = descripcion_descuento;
14
+				this.porcentaje = porcentaje;
15
+			}
16
+
17
+			public static Descuento[]? get_all_descuentos(Database conn) {
18
+				var res = conn.exec ("
19
+SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento
20
+				");
21
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
22
+					#if DEBUG
23
+						error (conn.get_error_message ());
24
+					#else
25
+						warning (conn.get_error_message ());
26
+						return null;
27
+					#endif
28
+				}
29
+
30
+				var wra = new ResultWrapper (res);
31
+				Descuento[] descuentos = {};
32
+				int n = res.get_n_tuples ();
33
+				for (int i = 0; i < n; i++) {
34
+					try {
35
+						var descuento = new Descuento (wra.get_int_n (i, "id_descuento"),
36
+							wra.get_string_n (i, "descripcion_descuento"),
37
+							wra.get_float_n (i, "porcentaje")
38
+						);
39
+						descuentos += descuento;
40
+					}
41
+					catch (Error e) {
42
+						#if DEBUG
43
+							error (e.message);
44
+						#else
45
+							warning (e.message);
46
+						#endif
47
+					}
48
+				}
49
+				return descuentos;
50
+			}
51
+		}
52
+	}
53
+}

+ 56
- 0
lib/db/empresa.vala View File

@@ -0,0 +1,56 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Empresa : GLib.Object {
7
+			public string rut_empresa { get; set; default = ""; }
8
+			public string nombre_empresa { get; set; default = ""; }
9
+			public string contacto { get; set; default = ""; }
10
+			public uint telefono { get; set; default = 0; }
11
+
12
+			public Empresa (string rut_empresa = "", string nombre_empresa = "", string contacto = "", uint telefono = 0) {
13
+				this.rut_empresa = rut_empresa;
14
+				this.nombre_empresa = nombre_empresa;
15
+				this.contacto = contacto;
16
+				this.telefono = telefono;
17
+			}
18
+
19
+			public static Empresa[]? get_all_empresas(Database conn) {
20
+				var res = conn.exec ("
21
+SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa
22
+				");
23
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
24
+					#if DEBUG
25
+						error (conn.get_error_message ());
26
+					#else
27
+						warning (conn.get_error_message ());
28
+						return null;
29
+					#endif
30
+				}
31
+
32
+				var wra = new ResultWrapper (res);
33
+				Empresa[] empresas = {};
34
+				int n = res.get_n_tuples ();
35
+				for (int i = 0; i < n; i++) {
36
+					try {
37
+						var empresa = new Empresa (wra.get_string_n (i, "rut_empresa"),
38
+							wra.get_string_n (i, "nombre_empresa"),
39
+							wra.get_string_n (i, "contacto"),
40
+							wra.get_int_n (i, "telefono")
41
+						);
42
+						empresas += empresa;
43
+					}
44
+					catch (Error e) {
45
+						#if DEBUG
46
+							error (e.message);
47
+						#else
48
+							warning (e.message);
49
+						#endif
50
+					}
51
+				}
52
+				return empresas;
53
+			}
54
+		}
55
+	}
56
+}

+ 50
- 0
lib/db/enfermedad.vala View File

@@ -0,0 +1,50 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Enfermedad : GLib.Object {
7
+			public uint id_enfermedad { get; set; default = 0; }
8
+			public string descripcion_enfermedad { get; set; default = ""; }
9
+
10
+			public Enfermedad (uint id_enfermedad = 0, string descripcion_enfermedad = "") {
11
+				this.id_enfermedad = id_enfermedad;
12
+				this.descripcion_enfermedad = descripcion_enfermedad;
13
+			}
14
+
15
+			public static Enfermedad[]? get_all_enfermedades(Database conn) {
16
+				var res = conn.exec ("
17
+SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad
18
+				");
19
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
20
+					#if DEBUG
21
+						error (conn.get_error_message ());
22
+					#else
23
+						warning (conn.get_error_message ());
24
+						return null;
25
+					#endif
26
+				}
27
+
28
+				var wra = new ResultWrapper (res);
29
+				Enfermedad[] enfermedades = {};
30
+				int n = res.get_n_tuples ();
31
+				for (int i = 0; i < n; i++) {
32
+					try {
33
+						var enfermedad = new Enfermedad (wra.get_int_n (i, "id_enfermedad"),
34
+							wra.get_string_n (i, "descripcion_enfermedad")
35
+						);
36
+						enfermedades += enfermedad;
37
+					}
38
+					catch (Error e) {
39
+						#if DEBUG
40
+							error (e.message);
41
+						#else
42
+							warning (e.message);
43
+						#endif
44
+					}
45
+				}
46
+				return enfermedades;
47
+			}
48
+		}
49
+	}
50
+}

+ 50
- 0
lib/db/especialidad.vala View File

@@ -0,0 +1,50 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Especialidad : GLib.Object {
7
+			public uint id_especialidad { get; set; default = 0; }
8
+			public string descripcion_especialidad { get; set; default = ""; }
9
+
10
+			public Especialidad (uint id_especialidad = 0, string descripcion_especialidad = "") {
11
+				this.id_especialidad = id_especialidad;
12
+				this.descripcion_especialidad = descripcion_especialidad;
13
+			}
14
+
15
+			public static Especialidad[]? get_all_especialidades(Database conn) {
16
+				var res = conn.exec ("
17
+SELECT id_especialidad, descripcion_especialidad FROM especialidad
18
+				");
19
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
20
+					#if DEBUG
21
+						error (conn.get_error_message ());
22
+					#else
23
+						warning (conn.get_error_message ());
24
+						return null;
25
+					#endif
26
+				}
27
+
28
+				var wra = new ResultWrapper (res);
29
+				Especialidad[] especialidades = {};
30
+				int n = res.get_n_tuples ();
31
+				for (int i = 0; i < n; i++) {
32
+					try {
33
+						var especialidad = new Especialidad (wra.get_int_n (i, "id_especialidad"),
34
+							wra.get_string_n (i, "descripcion_especialidad")
35
+						);
36
+						especialidades += especialidad;
37
+					}
38
+					catch (Error e) {
39
+						#if DEBUG
40
+							error (e.message);
41
+						#else
42
+							warning (e.message);
43
+						#endif
44
+					}
45
+				}
46
+				return especialidades;
47
+			}
48
+		}
49
+	}
50
+}

+ 69
- 0
lib/db/guia.vala View File

@@ -0,0 +1,69 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Guia : GLib.Object {
7
+			public string rut_guia { get; set; default = ""; }
8
+			public string nombre_guia { get; set; default = ""; }
9
+			public string calle { get; set; default = ""; }
10
+			public uint numero { get; set; default = 0; }
11
+			public Ciudad ciudad { get; set; default = null; }
12
+
13
+			public Guia (string rut_guia = "", string nombre_guia = "", string calle = "", uint numero = 0, Ciudad? ciudad = null) {
14
+				this.rut_guia = rut_guia;
15
+				this.nombre_guia = nombre_guia;
16
+				this.calle = calle;
17
+				this.numero = numero;
18
+				this.ciudad = ciudad;
19
+			}
20
+
21
+			public static Guia[]? get_all_guias(Database conn) {
22
+				var res = conn.exec ("
23
+SELECT G.rut_guia, G.nombre_guia, G.calle, G.numero,
24
+C.id_ciudad, C.nombre_ciudad,
25
+R.id_region, R.nombre_region
26
+FROM guia G
27
+JOIN ciudad C ON (G.id_ciudad = C.id_ciudad)
28
+JOIN region R ON (C.id_region = R.id_region)
29
+				");
30
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
31
+					#if DEBUG
32
+						error (conn.get_error_message ());
33
+					#else
34
+						warning (conn.get_error_message ());
35
+						return null;
36
+					#endif
37
+				}
38
+
39
+				var wra = new ResultWrapper (res);
40
+				Guia[] guias = {};
41
+				int n = res.get_n_tuples ();
42
+				for (int i = 0; i < n; i++) {
43
+					try {
44
+						var guia = new Guia	(wra.get_string_n (i, "rut_guia"),
45
+							wra.get_string_n (i, "nombre_guia"),
46
+							wra.get_string_n (i, "calle"),
47
+							wra.get_int_n (i, "numero"),
48
+							new Ciudad (wra.get_int_n (i, "id_ciudad"),
49
+								wra.get_string_n (i, "nombre_ciudad"),
50
+								new Region (wra.get_int_n (i, "id_region"),
51
+									wra.get_string_n (i, "nombre_region")
52
+								)
53
+							)
54
+						);
55
+						guias += guia;
56
+					}
57
+					catch (Error e) {
58
+						#if DEBUG
59
+							error (e.message);
60
+						#else
61
+							warning (e.message);
62
+						#endif
63
+					}
64
+				}
65
+				return guias;
66
+			}
67
+		}
68
+	}
69
+}

+ 69
- 0
lib/db/lugar.vala View File

@@ -0,0 +1,69 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Lugar : GLib.Object {
7
+			public uint id_lugar { get; set; default = 0; }
8
+			public string nombre_lugar { get; set; default = ""; }
9
+			public uint valor_entrada { get; set; default = 0; }
10
+			public uint nivel { get; set; default = 0; }
11
+			public Ciudad ciudad { get; set; default = null; }
12
+
13
+			public Lugar (uint id_lugar = 0, string nombre_lugar = "", uint valor_entrada = 0, uint nivel = 0, Ciudad? ciudad = null) {
14
+				this.id_lugar = id_lugar;
15
+				this.nombre_lugar = nombre_lugar;
16
+				this.valor_entrada = valor_entrada;
17
+				this.nivel = nivel;
18
+				this.ciudad = ciudad;
19
+			}
20
+
21
+			public static Lugar[]? get_all_lugares(Database conn) {
22
+				var res = conn.exec ("
23
+SELECT L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel,
24
+C.id_ciudad, C.nombre_ciudad,
25
+R.id_region, R.nombre_region
26
+FROM lugar L
27
+JOIN ciudad C ON (L.id_ciudad = C.id_ciudad)
28
+JOIN region R ON (C.id_region = R.id_region)
29
+				");
30
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
31
+					#if DEBUG
32
+						error (conn.get_error_message ());
33
+					#else
34
+						warning (conn.get_error_message ());
35
+						return null;
36
+					#endif
37
+				}
38
+
39
+				var wra = new ResultWrapper (res);
40
+				Lugar[] lugares = {};
41
+				int n = res.get_n_tuples ();
42
+				for (int i = 0; i < n; i++) {
43
+					try {
44
+						var lugar = new Lugar (wra.get_int_n (i, "id_lugar"),
45
+							wra.get_string_n (i, "nombre_lugar"),
46
+							wra.get_int_n (i, "valor_entrada"),
47
+							wra.get_int_n (i, "nivel"),
48
+							new Ciudad (wra.get_int_n (i, "id_ciudad"),
49
+								wra.get_string_n (i, "nombre_ciudad"),
50
+								new Region(wra.get_int_n (i, "id_region"),
51
+									wra.get_string_n (i, "nombre_region")
52
+								)
53
+							)
54
+						);
55
+						lugares += lugar;
56
+					}
57
+					catch (Error e) {
58
+						#if DEBUG
59
+							error (e.message);
60
+						#else
61
+							warning (e.message);
62
+						#endif
63
+					}
64
+				}
65
+				return lugares;
66
+			}
67
+		}
68
+	}
69
+}

+ 90
- 0
lib/db/participa.vala View File

@@ -0,0 +1,90 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Participa : GLib.Object {
7
+			public Tour tour { get; set; default = null; }
8
+			public Guia guia { get; set; default = null; }
9
+			public Categoria categoria { get; set; default = null; }
10
+
11
+			public Participa (Tour? tour = null, Guia? guia = null, Categoria? categoria = null) {
12
+				this.tour = tour;
13
+				this.guia = guia;
14
+				this.categoria = categoria;
15
+			}
16
+
17
+			public static Participa[]? get_all_participas(Database conn) {
18
+				var res = conn.exec ("
19
+SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
20
+C.id_ciudad, C.nombre_ciudad,
21
+R.id_region, R.nombre_region,
22
+G.rut_guia, G.nombre_guia, G.calle, G.numero,
23
+C2.id_ciudad AS id_ciudad_guia, C2.nombre_ciudad AS nombre_ciudad_guia,
24
+R2.id_region AS id_region_guia, R2.nombre_region AS nombre_region_guia,
25
+C3.id_categoria, C3.descripcion_categoria
26
+FROM participa P
27
+JOIN tour T ON (P.id_tour = T.id_tour)
28
+JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
29
+JOIN region R on (C.id_region = R.id_region)
30
+JOIN guia G on (P.rut_guia = G.rut_guia)
31
+JOIN ciudad C2 ON (G.id_ciudad = C2.id_ciudad)
32
+JOIN region R2 ON (C2.id_region = R2.id_region)
33
+JOIN categoria C3 ON (P.id_categoria = C3.id_categoria)
34
+				");
35
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
36
+					#if DEBUG
37
+						error (conn.get_error_message ());
38
+					#else
39
+						warning (conn.get_error_message ());
40
+						return null;
41
+					#endif
42
+				}
43
+
44
+				var wra = new ResultWrapper(res);
45
+				Participa[] participas = {};
46
+				int n = res.get_n_tuples ();
47
+				for (int i = 0; i < n; i++) {
48
+					try {
49
+						var participa = new Participa (
50
+							new Tour (wra.get_int_n (i, "id_tour"),
51
+								wra.get_string_n (i, "nombre_tour"),
52
+								wra.get_int_n (i, "costo_indiv"),
53
+								wra.get_int_n (i, "costo_grupal"),
54
+								wra.get_int_n (i, "minima_personas"),
55
+								new Ciudad (wra.get_int_n (i, "id_ciudad"),
56
+									wra.get_string_n (i, "nombre_ciudad"),
57
+									new Region (wra.get_int_n (i, "id_region"),
58
+										wra.get_string_n (i, "nombre_region")
59
+									)
60
+								)
61
+							),
62
+							new Guia (wra.get_string_n (i, "rut_guia"),
63
+								wra.get_string_n (i, "nombre_guia"),
64
+								wra.get_string_n (i, "calle"),
65
+								wra.get_int_n (i, "numero"),
66
+								new Ciudad (wra.get_int_n (i, "id_ciudad_guia"),
67
+									wra.get_string_n (i, "id_region_guia"),
68
+									new Region (wra.get_int_n (i, "id_region_guia"),
69
+										wra.get_string_n (i, "nombre_region_guia"))
70
+									)
71
+								),
72
+							new Categoria (wra.get_int_n (i, "id_categoria"),
73
+								wra.get_string_n (i, "descripcion_categoria")
74
+							)
75
+						);
76
+						participas += participa;
77
+					}
78
+					catch (Error e) {
79
+						#if DEBUG
80
+							error (e.message);
81
+						#else
82
+							warning (e.message);
83
+						#endif
84
+					}
85
+				}
86
+				return participas;
87
+			}
88
+		}
89
+	}
90
+}

+ 74
- 0
lib/db/posee.vala View File

@@ -0,0 +1,74 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Posee : GLib.Object {
7
+			public uint nivel_especialidad { get; set; default = 0; }
8
+			public Guia guia { get; set; default = null; }
9
+			public Especialidad especialidad { get; set; default = null; }
10
+
11
+			public Posee (uint nivel_especialidad = 0, Guia? guia = null, Especialidad? especialidad = null) {
12
+				this.nivel_especialidad = nivel_especialidad;
13
+				this.guia = guia;
14
+				this.especialidad = especialidad;
15
+			}
16
+
17
+			public static Posee[]? get_all_posees(Database conn) {
18
+				var res = conn.exec ("
19
+SELECT P.nivel_especialidad,
20
+G.rut_guia, G.nombre_guia, G.calle, G.numero,
21
+C.id_ciudad, C.nombre_ciudad,
22
+R.id_region, R.nombre_region,
23
+E.id_especialidad, E.descripcion_especialidad
24
+FROM posee P
25
+JOIN guia G on (P.rut_guia = G.rut_guia)
26
+JOIN ciudad C ON (G.id_ciudad = C.id_ciudad)
27
+JOIN region R ON (C.id_region = R.id_region)
28
+JOIN especialidad E ON (P.id_especialidad = E.id_especialidad)
29
+				");
30
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
31
+					#if DEBUG
32
+						error (conn.get_error_message ());
33
+					#else
34
+						warning (conn.get_error_message ());
35
+						return null;
36
+					#endif
37
+				}
38
+
39
+				var wra = new ResultWrapper (res);
40
+				Posee[] posees = {};
41
+				int n = res.get_n_tuples ();
42
+				for (int i = 0; i < n; i++) {
43
+					try {
44
+						var posee = new Posee (wra.get_int_n (i, "nivel_especialidad"),
45
+							new Guia (wra.get_string_n (i, "rut_guia"),
46
+								wra.get_string_n (i, "nombre_guia"),
47
+								wra.get_string_n (i, "calle"),
48
+								wra.get_int_n (i, "numero"),
49
+								new Ciudad (wra.get_int_n (i, "id_ciudad"),
50
+									wra.get_string_n (i, "nombre_ciudad"),
51
+									new Region (wra.get_int_n (i, "id_region"),
52
+										wra.get_string_n (i, "nombre_region")
53
+									)
54
+								)
55
+							),
56
+							new Especialidad (wra.get_int_n (i, "id_especialidad"),
57
+								wra.get_string_n (i, "descripcion_especialidad")
58
+							)
59
+						);
60
+						posees += posee;
61
+					}
62
+					catch (Error e) {
63
+						#if DEBUG
64
+							error (e.message);
65
+						#else
66
+							warning (e.message);
67
+						#endif
68
+					}
69
+				}
70
+				return posees;
71
+			}
72
+		}
73
+	}
74
+}

+ 87
- 0
lib/db/realiza.vala View File

@@ -0,0 +1,87 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Realiza : GLib.Object {
7
+			public Tour tour { get; set; default = null; }
8
+			public Turista turista { get; set; default = null; }
9
+			public Descuento descuento { get; set; default = null; }
10
+
11
+			public Realiza (Tour? tour = null, Turista? turista = null, Descuento? descuento = null) {
12
+				this.tour = tour;
13
+				this.turista = turista;
14
+				this.descuento = descuento;
15
+			}
16
+
17
+			public static Realiza[]? get_all_realizas(Database conn) {
18
+				var res = conn.exec ("
19
+SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
20
+C.id_ciudad, C.nombre_ciudad,
21
+R.id_region, R.nombre_region,
22
+T2.rut_turista, T2.nombre_turista, T2.fecha_nacimento,
23
+C2.id_contacto, C2.telefono_emergencia, C2.nombre_emergencia,
24
+D.id_descuento, D.descripcion_descuento, D.porcentaje
25
+FROM realiza RE
26
+JOIN tour T ON (RE.id_tour = T.id_tour)
27
+JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
28
+JOIN region R ON (C.id_region = R.id_region)
29
+JOIN turista T2 ON (RE.rut_turista = T2.rut_turista)
30
+JOIN contacto_emergencia C2 ON (T2.id_contacto = C2.id_contacto)
31
+JOIN descuento D ON (RE.id_descuento = D.id_descuento)
32
+				");
33
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
34
+					#if DEBUG
35
+						error (conn.get_error_message ());
36
+					#else
37
+						warning (conn.get_error_message ());
38
+						return null;
39
+					#endif
40
+				}
41
+
42
+				var wra = new ResultWrapper (res);
43
+				Realiza[] realizas = {};
44
+				int n = res.get_n_tuples ();
45
+				for (int i = 0; i < n; i++) {
46
+					try {
47
+						var realiza = new Realiza (
48
+							new Tour (wra.get_int_n (i, "id_tour"),
49
+								wra.get_string_n (i, "nombre_tour"),
50
+								wra.get_int_n (i, "costo_indiv"),
51
+								wra.get_int_n (i, "costo_grupal"),
52
+								wra.get_int_n (i, "minima_personas"),
53
+								new Ciudad (wra.get_int_n (i, "id_ciudad"),
54
+									wra.get_string_n (i, "nombre_ciudad"),
55
+									new Region (wra.get_int_n (i, "id_region"),
56
+										wra.get_string_n (i, "nombre_region")
57
+									)
58
+								)
59
+							),
60
+							new Turista (wra.get_string_n (i, "rut_turista"),
61
+								wra.get_string_n (i, "nombre_turista"),
62
+								wra.get_string_n (i, "fecha_nacimento"),
63
+								new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
64
+									wra.get_int_n (i, "telefono_emergencia"),
65
+									wra.get_string_n (i, "nombre_emergencia")
66
+								)
67
+							),
68
+							new Descuento (wra.get_int_n (i, "id_descuento"),
69
+								wra.get_string_n (i, "descripcion_descuento"),
70
+								wra.get_float_n (i, "porcentaje")
71
+							)
72
+						);
73
+						realizas += realiza;
74
+					}
75
+					catch (Error e) {
76
+						#if DEBUG
77
+							error (e.message);
78
+						#else
79
+							warning (e.message);
80
+						#endif
81
+					}
82
+				}
83
+				return realizas;
84
+			}
85
+		}
86
+	}
87
+}

+ 50
- 0
lib/db/region.vala View File

@@ -0,0 +1,50 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Region : GLib.Object {
7
+			public uint id_region { get; set; default = 0; }
8
+			public string nombre_region { get; set; default = ""; }
9
+
10
+			public Region (uint id_region = 0, string nombre_region = "") {
11
+				this.id_region = id_region;
12
+				this.nombre_region = nombre_region;
13
+			}
14
+
15
+			public static Region[]? get_all_regiones(Database conn) {
16
+				var res = conn.exec ("
17
+SELECT id_region, nombre_region FROM region
18
+				");
19
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
20
+					#if DEBUG
21
+						error (conn.get_error_message ());
22
+					#else
23
+						warning (conn.get_error_message ());
24
+						return null;
25
+					#endif
26
+				}
27
+
28
+				var wra = new ResultWrapper (res);
29
+				Region[] regiones = {};
30
+				int n = res.get_n_tuples ();
31
+				for (int i = 0; i < n; i++) {
32
+					try {
33
+						var region = new Region (wra.get_int_n (i, "id_region"),
34
+							wra.get_string_n (i, "nombre_region")
35
+						);
36
+						regiones += region;
37
+					}
38
+					catch (Error e) {
39
+						#if DEBUG
40
+							error (e.message);
41
+						#else
42
+							warning (e.message);
43
+						#endif
44
+					}
45
+				}
46
+				return regiones;
47
+			}
48
+		}
49
+	}
50
+}

+ 77
- 0
lib/db/requerir_auto.vala View File

@@ -0,0 +1,77 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class RequerirAuto : GLib.Object {
7
+			public string chofer { get; set; default = ""; }
8
+			public Tour tour { get; set; default = null; }
9
+			public Vehiculo vehiculo { get; set; default = null; }
10
+
11
+			public RequerirAuto (string chofer = "", Tour? tour = null, Vehiculo? vehiculo = null) {
12
+				this.chofer = chofer;
13
+				this.tour = tour;
14
+				this.vehiculo = vehiculo;
15
+			}
16
+
17
+			public static RequerirAuto[]? get_all_requerir_autos(Database conn) {
18
+				var res = conn.exec ("
19
+SELECT R.chofer,
20
+T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
21
+C.id_ciudad, C.nombre_ciudad,
22
+R2.id_region, R2.nombre_region,
23
+V.patente, V.ano_vehiculo, V.marca, V.capacidad
24
+FROM requerir_auto R
25
+JOIN tour T ON (R.id_tour = T.id_tour)
26
+JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
27
+JOIN region R2 ON (C.id_region = R2.id_region)
28
+Join vehiculo V ON (R.patente = V.patente)
29
+				");
30
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
31
+					#if DEBUG
32
+						error (conn.get_error_message ());
33
+					#else
34
+						warning (conn.get_error_message ());
35
+						return null;
36
+					#endif
37
+				}
38
+
39
+				var wra = new ResultWrapper(res);
40
+				RequerirAuto[] requerir_autos = {};
41
+				int n = res.get_n_tuples ();
42
+				for (int i = 0; i < n; i++) {
43
+					try {
44
+						var requerir_auto = new RequerirAuto (wra.get_string_n (i, "chofer"),
45
+							new Tour (wra.get_int_n (i, "id_tour"),
46
+								wra.get_string_n (i, "nombre_tour"),
47
+								wra.get_int_n (i, "costo_indiv"),
48
+								wra.get_int_n (i, "costo_grupal"),
49
+								wra.get_int_n (i, "minima_personas"),
50
+								new Ciudad (wra.get_int_n (i, "id_ciudad"),
51
+									wra.get_string_n (i, "nombre_ciudad"),
52
+									new Region (wra.get_int_n (i, "id_region"),
53
+										wra.get_string_n (i, "nombre_region")
54
+									)
55
+								)
56
+							),
57
+							new Vehiculo (wra.get_string_n (i, "patente"),
58
+								wra.get_int_n (i, "ano_vehiculo"),
59
+								wra.get_string_n (i, "marca"),
60
+								wra.get_int_n (i, "capacidad")
61
+							)
62
+						);
63
+						requerir_autos += requerir_auto;
64
+					}
65
+					catch (Error e) {
66
+						#if DEBUG
67
+							error (e.message);
68
+						#else
69
+							warning (e.message);
70
+						#endif
71
+					}
72
+				}
73
+				return requerir_autos;
74
+			}
75
+		}
76
+	}
77
+}

+ 66
- 0
lib/db/tiene_enfermedad.vala View File

@@ -0,0 +1,66 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class TieneEnfermedad : GLib.Object {
7
+			public Turista turista { get; set; default = null; }
8
+			public Enfermedad enfermedad { get; set; default = null; }
9
+
10
+			public TieneEnfermedad (Turista? turista = null, Enfermedad? enfermedad = null) {
11
+				this.turista = turista;
12
+				this.enfermedad = enfermedad;
13
+			}
14
+
15
+			public static TieneEnfermedad[]? get_all_tiene_enfermedades(Database conn) {
16
+				var res = conn.exec ("
17
+SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
18
+C.id_contacto, C.telefono_emergencia, C.nombre_emergencia,
19
+E.id_enfermedad, E.descripcion_enfermedad
20
+FROM tiene_enfermedad TE
21
+JOIN turista T ON (TE.rut_turista = T.rut_turista)
22
+JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto)
23
+JOIN enfermedad E ON (TE.id_enfermedad = E.id_enfermedad)
24
+				");
25
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
26
+					#if DEBUG
27
+						error (conn.get_error_message ());
28
+					#else
29
+						warning (conn.get_error_message ());
30
+						return null;
31
+					#endif
32
+				}
33
+
34
+				var wra = new ResultWrapper (res);
35
+				TieneEnfermedad[] tiene_enfermedades = {};
36
+				int n = res.get_n_tuples ();
37
+				for (int i = 0; i < n; i++) {
38
+					try {
39
+						var tiene_enfermedad = new TieneEnfermedad (
40
+							new Turista (wra.get_string_n (i, "rut_turista"),
41
+								wra.get_string_n (i, "nombre_turista"),
42
+								wra.get_string_n (i, "fecha_nacimento"),
43
+								new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
44
+									wra.get_int_n (i, "telefono_emergencia"),
45
+									wra.get_string_n (i, "nombre_emergencia")
46
+								)
47
+							),
48
+							new Enfermedad (wra.get_int_n (i, "id_enfermedad"),
49
+								wra.get_string_n (i, "descripcion_enfermedad")
50
+							)
51
+						);
52
+						tiene_enfermedades += tiene_enfermedad;
53
+					}
54
+					catch (Error e) {
55
+						#if DEBUG
56
+							error (e.message);
57
+						#else
58
+							warning (e.message);
59
+						#endif
60
+					}
61
+				}
62
+				return tiene_enfermedades;
63
+			}
64
+		}
65
+	}
66
+}

+ 72
- 0
lib/db/tour.vala View File

@@ -0,0 +1,72 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Tour : GLib.Object {
7
+			public uint id_tour { get; set; default = 0; }
8
+			public string nombre_tour { get; set; default = ""; }
9
+			public uint costo_indiv { get; set; default = 0; }
10
+			public uint costo_grupal { get; set; default = 0; }
11
+			public uint minima_personas { get; set; default = 0; }
12
+			public Ciudad ciudad { get; set; default = null; }
13
+
14
+			public Tour (uint id_tour = 0, string nombre_tour = "", uint costo_indiv = 0, uint costo_grupal = 0, uint minima_personas = 0, Ciudad? ciudad = null) {
15
+				this.id_tour = id_tour;
16
+				this.nombre_tour = nombre_tour;
17
+				this.costo_indiv = costo_indiv;
18
+				this.costo_grupal = costo_grupal;
19
+				this.minima_personas = minima_personas;
20
+				this.ciudad = ciudad;
21
+			}
22
+
23
+			public static Tour[]? get_all_tours(Database conn) {
24
+				var res = conn.exec ("
25
+SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
26
+C.id_ciudad, C.nombre_ciudad,
27
+R.id_region, R.nombre_region
28
+FROM tour T
29
+JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
30
+JOIN region R ON (C.id_region = R.id_region)
31
+				");
32
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
33
+					#if DEBUG
34
+						error (conn.get_error_message ());
35
+					#else
36
+						warning (conn.get_error_message ());
37
+						return null;
38
+					#endif
39
+				}
40
+
41
+				var wra = new ResultWrapper (res);
42
+				Tour[] tours = {};
43
+				int n = res.get_n_tuples ();
44
+				for (int i = 0; i < n; i++) {
45
+					try {
46
+						var tour = new Tour (wra.get_int_n (i, "id_tour"),
47
+							wra.get_string_n (i, "nombre_tour"),
48
+							wra.get_int_n (i, "costo_indiv"),
49
+							wra.get_int_n (i, "costo_grupal"),
50
+							wra.get_int_n (i, "minima_personas"),
51
+							new Ciudad (wra.get_int_n (i, "id_ciudad"),
52
+								wra.get_string_n (i, "nombre_ciudad"),
53
+								new Region (wra.get_int_n (i, "id_region"),
54
+									wra.get_string_n (i, "nombre_region")
55
+								)
56
+							)
57
+						);
58
+						tours += tour;
59
+					}
60
+					catch (Error e) {
61
+						#if DEBUG
62
+							error (e.message);
63
+						#else
64
+							warning (e.message);
65
+						#endif
66
+					}
67
+				}
68
+				return tours;
69
+			}
70
+		}
71
+	}
72
+}

+ 62
- 0
lib/db/turista.vala View File

@@ -0,0 +1,62 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Turista : GLib.Object {
7
+			public string rut_turista { get; set; default = ""; }
8
+			public string nombre_turista { get; set; default = ""; }
9
+			public string fecha_nacimento { get; set; default = ""; }
10
+			public ContactoEmergencia contacto_emergencia { get; set; default = null; }
11
+
12
+			public Turista (string rut_turista = "", string nombre_turista = "", string fecha_nacimento = "", ContactoEmergencia? contacto_emergencia = null) {
13
+				this.rut_turista = rut_turista;
14
+				this.nombre_turista = nombre_turista;
15
+				this.fecha_nacimento = fecha_nacimento;
16
+				this.contacto_emergencia = contacto_emergencia;
17
+			}
18
+
19
+			public static Turista[]? get_all_turistas(Database conn) {
20
+				var res = conn.exec ("
21
+SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
22
+C.id_contacto, C.telefono_emergencia, C.nombre_emergencia
23
+FROM turista T
24
+JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto)
25
+				");
26
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
27
+					#if DEBUG
28
+						error (conn.get_error_message ());
29
+					#else
30
+						warning (conn.get_error_message ());
31
+						return null;
32
+					#endif
33
+				}
34
+
35
+				var wra = new ResultWrapper (res);
36
+				Turista[] turistas = {};
37
+				int n = res.get_n_tuples ();
38
+				for (int i = 0; i < n; i++) {
39
+					try {
40
+						var turista = new Turista (wra.get_string_n (i, "rut_turista"),
41
+							wra.get_string_n (i, "nombre_turista"),
42
+							wra.get_string_n (i, "fecha_nacimento"),
43
+							new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
44
+								wra.get_int_n (i, "telefono_emergencia"),
45
+								wra.get_string_n (i, "nombre_emergencia")
46
+							)
47
+						);
48
+						turistas += turista;
49
+					}
50
+					catch (Error e) {
51
+						#if DEBUG
52
+							error (e.message);
53
+						#else
54
+							warning (e.message);
55
+						#endif
56
+					}
57
+				}
58
+				return turistas;
59
+			}
60
+		}
61
+	}
62
+}

+ 56
- 0
lib/db/vehiculo.vala View File

@@ -0,0 +1,56 @@
1
+namespace Sernatur {
2
+	namespace DB {
3
+		using Postgres;
4
+		using Wrapper;
5
+
6
+		public class Vehiculo : GLib.Object {
7
+			public string patente { get; set; default = ""; }
8
+			public uint ano_vehiculo { get; set; default = 0; }
9
+			public string marca { get; set; default = ""; }
10
+			public uint capacidad { get; set; default = 0; }
11
+
12
+			public Vehiculo (string patente = "", uint ano_vehiculo = 0, string marca = "", uint capacidad = 0) {
13
+				this.patente = patente;
14
+				this.ano_vehiculo = ano_vehiculo;
15
+				this.marca = marca;
16
+				this.capacidad = capacidad;
17
+			}
18
+
19
+			public static Vehiculo[]? get_all_vehiculos(Database conn) {
20
+				var res = conn.exec ("
21
+SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo
22
+				");
23
+				if (res.get_status () != ExecStatus.TUPLES_OK) {
24
+					#if DEBUG
25
+						error (conn.get_error_message ());
26
+					#else
27
+						warning (conn.get_error_message ());
28
+						return null;
29
+					#endif
30
+				}
31
+
32
+				var wra = new ResultWrapper (res);
33
+				Vehiculo[] vehiculos = {};
34
+				int n = res.get_n_tuples ();
35
+				for (int i = 0; i < n; i++) {
36
+					try {
37
+						var vehiculo = new Vehiculo (wra.get_string_n (i, "patente"),
38
+							wra.get_int_n (i, "ano_vehiculo"),
39
+							wra.get_string_n (i, "marca"),
40
+							wra.get_int_n (i, "capacidad")
41
+						);
42
+						vehiculos += vehiculo;
43
+					}
44
+					catch (Error e) {
45
+						#if DEBUG
46
+							error (e.message);
47
+						#else
48
+							warning (e.message);
49
+						#endif
50
+					}
51
+				}
52
+				return vehiculos;
53
+			}
54
+		}
55
+	}
56
+}

+ 64
- 0
lib/dbwrapper.vala View File

@@ -0,0 +1,64 @@
1
+namespace Sernatur {
2
+	/**
3
+	 * This is the database namespace for Sernatur
4
+	 */
5
+	namespace DB {
6
+		/**
7
+		 * This is a wrapper for Postgres that allows easier use of the database
8
+		 */
9
+		namespace Wrapper {
10
+			using Postgres;
11
+
12
+			public errordomain Field {
13
+				NOTFOUND
14
+			}
15
+
16
+			public class ResultWrapper : GLib.Object {
17
+				public unowned Result result { get; set; default = null; }
18
+
19
+				public ResultWrapper (Result? result = null) {
20
+					this.result = result;
21
+				}
22
+
23
+				public string get_string_v (int tup_num, int field_num) {
24
+					return result.get_value (tup_num, field_num);
25
+				}
26
+
27
+				public int get_int_v (int tup_num, int field_num) {
28
+					return int.parse (result.get_value (tup_num, field_num));
29
+				}
30
+
31
+				public float get_float_v (int tup_num, int field_num) {
32
+					return float.parse(result.get_value (tup_num, field_num));
33
+				}
34
+
35
+				public double get_double_v (int tup_num, int field_num) {
36
+					return double.parse (result.get_value (tup_num, field_num));
37
+				}
38
+
39
+				public string get_string_n (int tup_num, string name) throws Field {
40
+					return get_string_v (tup_num, check_field_found (result.get_field_number (name), name));;
41
+				}
42
+
43
+				public int get_int_n (int tup_num, string name) throws Field {
44
+					return get_int_v (tup_num, check_field_found (result.get_field_number (name), name));;
45
+				}
46
+
47
+				public float get_float_n (int tup_num, string name) throws Field {
48
+					return get_float_v (tup_num, check_field_found (result.get_field_number (name), name));;
49
+				}
50
+
51
+				public double get_double_n (int tup_num, string name) throws Field {
52
+					return get_double_v (tup_num, check_field_found (result.get_field_number (name), name));
53
+				}
54
+
55
+				private int check_field_found (int field_num, string name) throws Field {
56
+					if (field_num == -1) {
57
+						throw new Field.NOTFOUND (dgettext (null, "The field %s was not found in the query results!"), name);
58
+					}
59
+					return field_num;
60
+				}
61
+			}
62
+		}
63
+	}
64
+}

+ 44
- 0
lib/meson.build View File

@@ -0,0 +1,44 @@
1
+glib_dep = dependency('glib-2.0')
2
+gobject_dep = dependency('gobject-2.0')
3
+pq_dep = dependency('libpq', version: '>=9.0')
4
+
5
+lib_sources = files(
6
+	'dbwrapper.vala',
7
+	'rut.vala',
8
+	'db/arrienda.vala',
9
+	'db/asociado.vala',
10
+	'db/categoria.vala',
11
+	'db/ciudad.vala',
12
+	'db/contacto_emergencia.vala',
13
+	'db/descuento.vala',
14
+	'db/empresa.vala',
15
+	'db/enfermedad.vala',
16
+	'db/especialidad.vala',
17
+	'db/guia.vala',
18
+	'db/lugar.vala',
19
+	'db/participa.vala',
20
+	'db/posee.vala',
21
+	'db/realiza.vala',
22
+	'db/region.vala',
23
+	'db/requerir_auto.vala',
24
+	'db/tiene_enfermedad.vala',
25
+	'db/tour.vala',
26
+	'db/turista.vala',
27
+	'db/vehiculo.vala')
28
+
29
+vala_args = ['--vapidir='+join_paths(meson.source_root(),'vapi')]
30
+
31
+sernatur_lib = library('sernatur',
32
+	lib_sources,
33
+	vala_header: 'sernatur.h',
34
+	vala_vapi: 'sernatur-1.0.0.vapi',
35
+#	vala_gir: 'Sernatur-1.0.0.gir',
36
+	vala_args: vala_args,
37
+	dependencies: [glib_dep, gobject_dep, pq_dep],
38
+	version: '1.0.0',
39
+	soversion: '1',
40
+	install: true,
41
+	install_dir: [true, true, true])
42
+
43
+pkg_mod = import('pkgconfig')
44
+pkg_mod.generate(sernatur_lib)

+ 139
- 0
lib/rut.vala View File

@@ -0,0 +1,139 @@
1
+namespace Sernatur {
2
+	namespace Person {
3
+
4
+		public errordomain InvalidRut {
5
+			INVALID,
6
+			TOOLARGE,
7
+			INVALIDVERIFIER
8
+		}
9
+
10
+		public class Rut : GLib.Object {
11
+			private string clean_rut;
12
+			private string pretty_rut;
13
+			private unichar verifier;
14
+
15
+			public enum Type {
16
+				RUN,
17
+				RUT
18
+			}
19
+
20
+			public Rut (string rut) throws InvalidRut {
21
+				parse (rut);
22
+			}
23
+
24
+			private void parse (string rut) throws InvalidRut {
25
+				try {
26
+					var regex = new Regex ("^[ ]*([0-9.]{0,11}[\\-]?[0-9kK])?[ ]*$");
27
+					if (!regex.match (rut)) {
28
+						throw new InvalidRut.INVALID (dgettext (null, "The RUT %s has an invalid character!"), rut);
29
+					}
30
+				}
31
+				catch (Error e) {
32
+					#if DEBUG
33
+						error (e.message);
34
+					#else
35
+						warning (e.message);
36
+					#endif
37
+				}
38
+				try {
39
+					var regex = new Regex ("([.-])");
40
+					string new_rut = rut.up ();
41
+					new_rut = new_rut.strip ();
42
+					rut = regex.replace (new_rut, new_rut.length, 0, "");
43
+					if (int.parse (rut.substring (0, rut.length - 1)) > 100000000) {
44
+						throw new InvalidRut.TOOLARGE (dgettext (null, "The RUT %s is too big!"), rut);
45
+					}
46
+					this.verifier = rut.get_char (rut.length - 1);
47
+					this.clean_rut = rut.substring (0, rut.length - 1);
48
+					if (generate_verfifier (this.clean_rut) != this.verifier) {
49
+						throw new InvalidRut.INVALIDVERIFIER (dgettext (null, "The verifier %C is invalid!"), this.verifier);
50
+					}
51
+					pretty();
52
+				}
53
+				catch (Error e) {
54
+					#if DEBUG
55
+						error (e.message);
56
+					#else
57
+						warning (e.message);
58
+					#endif
59
+				}
60
+			}
61
+
62
+			private void pretty () {
63
+				string new_rut = "";
64
+				string temp_rut = this.clean_rut.reverse ();
65
+				int rut_length = this.clean_rut.length;
66
+				for (int i = 0; i < rut_length; i++) {
67
+					new_rut = new_rut + temp_rut.get_char(i).to_string ();
68
+					if ((i + 1) % 3 == 0) {
69
+						new_rut = new_rut + ".";
70
+					}
71
+				}
72
+				new_rut = new_rut.reverse ();
73
+				this.pretty_rut = new_rut + "-" + this.verifier.to_string ();
74
+			}
75
+
76
+			private unichar generate_verfifier (string rut) {
77
+				/**
78
+				 * 1. Multiply each digit of the RUT by 2, 3, ..., 7, 2, 3, ... from the end of the RUT moving forward.
79
+				 * 2. Add the partial multiplications.
80
+				 * 3. Calculate the remainder of the division by 11.
81
+				 * 4. The verifier is 11 minus the previous result. If the result is 10, change it to K.
82
+				 */
83
+				int multiplier = 2;
84
+				int sum = 0;
85
+				int remainder;
86
+				int division;
87
+				int rut_length = rut.length;
88
+
89
+				// Steps 1 and 2
90
+				for (int i = rut_length - 1; i >= 0; i--) {
91
+					sum = sum + (int.parse (rut.substring(i, 1)) * multiplier);
92
+					multiplier++;
93
+					if (multiplier == 8) {
94
+						multiplier = 2;
95
+					}
96
+				}
97
+
98
+				// Step 3
99
+				division = sum / 11;
100
+				division = division * 11;
101
+				remainder = sum - division;
102
+
103
+				// Step 4
104
+				if (remainder != 0) {
105
+					remainder = 11 - remainder;
106
+				}
107
+
108
+				// Let's return their verifier
109
+				if (remainder == 10) {
110
+					// Their verifier is 10 so let's return K.
111
+					return 'K';
112
+				}
113
+				else {
114
+					return (unichar) remainder + '0';
115
+				}
116
+			}
117
+
118
+			public string get_clean_rut () {
119
+				return this.clean_rut + this.verifier.to_string ();
120
+			}
121
+
122
+			public string get_rut () {
123
+				return this.pretty_rut;
124
+			}
125
+
126
+			public Type type () {
127
+				uint rut = int.parse (this.clean_rut);
128
+				if (rut < 100000000 && rut > 50000000) {
129
+					// Company
130
+					return Type.RUT;
131
+				}
132
+				else {
133
+					// Person
134
+					return Type.RUN;
135
+				}
136
+			}
137
+		}
138
+	}
139
+}

+ 9
- 1
meson.build View File

@@ -3,6 +3,7 @@ project('sernatur',
3 3
 	version: '1.0.0',
4 4
 	license: 'BSD-3',
5 5
 	default_options: [
6
+		'c_std=c11',
6 7
 		'b_ofast=if-release',
7 8
 		'b_march_native=if-release',
8 9
 		'b_ndebug=if-release'
@@ -10,12 +11,19 @@ project('sernatur',
10 11
 )
11 12
 add_global_arguments('-DGETTEXT_PACKAGE="sernatur"', language: 'c')
12 13
 
14
+debugging = get_option('debugging')
15
+if debugging
16
+	add_global_arguments('-DDEBUG', language : 'c')
17
+	add_global_arguments('-D', 'DEBUG', language : 'vala')
18
+endif
19
+
13 20
 add_project_arguments(['--vapidir',
14
-	join_paths(meson.current_source_dir(), 'src/vapi')],
21
+	join_paths(meson.current_source_dir(), 'vapi')],
15 22
 	language: 'vala')
16 23
 
17 24
 subdir('po')
18 25
 subdir('data')
26
+subdir('lib')
19 27
 subdir('src')
20 28
 subdir('doc')
21 29
 subdir('script')

+ 4
- 0
meson_options.txt View File

@@ -1,3 +1,7 @@
1
+option('debugging',
2
+	type: 'boolean',
3
+	value: false,
4
+	description: 'Build with debugging preprocessor')
1 5
 option('valadocs',
2 6
 	type: 'boolean',
3 7
 	value: true,

+ 2
- 0
po/POTFILES View File

@@ -1,3 +1,5 @@
1
+lib/dbwrapper.vala
2
+lib/rut.vala
1 3
 src/sernatur.vala
2 4
 src/sernatur-window.vala
3 5
 data/ui/sernatur.window.ui

+ 28
- 22
po/es.po View File

@@ -7,8 +7,8 @@ msgid ""
7 7
 msgstr ""
8 8
 "Project-Id-Version: sernatur\n"
9 9
 "Report-Msgid-Bugs-To: \n"
10
-"POT-Creation-Date: 2018-12-23 19:19-0300\n"
11
-"PO-Revision-Date: 2018-12-23 19:21-0300\n"
10
+"POT-Creation-Date: 2019-01-03 19:19-0300\n"
11
+"PO-Revision-Date: 2019-01-01 21:06-0300\n"
12 12
 "Last-Translator: Chris Cromer <chris@cromer.cl>\n"
13 13
 "Language-Team: none\n"
14 14
 "Language: es\n"
@@ -18,33 +18,36 @@ msgstr ""
18 18
 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19 19
 "X-Generator: Poedit 2.0.6\n"
20 20
 
21
-#: src/sernatur.vala:54
21
+#: lib/dbwrapper.vala:57
22 22
 #, c-format
23
-msgid "Could not load application icon: %s\n"
24
-msgstr "No se puede cargar el icono de la aplicación: %s\n"
23
+msgid "The field %s was not found in the query results!"
24
+msgstr "La campo %s no estaba en los resultados de la consulta!"
25 25
 
26
-#: src/sernatur-window.vala:97
27
-msgid "Error"
28
-msgstr "Error"
26
+#: lib/rut.vala:28
27
+#, c-format
28
+msgid "The RUT %s has an invalid character!"
29
+msgstr "El RUT %s tiene un carácter invalido!"
29 30
 
30
-#: src/sernatur-window.vala:125
31
-msgid "Server version:"
32
-msgstr "Versión del servidor:"
31
+#: lib/rut.vala:44
32
+#, c-format
33
+msgid "The RUT %s is too big!"
34
+msgstr "El RUT %s es demasiado grande!"
33 35
 
34
-#: data/ui/sernatur.window.ui:42
35
-msgid "_File"
36
-msgstr ""
36
+#: lib/rut.vala:49
37
+#, c-format
38
+msgid "The verifier %C is invalid!"
39
+msgstr "El verificador %C es invalido!"
37 40
 
38
-#: data/ui/sernatur.window.ui:107
39
-msgid "_Edit"
40
-msgstr ""
41
+#: src/sernatur-window.vala:128
42
+msgid "Error"
43
+msgstr "Error"
41 44
 
42
-#: data/ui/sernatur.window.ui:157
43
-msgid "_View"
44
-msgstr ""
45
+#: src/sernatur-window.vala:133
46
+msgid "Postgresql server version:"
47
+msgstr "Versión del servidor Postgresql:"
45 48
 
46
-#: data/ui/sernatur.window.ui:165
47
-msgid "_Help"
49
+#: data/ui/sernatur.window.ui:43
50
+msgid "_Menu"
48 51
 msgstr ""
49 52
 
50 53
 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5
@@ -96,3 +99,6 @@ msgstr "El ancho de la ventana"
96 99
 #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:20
97 100
 msgid "Window height"
98 101
 msgstr "La altura de la venta"
102
+
103
+#~ msgid "Could not load application icon: %s\n"
104
+#~ msgstr "No se puede cargar el icono de la aplicación: %s\n"

+ 18
- 15
po/sernatur.pot View File

@@ -8,7 +8,7 @@ msgid ""
8 8
 msgstr ""
9 9
 "Project-Id-Version: sernatur\n"
10 10
 "Report-Msgid-Bugs-To: \n"
11
-"POT-Creation-Date: 2018-12-23 19:19-0300\n"
11
+"POT-Creation-Date: 2019-01-03 19:19-0300\n"
12 12
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13 13
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 14
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,33 +17,36 @@ msgstr ""
17 17
 "Content-Type: text/plain; charset=CHARSET\n"
18 18
 "Content-Transfer-Encoding: 8bit\n"
19 19
 
20
-#: src/sernatur.vala:54
20
+#: lib/dbwrapper.vala:57
21 21
 #, c-format
22
-msgid "Could not load application icon: %s\n"
22
+msgid "The field %s was not found in the query results!"
23 23
 msgstr ""
24 24
 
25
-#: src/sernatur-window.vala:97
26
-msgid "Error"
25
+#: lib/rut.vala:28
26
+#, c-format
27
+msgid "The RUT %s has an invalid character!"
27 28
 msgstr ""
28 29
 
29
-#: src/sernatur-window.vala:125
30
-msgid "Server version:"
30
+#: lib/rut.vala:44
31
+#, c-format
32
+msgid "The RUT %s is too big!"
31 33
 msgstr ""
32 34
 
33
-#: data/ui/sernatur.window.ui:42
34
-msgid "_File"
35
+#: lib/rut.vala:49
36
+#, c-format
37
+msgid "The verifier %C is invalid!"
35 38
 msgstr ""
36 39
 
37
-#: data/ui/sernatur.window.ui:107
38
-msgid "_Edit"
40
+#: src/sernatur-window.vala:128
41
+msgid "Error"
39 42
 msgstr ""
40 43
 
41
-#: data/ui/sernatur.window.ui:157
42
-msgid "_View"
44
+#: src/sernatur-window.vala:133
45
+msgid "Postgresql server version:"
43 46
 msgstr ""
44 47
 
45
-#: data/ui/sernatur.window.ui:165
46
-msgid "_Help"
48
+#: data/ui/sernatur.window.ui:43
49
+msgid "_Menu"
47 50
 msgstr ""
48 51
 
49 52
 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5

+ 5
- 17
src/meson.build View File

@@ -3,21 +3,7 @@ gobject_dep = dependency('gobject-2.0')
3 3
 gtk_dep = dependency('gtk+-3.0', version: '>=3.0.0')
4 4
 # gmodule-export-2.0 is needed to connect the handlers
5 5
 gmodule_dep = dependency('gmodule-2.0', version: '>=2.0')
6
-pq_dep = dependency('libpq', version: '>=10.0')
7
-posix_dep = meson.get_compiler('vala').find_library('posix')
8
-
9
-# this is how to link against a c lib
10
-#libsystemd_lib = meson.get_compiler('c').find_library('libsystemd')
11
-
12
-#cc = meson.get_compiler('c')
13
-# -no-pie so that the executable is double clickable in gui
14
-#if cc.get_id() == 'gcc'
15
-#	c_args = ['-no-pie']
16
-#	link_args = ['-no-pie']
17
-#else
18
-#	c_args ''
19
-#	link_args ''
20
-#endif
6
+pq_dep = dependency('libpq', version: '>=9.0')
21 7
 
22 8
 vala_sources = files(
23 9
 	'sernatur.vala',
@@ -29,11 +15,13 @@ c_sources = [sernatur_gresource_c]
29 15
 sources = vala_sources
30 16
 sources += c_sources
31 17
 
32
-vala_args = ['--vapidir='+join_paths(meson.source_root(),'src/vapi')]
18
+vala_args = ['--vapidir='+join_paths(meson.source_root(),'vapi')]
33 19
 vala_args += ['--gresources='+join_paths(meson.source_root(),'data/ui/sernatur.gresource.xml')]
34 20
 
21
+sernatur_dep = declare_dependency(link_with: sernatur_lib, include_directories: include_directories('../lib'))
22
+
35 23
 exe = executable('sernatur',
36 24
 	sources,
37 25
 	vala_args: vala_args,
38
-	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, posix_dep],
26
+	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, sernatur_dep],
39 27
 	install: true)

+ 86
- 53
src/sernatur-window.vala View File

@@ -16,13 +16,16 @@
16 16
  * The main Sernatur namespace
17 17
  */
18 18
 namespace Sernatur {
19
-	using Postgres;
19
+	using DB;
20 20
 
21 21
 	/**
22 22
 	 * The MainWindow class
23 23
 	 */
24 24
 	[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/sernatur.window.ui")]
25 25
 	public class MainWindow : Gtk.ApplicationWindow {
26
+		Gtk.Grid content;
27
+		[GtkChild]
28
+		private Gtk.Box mainbox;
26 29
 
27 30
 		/**
28 31
 		 * This is a callback for when the window is maximized or unmaximized
@@ -32,7 +35,7 @@ namespace Sernatur {
32 35
 		 */
33 36
 		[GtkCallback]
34 37
 		private bool maximize_window(Gtk.Widget widget, Gdk.EventWindowState state) {
35
-			Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
38
+			var settings = new Settings ("cl.cromer.ubb.sernatur.window");
36 39
 			if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) {
37 40
 				// Maximized
38 41
 				settings.set_boolean ("maximized", true);
@@ -52,7 +55,7 @@ namespace Sernatur {
52 55
 		 */
53 56
 		[GtkCallback]
54 57
 		private bool resize_window(Gtk.Widget widget, Gdk.Event event) {
55
-			Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
58
+			var settings = new Settings ("cl.cromer.ubb.sernatur.window");
56 59
 			if (event.get_event_type () == Gdk.EventType.CONFIGURE && !settings.get_boolean ("maximized")) {
57 60
 				if (settings.get_int ("width") != event.get_window ().get_width ()) {
58 61
 					settings.set_int ("width", event.get_window ().get_width ());
@@ -64,71 +67,101 @@ namespace Sernatur {
64 67
 			return false;
65 68
 		}
66 69
 
70
+		[GtkCallback]
71
+		private void menu_quit(Gtk.MenuItem menu_item) {
72
+			application.quit ();
73
+		}
74
+
67 75
 		/**
68 76
 		* Initialize the main window class
69 77
 		* @param application The application used to make the GLib object
70 78
 		*/
71 79
 		public MainWindow (Gtk.Application application) {
72 80
 			GLib.Object (application: application);
73
-			Database conn;
74 81
 
75
-			Settings settings = new Settings ("cl.cromer.ubb.sernatur.db");
76
-			string host = settings.get_string ("host");
77
-			string port = settings.get_string ("port");
78
-			string options = settings.get_string ("options");
79
-			string tty = settings.get_string ("tty");
80
-			string database = settings.get_string ("database");
81
-			string username = settings.get_string ("username");
82
-			string password = settings.get_string ("password");
82
+			// Load logo
83
+			var builder = new Gtk.Builder ();
84
+			try {
85
+				builder.add_from_resource ("/cl/cromer/ubb/sernatur/splash.ui");
86
+				builder.connect_signals (null);
87
+				content = builder.get_object ("content_grid") as Gtk.Grid;
83 88
 
84
-			conn = set_db_login (host, port, options, tty, database, username, password);
85
-			if (conn.get_status () != ConnectionStatus.OK) {
86
-				stderr.printf ("%s\n", conn.get_error_message ());
87
-				Gtk.MessageDialog msg = new Gtk.MessageDialog (this,
88
-					Gtk.DialogFlags.MODAL,
89
-					Gtk.MessageType.ERROR,
90
-					Gtk.ButtonsType.CLOSE,
91
-					conn.get_error_message ());
92
-				msg.response.connect ((response_id) => {
93
-					switch (response_id) {
94
-						case Gtk.ResponseType.CLOSE:
95
-							application.quit ();
96
-							break;
97
-						case Gtk.ResponseType.DELETE_EVENT:
98
-							application.quit ();
99
-							break;
100
-					}
101
-					msg.destroy();
102
-				});
103
-				msg.set_title (dgettext (null, "Error"));
104
-				msg.show ();
105
-				return;
89
+				// Add logo to main main box
90
+				mainbox.pack_start (content, true, false, 0);
106 91
 			}
107
-
108
-			/*Result res = conn.exec ("CREATE DATABASE bdd;");
109
-			if (res.get_status () != ExecStatus.COMMAND_OK) {
110
-				stderr.printf ("%s\n", conn.get_error_message ());
111
-				application.quit ();
112
-				return;
92
+			catch (Error e) {
93
+				// This error is not fatal, so let's keep going
94
+				warning (e.message);
113 95
 			}
114 96
 
115
-			string password = encrypt_password ("bdd", "bdd");
97
+			var settings = new Settings ("cl.cromer.ubb.sernatur.db");
98
+			var host = settings.get_string ("host");
99
+			var port = settings.get_string ("port");
100
+			var options = settings.get_string ("options");
101
+			var tty = settings.get_string ("tty");
102
+			var database = settings.get_string ("database");
103
+			var username = settings.get_string ("username");
104
+			var password = settings.get_string ("password");
116 105
 
117
-			res = conn.exec ("CREATE USER bdd WITH ENCRYPTED PASSWORD '" + password + "';");
118
-			if (res.get_status () != ExecStatus.COMMAND_OK) {
119
-				stderr.printf ("%s\n", conn.get_error_message ());
120
-				application.quit ();
121
-				return;
106
+			var conn = Postgres.set_db_login (host, port, options, tty, database, username, password);
107
+			if (conn.get_status () != Postgres.ConnectionStatus.OK) {
108
+				#if DEBUG
109
+					error (conn.get_error_message ());
110
+				#else
111
+					warning (conn.get_error_message ());
112
+					var msg = new Gtk.MessageDialog (this,
113
+						Gtk.DialogFlags.MODAL,
114
+						Gtk.MessageType.ERROR,
115
+						Gtk.ButtonsType.CLOSE,
116
+						conn.get_error_message ());
117
+					msg.response.connect ((response_id) => {
118
+						switch (response_id) {
119
+							case Gtk.ResponseType.CLOSE:
120
+								application.quit ();
121
+								break;
122
+							case Gtk.ResponseType.DELETE_EVENT:
123
+								application.quit ();
124
+								break;
125
+						}
126
+						msg.destroy();
127
+					});
128
+					msg.set_title (dgettext (null, "Error"));
129
+					msg.show ();
130
+					return;
131
+				#endif
122 132
 			}
133
+			print (dgettext (null, "Postgresql server version:") + " %d\n", conn.get_server_version ());
123 134
 
124
-			res = conn.exec ("GRANT ALL PRIVILEGES ON DATABASE bdd TO bdd;");
125
-			if (res.get_status () != ExecStatus.COMMAND_OK) {
126
-				stderr.printf ("%s\n", conn.get_error_message ());
127
-				application.quit ();
128
-				return;
135
+			/*var tour = Tour.get_all_tours (conn);
136
+			print (tour[0].ciudad.region.nombre_region + "\n");
137
+			var tiene_enfermedad = TieneEnfermedad.get_all_tiene_enfermedades (conn);
138
+			print (tiene_enfermedad[0].turista.contacto_emergencia.nombre_emergencia + "\n");
139
+			var descuento = Descuento.get_all_descuentos (conn);
140
+			print (descuento[0].porcentaje.to_string () + "\n");
141
+			var realiza = Realiza.get_all_realizas (conn);
142
+			print (realiza[0].turista.contacto_emergencia.nombre_emergencia + "\n");
143
+			var posee = Posee.get_all_posees (conn);
144
+			print (posee[0].guia.ciudad.region.nombre_region + "\n");
145
+			var region = Region.get_all_regiones (conn);
146
+			print (region[0].nombre_region + "\n");
147
+			var participa = Participa.get_all_participas (conn);
148
+			print (participa[0].guia.ciudad.region.nombre_region + "\n");
149
+			print (participa[0].tour.ciudad.region.nombre_region + "\n");
150
+			var requerir_auto = RequerirAuto.get_all_requerir_autos (conn);
151
+			print (requerir_auto[0].vehiculo.marca + "\n");
152
+			try {
153
+				var rut = new Person.Rut ("23.660.457-8");
154
+				print (rut.get_rut () + "\n");
155
+				if (rut.type () == Person.Rut.Type.RUN) {
156
+					print ("person\n");
157
+				}
158
+				else {
159
+					print ("company\n");
160
+				}
161
+			}
162
+			catch (Person.InvalidRut e) {
163
+				print ("Rut is invalid");
129 164
 			}*/
130
-
131
-			GLib.print (dgettext (null, "Server version:") + " %d\n", conn.get_server_version ());
132 165
 		}
133 166
 	}
134 167
 }

+ 3
- 3
src/sernatur.vala View File

@@ -39,19 +39,19 @@ namespace Sernatur {
39 39
 		 */
40 40
 		public override void activate () {
41 41
 			window = new MainWindow (this);
42
-			GLib.Settings settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
42
+			var settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
43 43
 
44 44
 			window.set_default_size (settings.get_int("width"), settings.get_int("height"));
45 45
 
46 46
 			if (settings.get_boolean ("maximized")) {
47 47
 				window.maximize ();
48 48
 			}
49
-			
49
+
50 50
 			try {
51 51
 				window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
52 52
 			}
53 53
 			catch (Error e) {
54
-				stderr.printf (dgettext (null, "Could not load application icon: %s\n"), e.message);
54
+				warning (e.message);
55 55
 			}
56 56
 			window.present ();
57 57
 		}

Loading…
Cancel
Save