using System; using System.Collections; using Gtk; using Glade; using Controlador; using Controlador.Afiliacion; using Dominio.Afiliados; using Dominio; public class VEmitirHojaDeRuta { Dialog wIngresarSolicitud; Glade.XML xml; [Widget] ComboBox promotores; [Widget] TreeView disponibles; [Widget] TreeView hojaderuta; public VEmitirHojaDeRuta () { xml = new Glade.XML (null, "emitir_hoja_de_ruta.glade", "emitir_hoja_de_ruta", null); xml.Autoconnect (this); /* Creo los modelos para los TreeView y el ComboBox Tipo Doc NroDoc Apellido Nombre */ disponibles.Model = new TreeModelSort (new ListStore (typeof(string), typeof(int), typeof (string), typeof (string))); hojaderuta.Model = new TreeModelSort (new ListStore (typeof(string), typeof(int), typeof (string), typeof (string))); /* Columnas */ disponibles.HeadersVisible = true; disponibles.AppendColumn ("Tipo Doc.", new CellRendererText (), "text", 0); disponibles.AppendColumn ("Nro Doc.", new CellRendererText (), "text", 1); disponibles.AppendColumn ("Apellido", new CellRendererText (), "text", 2); disponibles.AppendColumn ("Nombre", new CellRendererText (), "text", 3); hojaderuta.HeadersVisible = true; hojaderuta.AppendColumn ("Tipo Doc.", new CellRendererText (), "text", 0); hojaderuta.AppendColumn ("Nro Doc.", new CellRendererText (), "text", 1); hojaderuta.AppendColumn ("Apellido", new CellRendererText (), "text", 2); hojaderuta.AppendColumn ("Nombre", new CellRendererText (), "text", 3); int i = 0; foreach (TreeViewColumn col in disponibles.Columns) { col.SortColumnId = i++; } disponibles.EnableSearch = true; disponibles.Reorderable = true; disponibles.HeadersClickable = true; i = 0; foreach (TreeViewColumn col in hojaderuta.Columns) { col.SortColumnId = i++; } hojaderuta.EnableSearch = true; hojaderuta.Reorderable = true; hojaderuta.HeadersClickable = true; xml.GetWidget ("emitir_hoja_de_ruta").SetSizeRequest (500, 420); /* Cargo promotores */ ListStore l = (ListStore)promotores.Model; l.Clear (); for(i=0; i<10; i++) l.AppendValues (String.Format ("Promotor {0}", i)); } public void OnDialogResponse (object o, ResponseArgs args) { if (args.ResponseId == ResponseType.Cancel) return; /* Armo la hoja de ruta */ /* TODO : No tengo de donde sacarlo, creo uno pedorro para test */ int promotor = 0; /* Veo si hay items en la hoja de ruta */ ListStore store = (hojaderuta.Model as TreeModelSort).Model as ListStore; TreeIter iter; if (store.GetIterFirst (out iter) == false) { /* Lista vacia! .. Alarm! Alarm! :) */ MessageDialog md = new MessageDialog (null, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close, "La hoja de ruta está vacía."); md.Run (); md.Destroy (); return; } AfiliadoSolicitanteController c = new AfiliadoSolicitanteController (); ETipoDocumento tipoDoc; int nroDoc; tipoDoc = (ETipoDocumento)Enum.Parse (typeof (ETipoDocumento), (string)store.GetValue (iter, 0), true); nroDoc = (int)store.GetValue (iter, 1); c.AsociarPromotor (tipoDoc, nroDoc, promotor); while (store.IterNext (ref iter) == true) { tipoDoc = (ETipoDocumento)Enum.Parse (typeof (ETipoDocumento), (string)store.GetValue (iter, 0), true); nroDoc = Int32.Parse ((string)store.GetValue (iter, 1)); c.AsociarPromotor (tipoDoc, nroDoc, promotor); } c.Dispose (); } public void OnAgregarClicked (object o, EventArgs args) { /* Obtengo el TreeIter seleccionado de disponibles */ TreeSelection fromSel = disponibles.Selection; TreeIter iter; TreeModel model; if (fromSel.GetSelected (out model, out iter)) { ListStore store1 = (disponibles.Model as TreeModelSort).Model as ListStore; ListStore store2 = (hojaderuta.Model as TreeModelSort).Model as ListStore; TreeIter nuevo = store2.Append (); for(int i=0; i<4; i++) store2.SetValue (nuevo, i, model.GetValue (iter, i)); TreeIter rem = (model as TreeModelSort).ConvertIterToChildIter (iter); store1.Remove (ref rem); } } public void OnBorrarClicked (object o, EventArgs args) { /* Obtengo el TreeIter seleccionado de disponibles */ TreeSelection fromSel = hojaderuta.Selection; TreeIter iter; TreeModel model; if (fromSel.GetSelected (out model, out iter)) { ListStore store2 = (disponibles.Model as TreeModelSort).Model as ListStore; ListStore store1 = (hojaderuta.Model as TreeModelSort).Model as ListStore; TreeIter nuevo = store2.Append (); for(int i=0; i<4; i++) store2.SetValue (nuevo, i, model.GetValue (iter, i)); TreeIter rem = (model as TreeModelSort).ConvertIterToChildIter (iter); store1.Remove (ref rem); } } public void OnPromotorSelected (object o, EventArgs args) { RutasController c = new RutasController (); ArrayList sols = c.ObtenerSolicitantesPendientes (); ListStore store = (disponibles.Model as TreeModelSort).Model as ListStore; foreach (Solicitante s in sols) { TreeIter iter = store.AppendValues (s.TipoDocumento.ToString (), s.NroDocumento, s.Nombre, s.Apellido); } c.Dispose (); } public void Run () { Dialog w = (Dialog)xml.GetWidget ("emitir_hoja_de_ruta"); w.Run (); w.Destroy (); } }