Exemple #1
0
        public static List <Propiedad> LeerArchivo1(string archivo)
        {
            string           linea = "";
            int              i     = 0;
            Propiedad        Imueble;
            List <Propiedad> ListaDePropiedad = new List <Propiedad>();
            StreamReader     file             = new StreamReader(archivo);

            while ((linea = file.ReadLine()) != null)
            {
                string[] Lineas = linea.Split(";");
                int      caso   = 1;
                switch (Lineas[1])
                {
                case "Departamento":  caso = 0; break;

                case "Casa":  caso = 1; break;

                case "duplex":  caso = 2; break;

                case "Penthhouse":  caso = 3; break;

                case "Terreno":  caso = 4; break;
                }
                Imueble = new Propiedad((TipoDePropiedad)caso, i, Lineas[0]);
                ListaDePropiedad.Add(Imueble);
            }
            return(ListaDePropiedad);
        }
        static void Main(string[] args)
        {
            string           NombreArchivo    = "ListadoInmuebles.csv";
            string           PathArch         = @"C:\TP10\";
            List <Propiedad> ListaPropiedades = new List <Propiedad>();
            FileStream       Arch_Leer        = new FileStream(PathArch + NombreArchivo, FileMode.Open);
            StreamReader     Leer             = new StreamReader(Arch_Leer);

            string Linea;
            int    cont = 0;

            while ((Linea = Leer.ReadLine()) != null)
            {
                int       id       = cont;
                string[]  Dato     = Linea.Split(';');
                string    Doc      = Dato[0];
                string    TipoProp = Dato[1];
                Propiedad Prop     = new Propiedad();
                Prop.CargarInmueble(id, Doc, TipoProp);
                ListaPropiedades.Add(Prop);
                cont++;
            }
            Leer.Close();

            string       NuevoArch     = "ListadoInmueblesCompleto.csv";
            FileStream   Arch_Escribir = new FileStream(PathArch + NuevoArch, FileMode.OpenOrCreate);
            StreamWriter Escribir      = new StreamWriter(Arch_Escribir);

            foreach (Propiedad _prop in ListaPropiedades)
            {
                Escribir.WriteLine(_prop.Id.ToString() + ';' + _prop.Tamanio.ToString() + ';' + _prop.Cantidad_baños.ToString() + ';' + _prop.Cantidad_habitaciones.ToString() + ';' + _prop.Domicilio + ';' + _prop.Operacion + ';' + _prop.Precio + ';' + _prop.Estado + ';' + _prop.Propiedades + ';');
                Console.WriteLine(_prop.Id.ToString() + ';' + _prop.Tamanio.ToString() + ';' + _prop.Cantidad_baños.ToString() + ';' + _prop.Cantidad_habitaciones.ToString() + ';' + _prop.Domicilio + ';' + _prop.Operacion + ';' + _prop.Precio + ';' + _prop.Estado + ';' + _prop.Propiedades + ';');
            }
            Escribir.Close();
        }
Exemple #3
0
        public static void AgregraAlArchivo(Propiedad Agregar, string archivo)
        {
            string texto = "\n";

            texto += Agregar.Id + ";";
            texto += Agregar.Tamanio + ";";
            texto += Agregar.Tpropiedad + ";";
            texto += Agregar.Operacion + ";";

            texto += Agregar.CantidadDeBaños + ";";
            texto += Agregar.CantidadDeHabitaciones + ";";
            texto += Agregar.Domicilio + ";";
            texto += Agregar.Precio + ";";
            texto += Agregar.Estado + ";";
            texto  = texto + Environment.NewLine;
            File.AppendAllText(archivo, texto);
        }