Example #1
0
        /* Código referente ao cadastro dos Ônibus juntamente com suas Rotas.
         É feito um join da rota do ônibus com as estações em que ele passa. Portanto, DEVE ser feito o
            cadastro das estações de ônibus ANTES de adicionar a rota.
         É realizado um insert nas tabelas BUSES, ROUTES e STATION_BUSES */
        private bool addBusRoutes(KmlFile kml)
        {
            BUS bus = new BUS();
            ROUTE route = new ROUTE();
            DBRoute dbRoute = new DBRoute(context);
            DBStation dbStation = new DBStation(context);

            route.BUS = bus;

            StringBuilder sb = new StringBuilder("LINESTRING (");
            bus.Bus_Description = Methods.getBusDescription(kml);
            bool hasStation = false;

            foreach (var folder in kml.Root.Flatten().OfType<Folder>())
            {
                if (folder.Flatten().OfType<SharpKml.Dom.LineString>().Any())
                {
                    DBStation_Bus dbStationBus = new DBStation_Bus(context);

                    foreach (var placemark in folder.Flatten().OfType<SharpKml.Dom.Placemark>())
                    {
                        parseLineString(placemark, sb); // grava a rota do onibus
                        hasStation = parsePoint(placemark, dbStationBus, dbStation, bus, route, hasStation); // grava as estacoes que o onibus passa
                    }
                }
            }

            if (!hasStation)
            {
                string message = "The stations this bus pass by are not in the database. Please insert the stations first, then the bus route";
                Methods.DisplayMessage(lblMessage, message, Color.Red);
                throw new Exception(message);
            }

            route.Route_Coordinates = DbGeography.LineFromText(sb.Replace(',', ')', sb.Length - 1, 1).ToString(), 4326);

            dbRoute.Add(route);
            return true;
        }
Example #2
0
 public void AddStation_Buses_Route(ROUTE route, STATION_BUSES stationBus)
 {
     dBase.STATION_BUSES.Add(stationBus);
     dBase.SaveChanges();
 }
Example #3
0
        private bool parsePoint(Placemark placemark, DBStation_Bus dbStationBus, DBStation dbStation, BUS bus, ROUTE route, bool hasStation)
        {
            foreach (var lineString in placemark.Flatten().OfType<SharpKml.Dom.Point>())
            {
                IList<STATION> stationsNear = dbStation.SelectStationsNear(50,
                    Methods.ConvertLatLonToDbGeography(lineString.Coordinate.Longitude, lineString.Coordinate.Latitude));

                foreach (var station in stationsNear)
                {
                    STATION_BUSES stationBus = new STATION_BUSES();

                    stationBus.STATION = station;
                    stationBus.BUS = bus;

                    dbStationBus.AddStation_Buses_Route(route, stationBus);
                    hasStation = true;
                }
            }
            return hasStation;
        }
Example #4
0
 public void Add(ROUTE route)
 {
     dBase.ROUTEs.Add(route);
     dBase.SaveChanges();
 }