+
+using System;
+using System.Collections;
+using Gtk;
+using Glade;
+
+using Controlador.Afiliacion;
+using Dominio.Autorizaciones;
+using Dominio.Planes;
+using Dominio.Afiliados;
+using Dominio;
+
+public class VBuscarAfiliado
+{
+ Glade.XML xml;
+ string retorno = null;
+
+
+ [Widget] TreeView lista;
+
+ /* Busqueda */
+ [Widget] ComboBox s_tipoDocumento;
+ [Widget] Entry s_nroDocument;
+ [Widget] Entry s_apellido;
+ [Widget] Entry s_codigo;
+
+ public VBuscarAfiliado ()
+ {
+ xml = new Glade.XML (null, "buscar_afiliado.glade", "buscar_afiliado", null);
+ xml.Autoconnect (this);
+
+ lista.Model = new ListStore (typeof(int), typeof(string), typeof(int), typeof (string), typeof(string));
+
+ /* Columnas */
+ lista.HeadersVisible = true;
+ lista.AppendColumn ("Codigo", new CellRendererText (), "text", 0);
+ lista.AppendColumn ("Tipo Doc.", new CellRendererText (), "text", 1);
+ lista.AppendColumn ("Número Doc.", new CellRendererText (), "text", 2);
+ lista.AppendColumn ("Nombre", new CellRendererText (), "text", 3);
+ lista.AppendColumn ("Apellido", new CellRendererText (), "text", 4);
+ }
+
+ public void OnBuscarAfiliado (object o, EventArgs args)
+ {
+ ETipoDocumento tipoDoc;
+ try {
+ TreeIter iter;
+ s_tipoDocumento.GetActiveIter (out iter);
+ tipoDoc = (ETipoDocumento)Enum.Parse (typeof (ETipoDocumento), (string)s_tipoDocumento.Model.GetValue (iter, 0), true);
+ } catch (Exception e) {
+ tipoDoc = ETipoDocumento.NONE;
+ }
+ int nroDoc;
+ try {
+ nroDoc = Int32.Parse (s_nroDocument.Text);
+ } catch (Exception e) {
+ nroDoc = 0;
+ }
+ int cod;
+ try {
+ cod = Int32.Parse (s_codigo.Text);
+ } catch (Exception e) {
+ cod = 0;
+ }
+
+ AfiliadoSolicitanteController c = new AfiliadoSolicitanteController ();
+ ListStore store = (ListStore)lista.Model;
+ store.Clear ();
+ ArrayList lst = c.BuscarAfiliados (tipoDoc, nroDoc, cod, null);
+ foreach (Afiliado p in lst) {
+ TreeIter i = store.Append ();
+ store.SetValue (i, 0, p.Codigo);
+ store.SetValue (i, 1, p.TipoDocumento.ToString ());
+ store.SetValue (i, 2, p.NroDocumento);
+ store.SetValue (i, 3, p.Nombre);
+ store.SetValue (i, 4, p.Apellido);
+ }
+
+ c.Dispose ();
+ }
+
+ public void OnDialogResponse (object o, ResponseArgs args)
+ {
+ if (args.ResponseId == ResponseType.Cancel)
+ return;
+
+ /* Todo el seleccionado. TODO : abortar si no hay nada seleccionado! :) */
+
+ TreeSelection fromSel = lista.Selection;
+ TreeIter iter;
+ TreeModel model;
+
+ if (fromSel.GetSelected (out model, out iter)) {
+ retorno = String.Format ("{0}", (int)model.GetValue (iter, 0));
+ }
+ }
+
+ public string Run ()
+ {
+ Dialog w = (Dialog)xml.GetWidget ("buscar_afiliado");
+ w.Run ();
+ w.Destroy ();
+
+ return retorno;
+ }
+}
+