Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        private void btnClearAll_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete all records?", "Confirmation", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (context = new Teste_OnibusContext())
                    {
                        DBLandmark dbLandmark = new DBLandmark(context);
                        dbLandmark.DeleteAll();

                        DBBus dbBus = new DBBus(context);
                        dbBus.DeleteAll();

                        DBStation dbStation = new DBStation(context);
                        dbStation.DeleteAll();

                        Methods.DisplayMessage(lblMessage, "All records deleted successfully!", Color.Green);
                    }
                }
                catch (Exception ex)
                {
                    Methods.DisplayMessage(lblMessage, "It was not possible to delete the records!", Color.Red);
                }
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 4
0
        private void addStation(Placemark placemark, SharpKml.Dom.Point point, DbGeography coordinates)
        {
            STATION station = new STATION();

            station.Station_Description = placemark.Name;
            station.Station_Coordinates = coordinates;

            DBStation db = new DBStation(context);
            db.Add(station);
        }