private void button4_Click(object sender, EventArgs e) // agregar Cabaña { try { int codigo = Int32.Parse(textBox1.Text); string ciudad = textBox2.Text; string barrio = textBox3.Text; int estrella = Int32.Parse(textBox4.Text); int cantP = Int32.Parse(textBox5.Text); bool tv = Boolean.Parse(textBox6.Text); double precioPorHabitacion = Double.Parse(textBox8.Text); int habitacion = Int32.Parse(textBox9.Text); int baño = Int32.Parse(textBox10.Text); c = new Cabaña(codigo, ciudad, barrio, estrella, cantP, tv, precioPorHabitacion, habitacion, baño); aloj.Add(c); Ag.agregarAlojamiento(c); Ag.leerAlojamientos(); MessageBox.Show("Cabaña Ingresada"); foreach (Control c in this.Controls) { if (c is TextBox) { c.Text = ""; } } } catch (FormatException) { MessageBox.Show("Debe ingresar obligatoriamente los campos"); } }
public Agencia alojamientosEntrePrecios(double min, double maximo) { Agencia Salida = new Agencia(this.cantAloj); foreach (Alojamiento alojamiento in alojamientosAgencia) { if (alojamiento is Cabaña) { Cabaña c = (Cabaña)alojamiento; if (c.getPrecioDia() <= maximo && c.getPrecioDia() >= min) { Salida.insertarAlojamiento(c); } } else if (alojamiento is Hotel) { Hotel h = (Hotel)alojamiento; if (h.getPrecioDia() <= maximo && h.getPrecioDia() >= min) { Salida.insertarAlojamiento(h); } } } return(Salida); } // Funciona Ok
public bool agregarAlojamiento(Alojamiento alojamiento) { //bool r=miAgencia.agregarAlojamiento(alojamiento); string path = "Alojamientos.txt"; try { using (StreamWriter sw = File.AppendText(path)) { if (alojamiento is Cabaña) { Cabaña al = (Cabaña)alojamiento; sw.WriteLine(al.getCodigo().ToString() + " " + al.getCiudad() + " " + al.getBarrio() + " " + al.getEstrellas().ToString() + " " + al.getCantPersonas().ToString() + " " + al.getTV().ToString() + " " + al.getPrecioDia().ToString() + " " + al.getHabitacion() + " " + al.getBaño()); } else if (alojamiento is Hotel) { Hotel al = (Hotel)alojamiento; sw.WriteLine(al.getCodigo().ToString() + " " + al.getCiudad() + " " + al.getBarrio() + " " + al.getEstrellas().ToString() + " " + al.getCantPersonas().ToString() + " " + al.getTV().ToString() + " " + al.getPrecioDia().ToString() + " "); } } return(true); } catch (IOException) { return(false); } }
public bool quitarAlojamiento(int codigo) { bool r = miAgencia.eliminarAlojamientoCodigo(codigo); if (r == true) { string path = "Alojamientos.txt"; using (StreamWriter sw = File.CreateText(path)) { for (int w = 0; w < miAgencia.getAlojamientos().Count; w++) { Console.WriteLine(r); if (miAgencia.getAlojamientos()[w] is Cabaña) { Cabaña al = (Cabaña)miAgencia.getAlojamientos()[w]; sw.WriteLine(al.getCodigo().ToString() + " " + al.getCiudad() + " " + al.getBarrio() + " " + al.getEstrellas().ToString() + " " + al.getCantPersonas().ToString() + " " + al.getTV().ToString() + " " + al.getPrecioDia().ToString() + " " + al.getHabitacion() + " " + al.getBaño()); } if (miAgencia.getAlojamientos()[w] is Hotel) { Hotel al = (Hotel)miAgencia.getAlojamientos()[w]; sw.WriteLine(al.getCodigo().ToString() + " " + al.getCiudad() + " " + al.getBarrio() + " " + al.getEstrellas().ToString() + " " + al.getCantPersonas().ToString() + " " + al.getTV().ToString() + " " + al.getPrecioDia().ToString() + " "); } } return(true); } } return(false); }
public void leerAlojamientos() //lee los Alojamientos y los guarda en la lista { string path = "Alojamientos.txt"; string text = System.IO.File.ReadAllText(path); string[] lineas = text.Split('\n'); string[] variables; miAgencia.getAlojamientos().RemoveRange(0, miAgencia.getAlojamientos().Count); for (int i = 0; i < lineas.Length - 1; i++) { Console.WriteLine(lineas[i]); variables = lineas[i].Split(' '); for (int w = 0; w < variables.Length; w++) { Console.WriteLine("numero w: " + w); Console.WriteLine(variables[w]); } Console.WriteLine(variables.Length); if (variables.Length > 8) { try { int codigo = Int32.Parse(variables[0]); string ciudad = variables[1]; string barrio = variables[2]; int estrella = Int32.Parse(variables[3]); int cantPersonas = Int32.Parse(variables[4]); bool TV = bool.Parse(variables[5]); double precioxDia = Double.Parse(variables[6]); int habitacion = Int32.Parse(variables[7]); int baño = Int32.Parse(variables[8]); Cabaña alojamiento = new Cabaña(codigo, ciudad, barrio, estrella, cantPersonas, TV, precioxDia, habitacion, baño); miAgencia.insertarAlojamiento(alojamiento); } catch (FormatException) { Console.WriteLine("Excepcion de Formato"); } } else { int codigo = Int32.Parse(variables[0]); string ciudad = variables[1]; string barrio = variables[2]; int estrella = Int32.Parse(variables[3]); int cantPersonas = Int32.Parse(variables[4]); bool TV = bool.Parse(variables[5]); double precioxDia = Double.Parse(variables[6]); Hotel alojamiento = new Hotel(codigo, ciudad, barrio, estrella, cantPersonas, TV, precioxDia); miAgencia.insertarAlojamiento(alojamiento); } } }
public Agencia cabañasEntrePrecios(double min, double maximo) { Agencia Salida = new Agencia(this.cantAloj); foreach (Alojamiento alojamiento in alojamientosAgencia) { if (alojamiento is Cabaña) { Cabaña c = (Cabaña)alojamiento; if (c.getPrecioDia() <= maximo && c.getPrecioDia() >= min) { Salida.insertarAlojamiento(c); } } } return(Salida); }
private void button1_Click(object sender, EventArgs e) //Mostrar Datos { dataGridView1.Rows.Clear(); List <List <string> > listaString = new List <List <string> >(); listaString.Add(new List <string> { "a", "b" }); listaString.Add(new List <string> { "b", "c" }); listaString.Add(new List <string> { "d", "f" }); List <List <Alojamiento> > listaAloj = new List <List <Alojamiento> >(); List <object> Rows = new List <object>(); for (int i = 0; i < Ag.getAgencia().getAlojamientos().Count; i++) { if (Ag.getAgencia().getAlojamientos()[i] is Hotel) { Hotel al = (Hotel)Ag.getAgencia().getAlojamientos()[i]; List <string> listaS = new List <string>() { "Hotel", al.getCodigo().ToString(), al.getCiudad(), al.getBarrio(), al.getEstrellas().ToString(), al.getCantPersonas().ToString(), al.getTV().ToString(), al.getPrecioDia().ToString() }; Rows.Add(listaS); } else if (Ag.getAgencia().getAlojamientos()[i] is Cabaña) { Cabaña al = (Cabaña)Ag.getAgencia().getAlojamientos()[i]; List <string> listaS = new List <string>() { "Cabaña", al.getCodigo().ToString(), al.getCiudad(), al.getBarrio(), al.getEstrellas().ToString(), al.getCantPersonas().ToString(), al.getTV().ToString(), " ", al.getPrecioDia().ToString(), al.getHabitacion().ToString(), al.getBaño().ToString() }; Rows.Add(listaS); } } foreach (List <string> aj in Rows) { dataGridView1.Rows.Add(aj.ToArray()); } /*for (int i = 0; i < Ag.getAgencia().getAlojamientos().Count; i++) * { * listaAloj.Add(new List<Alojamiento> { Ag.getAgencia().getAlojamientos()[i] }); * } * * * foreach(List<Alojamiento> aj in listaAloj) * { * dataGridView1.Rows.Add(aj.ToArray()); * } */ /*for(int i=0; i< Ag.getAgencia().getAlojamientos().Count; i++) * { * dataGridView1.Rows.Add(Ag.getAgencia().getAlojamientos()[i].getCodigo()); * * }*/ /*foreach (List<string> aj in listaString) * { * dataGridView1.Rows.Add(aj.ToArray()); * }*/ }