public List <IObjetoTexto> LeerTabla()
        {
            List <IObjetoTexto> lista = new List <IObjetoTexto>();

            try
            {
                String[] lineas = _contenido.Split("\n");
                for (int i = 0; i < lineas.Length; i++)
                {
                    lineas[i] = lineas[i].Trim();
                    if (!lineas[i].Equals(""))
                    {
                        IObjetoTexto _objeto = ModeloFactory.darInstancia(_tipo);
                        lista.Add(_objeto.leerTexto(lineas[i]));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Ha ocurrido un Error: " + ex.Message);
            }


            return(lista);
        }
        //CRUD....
        //Create Crear
        //Retreive Obtener
        //Update Modificar
        //Delete Eliminar

        //Reflection ----> Ingenieria Inversa... Analizar o modificar la estructura de un objeto

        //Id: 1
        // Nombre: Fulanito de Tal
        // Estado: Habilitado
        // Insert Usuario(id,nombre,contrasena,estado)values(1,Fulanito de tal,******,Habilitado)


        public static Boolean Crear(IObjetoTexto fuente)
        {
            Type tipo = fuente.GetType();

            PropertyInfo[] propiedades = tipo.GetProperties();

            Dictionary <String, String> campos = new Dictionary <String, String>();

            foreach (PropertyInfo propiedadx in propiedades)
            {
                campos.Add(propiedadx.Name, propiedadx.GetValue(fuente).ToString());
            }

            return(Crear(campos, tipo));
        }
Exemple #3
0
 public List <object> LeerTabla()
 {
     try
     {
         String[]      lineas = _contenido.Split("\n");
         List <object> lista  = new List <object>();
         for (int i = 0; i < lineas.Length; i++)
         {
             IObjetoTexto _objeto = (IObjetoTexto)Activator.CreateInstance(_tipo);
             lista.Add(_objeto.leerTexto(lineas[i]));
         }
         return(lista);
     }
     catch (Exception ex)
     {
         System.Console.WriteLine("Ha ocurrido un Error: " + ex.Message);
     }
     return(null);
 }
Exemple #4
0
 public bool EscribirTabla(List <object> lista)
 {
     try
     {
         if (lista != null)
         {
             String contenido = "";
             foreach (object _objeto in lista)
             {
                 IObjetoTexto _objetoTexto = (IObjetoTexto)_objeto;
                 contenido += _objetoTexto.guardarTexto() + "\n";
             }
             File.WriteAllText(_archivo, contenido);
             _contenido = contenido;
             return(true);
         }
     }
     catch (Exception ex) {
         System.Console.WriteLine("Ha ocurrido un Error: " + ex.Message);
     }
     return(false);
 }
Exemple #5
0
        //CRUD....
        //Create Crear
        //Retreive Obtener
        //Update Modificar
        //Delete Eliminar

        //Reflection ----> Ingenieria Inversa... Analizar o modificar la estructura de un objeto

        //Id: 1
        // Nombre: Fulanito de Tal
        // Estado: Habilitado
        // Insert Usuario(id,nombre,contrasena,estado)values(1,Fulanito de tal,******,Habilitado)


        public static Boolean Crear(Dictionary <String, String> campos, List <IObjetoTexto> lista, Type tipo)
        {
            PropertyInfo[] _propiedadesClase = tipo.GetProperties();
            IObjetoTexto   objeto            = darInstancia(tipo);

            foreach (PropertyInfo propiedad in _propiedadesClase)
            {
                foreach (KeyValuePair <String, String> campo in campos)
                {
                    if (campo.Key.Equals(propiedad.Name))
                    {
                        propiedad.SetValue(objeto, campo.Value);
                    }
                }
            }

            lista.Add(objeto);
            ConexionFactory.DarConexion(tipo).EscribirTabla(lista);


            return(true);
        }
        public static Boolean Crear(Dictionary <String, String> campos, Type tipo)
        {
            List <IObjetoTexto> lista = Listar(tipo);

            PropertyInfo[] _propiedadesClase = tipo.GetProperties();
            IObjetoTexto   objeto            = darInstancia(tipo);

            foreach (PropertyInfo propiedad in _propiedadesClase)
            {
                foreach (KeyValuePair <String, String> campo in campos)
                {
                    if (campo.Key.Equals(propiedad.Name))
                    {
                        switch (propiedad.PropertyType.Name)
                        {
                        case "Int32":
                            propiedad.SetValue(objeto, Int32.Parse(campo.Value));
                            break;

                        case "Boolean":
                            propiedad.SetValue(objeto, Boolean.Parse(campo.Value));
                            break;

                        default:
                            propiedad.SetValue(objeto, campo.Value);
                            break;
                        }
                    }
                }
            }

            lista.Add(objeto);
            ConexionFactory.DarConexion(tipo).EscribirTabla(lista);


            return(true);
        }