From 05e29ccd5432642ed3716ebb4d7675ca944c8000 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Tue, 21 Jun 2005 15:09:55 +0000 Subject: [PATCH] * Instancia clases, asigna valores desde la ventan y los guarda en la DB TODO : verificar w/r de las clases que se van a usar con eso --- demo/src/Controlador/Controller.cs | 4 ++++ demo/src/Dominio/Plan.cs | 12 ++++++++++++ demo/src/Vistas/ABMGenerico.cs | 31 +++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/demo/src/Controlador/Controller.cs b/demo/src/Controlador/Controller.cs index a0ae47c..54f372f 100644 --- a/demo/src/Controlador/Controller.cs +++ b/demo/src/Controlador/Controller.cs @@ -35,6 +35,10 @@ public class Controller : IDisposable } return lst; } + + public void GenericSave (object o) + { + } } } diff --git a/demo/src/Dominio/Plan.cs b/demo/src/Dominio/Plan.cs index 58f6bbb..659a2e3 100644 --- a/demo/src/Dominio/Plan.cs +++ b/demo/src/Dominio/Plan.cs @@ -15,9 +15,11 @@ public class Plan public int Codigo { get { return _codigo; } + set { _codigo = value; } } public float Categoria { get { return _categoria; } + set { _categoria = value; } } public string Descripcion { get { return _descripcion; } @@ -31,6 +33,11 @@ public class Plan get { return _fechaBaja; } } + public Plan () + { + _categoria = 0; + } + public Plan (float categoria) { /* TODO */ @@ -58,6 +65,11 @@ public class Plan { return _coberturas; } + + public override string ToString () + { + return String.Format ("Plan : {0} {1} {2}", _codigo, _categoria, _descripcion); + } } } diff --git a/demo/src/Vistas/ABMGenerico.cs b/demo/src/Vistas/ABMGenerico.cs index 4e185db..ceb15d3 100644 --- a/demo/src/Vistas/ABMGenerico.cs +++ b/demo/src/Vistas/ABMGenerico.cs @@ -5,14 +5,19 @@ using System.Collections; using Gtk; using Glade; +using Controlador; + public class ABMGenerico { Glade.XML xml; [Widget] Table tabla; Type current; + Hashtable widgets; public ABMGenerico (Type objectType) { + widgets = new Hashtable (); + PropertyInfo[] properties = objectType.GetProperties (); current = objectType; @@ -28,6 +33,7 @@ public class ABMGenerico tabla.Attach (e, 1, 2, i, i+1); l.Show (); e.Show (); + widgets[mf.Name] = e; } i++; } @@ -66,8 +72,31 @@ public class ABMGenerico { if (args.ResponseId == ResponseType.Cancel) return; - } + + PropertyInfo[] properties = current.GetProperties (); + + System.Object output = Activator.CreateInstance (current); + + foreach (string key in widgets.Keys) { + PropertyInfo p = current.GetProperty (key); + Entry e = (Entry)widgets[key]; + Console.WriteLine ("{0} = {1}", key, e.Text); + if (p.PropertyType.Equals (typeof(string))) + p.SetValue (output, e.Text, null); + if (p.PropertyType.Equals (typeof(int))) + p.SetValue (output, Int32.Parse (e.Text), null); + if (p.PropertyType.Equals (typeof(float))) { + p.SetValue (output, (float)Double.Parse (e.Text), null); + } + } + Controller c = new Controller (); + + c.GenericSave (output); + + c.Dispose (); + } + public void Run () { Dialog w = (Dialog)xml.GetWidget ("abm_one"); -- 2.43.0