/// <summary> /// Retorna una lista con las ciudades cargadas luego de seleccionar los radio buttons (casa/apartamento y alquiler/compra). /// </summary> /// <returns></returns> public ArrayList Ciudades() { ListaCiudades.Clear(); foreach (Inmueble i in ListaInmuebles) { if (!ListaCiudades.Contains(i.Ciudad)) { ListaCiudades.Add(i.Ciudad); } } return(ListaCiudades); }
private void button1_Click(object sender, EventArgs e) { string cityName = textBox1.Text; bool flag = true; if (cityName == "") { MessageBox.Show("No se puede Dejar en blanco"); } else { if (listaCity.Count == 0) { Ciudades ciudad = new Ciudades(valorX, valorY, cityName); listaCity.Add(ciudad); button1.Enabled = false; } else { for (int i = 0; i < listaCity.Count; i++) { if (listaCity[i].abreviacion == cityName) { MessageBox.Show("Esta repetido, hay Pedo"); flag = false; break; } if (flag && i == listaCity.Count - 1) { Ciudades city = new Ciudades(valorX, valorY, cityName); listaCity.Add(city); button1.Enabled = false; break; } } } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Principal()); ListaVuelos listaVuelos = new ListaVuelos(); ListaCiudades listaciudades = new ListaCiudades(); try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader("infoVuelos.txt")) { // Read the stream to a string, and write the string to the console. while (!sr.EndOfStream) { String line = sr.ReadLine(); string[] datavuelo = line.Split('|'); Console.WriteLine(datavuelo[5]); DateTime date = DateTime.Parse(datavuelo[5]); Vuelo vuelo = new Vuelo(int.Parse(datavuelo[0]),datavuelo[1], datavuelo[2], int.Parse(datavuelo[4]), int.Parse(datavuelo[3]),date); listaVuelos.Add(vuelo); } } } catch (Exception e) { Console.WriteLine("The file Info vueloes could not be read:"); Console.WriteLine(e.Message); return; } //Leyendo usuarios try { using (StreamReader ifile = new StreamReader("usuarios.txt")) { while(!ifile.EndOfStream) { string uline = ifile.ReadLine(); string[] du = uline.Split('|'); int indexV = int.Parse(du[0]); //indice es igual a al primer campo de du Usuario user = new Usuario(du[1], du[2], du[4], int.Parse(du[3])); listaVuelos[indexV].userlist.Add(user); listaVuelos[indexV].setAsientoTomado(int.Parse(du[3])); } } } catch(Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } //Leyendo Ciudades try { using (StreamReader ifile = new StreamReader("Ciudades.txt")) { while (!ifile.EndOfStream) { string cline = ifile.ReadLine(); string[] cu = cline.Split('|'); List<AristaCiudad> aristas = new List<AristaCiudad>(); CiudadNodo city = new CiudadNodo(float.Parse(cu[0]), float.Parse(cu[1]), cu[2],aristas); listaciudades.Add(city); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } //Leyendo Aristas try { using (StreamReader ifile = new StreamReader("Aristas.txt")) { while (!ifile.EndOfStream) { string aline = ifile.ReadLine(); string[] au = aline.Split('|'); AristaCiudad arista = new AristaCiudad(float.Parse(au[1]), float.Parse(au[2]),au[0], au[3], int.Parse(au[4]),int.Parse(au[5])); int ind = listaciudades.getcityIndex(au[0]); listaciudades[ind].Aristas.Add(arista); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } Principal ventanaPrincipal = new Principal(ref listaVuelos,ref listaciudades); ventanaPrincipal.ShowDialog(); //codigo para escribir //string lines = "First line.\r\nSecond line.\r\nThird line."; StreamWriter file = new StreamWriter("infoVuelos.txt"); StreamWriter file2 = new StreamWriter("usuarios.txt"); int vindex=0; foreach (Vuelo v in listaVuelos) { file.WriteLine(v.ToString('|')); foreach(Usuario u in v.userlist) { file2.WriteLine(vindex.ToString()+'|'+u.ToString()); } vindex++; } file.Close(); file2.Close(); StreamWriter filecity = new StreamWriter("Ciudades.txt"); StreamWriter fileari = new StreamWriter("Aristas.txt"); foreach(CiudadNodo c in listaciudades) { filecity.WriteLine(c.X.ToString() + '|' + c.Y.ToString() + '|' + c.getName()); foreach (AristaCiudad a in c.Aristas) { fileari.WriteLine(c.getName() + '|' + a.ToString()); } } filecity.Close(); fileari.Close(); Console.WriteLine("fin del programa"); }