//Lee el archivo donde estan los nombres y rutas de los buses public void nameBus() { try { ICollection buses = bus1.Keys; StreamReader lector = new StreamReader(RELATIVE_PATH_LINES); // Hashtable name = new Hashtable(); String line = lector.ReadLine(); line = lector.ReadLine(); while (line != null) { String[] l = line.Split(','); if (!Routes.ContainsKey(l[0])) { // Console.WriteLine("agrega " + l[0]+" "+ l[2]+ " "+ l[3]); Routes.Add(l[0], new Bus(l[0], l[2], l[3])); } line = lector.ReadLine(); } relationBus(); } catch (DirectoryNotFoundException dnf) { LoadDate = new DialogDataAddress(this); LoadDate.ErrorLine("No se encontro el archivo de lines"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } catch (ArgumentException ae) { LoadDate = new DialogDataAddress(this); LoadDate.ErrorLine("Se esta cargando el archivo equivocado de lines"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } catch (IndexOutOfRangeException ae) { LoadDate.ErrorStop("Se esta cargando el archivo equivocado de lines"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } }
//Constructor public Managment() { Routes = new Hashtable(); Stops = new Hashtable(); Stations = new Hashtable(); Bus1 = new Hashtable(); absolutePath(); // año dia mes min hor seg RealTime = new GenericTime(18, 01, 11, 35, 5, 25, "AM"); LoadDate = new DialogDataAddress(this); Load(); }
//Crea los buses public void createBus() { try { StreamReader lector = new StreamReader(RELATIVE_PATH_BUS); String line = lector.ReadLine(); line = lector.ReadLine(); while (line != null) { String[] bus = line.Split(','); if (!bus1.ContainsKey(bus[0])) { if (bus[2].Equals("")) { Bus nuevo = new Bus(bus[0], "Sin placa"); bus1.Add(bus[0], nuevo); } else { Bus nuevo = new Bus(bus[0], bus[2]); bus1.Add(bus[0], nuevo); } } line = lector.ReadLine(); } } catch (DirectoryNotFoundException dnf) { LoadDate = new DialogDataAddress(this); LoadDate.ErrorBus("No se encontro el archivo de buses"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } catch (ArgumentException ae) { LoadDate = new DialogDataAddress(this); LoadDate.ErrorBus("Se esta cargando el archivo equivocado de buses"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } catch (IndexOutOfRangeException ae) { LoadDate.ErrorStop("Se esta cargando el archivo equivocado de buses"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } }
//Le asigna a todos los buses la hora y la posicion que se va mover public void timeReading() { try { StreamReader sr = new StreamReader(RELATIVE_PATH_DATAGRAM); String line = sr.ReadLine(); line = sr.ReadLine(); while (line != null) { String[] dato = line.Split(','); Boolean terminado = false; while (!terminado) { if (dato[4].Equals("-1") || dato[5].Equals("-1")) { line = sr.ReadLine(); dato = line.Split(','); } else { terminado = true; } } if (cont < 1048575) { String lat = dato[4].Insert(1, ","); String lon = dato[5].Insert(3, ","); if (bus1.ContainsKey(dato[11])) { ((Bus)bus1[dato[11]]).addTime(lat, lon, dato[10]); if (!(dato[7].Equals("-1"))) { // Console.WriteLine("3ntra "+dato[7]); ((Bus)bus1[dato[11]]).IdLine = dato[7]; } } cont++; // progress.porcentaje(cont); line = sr.ReadLine(); } else { line = null; } } sr.Close(); // nameBus(); nameBus(); Console.WriteLine("cargado"); //prueba2(); } catch (DirectoryNotFoundException dnf) { LoadDate = new DialogDataAddress(this); LoadDate.ErrorDatagram("No se encuentra el archivo datagram"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } catch (ArgumentException ae) { LoadDate = new DialogDataAddress(this); LoadDate.ErrorDatagram("Archivo equivocado de datagram"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } catch (IndexOutOfRangeException ae) { LoadDate.ErrorStop("Archivo equivocado de datagram"); if (LoadDate.Estado == false) { LoadDate.DialogError(); LoadDate.ShowDialog(); LoadDate.Estado = true; } } }