Beispiel #1
0
        public void SendVehNextStop(string preamble)
        {
            string msgText    = "";
            string pickupAddr = "";


            OdbcConnection conn = new OdbcConnection(ConfigurationSettings.AppSettings.Get("MPKODBC"));

            try
            {
                conn.Open();
                using (OdbcCommand ct = conn.CreateCommand())
                {
                    string sqlQuery = "select * from stop, route, passenger where stop.stop_id='" + currentStop + "' and stop.route_id=route.route_id and (pickup=stop.stop_id or dropoff=stop.stop_id)";
                    ct.CommandText = sqlQuery;
                    OdbcDataReader dr    = ct.ExecuteReader();
                    int            count = 0;

                    while (dr.Read())
                    {
                        ++count;
                        pickupAddr = String.Format("{0} {1}%R", dr["ad_str_name"].ToString(), dr["ad_city"].ToString());
                        // Pickup Node
                        if (dr["pickup"].ToString().Equals(dr["stop_id"].ToString()))
                        {
                            msgText += VehFormatPickup(dr);
                        }
                        // Dropoff Node
                        else
                        {
                            msgText += VehFormatDropoff(dr);
                        }
                    }
                    msgText = String.Format("{0}{1}{2}", preamble, pickupAddr, msgText);
                }
                conn.Close();
            }
            catch (OdbcException exc)
            {
                conn.Close();
                log.InfoFormat("Error accessing DB {0}", exc.Message);
            }
            catch (Exception exc)
            {
                conn.Close();
                log.InfoFormat("Error - SendVehNextStop - {0}", exc.Message);
            }

            TPakMsg myTPakMsg = new TPakMsg(vehID.ToString(), "H", "T");

            myTPakMsg.Msg = msgText;
            myTPakMsg.Send();
        }
Beispiel #2
0
        public void ConfirmArrive()
        {
            // Sets routeID, currentStop, nextStop, LocX, LocY properties
            if (GetVehInfo() == false)               // couldn't find any data for this vehicle in tables
            {
                return;
            }

            log.InfoFormat("Vehicle {0} confirms arrival at stop {1}", this.vehID.ToString(), currentStop);
            // Retrieve this stop from STOP table and update the arrival time with a timestamp


            OdbcConnection conn = new OdbcConnection(ConfigurationSettings.AppSettings.Get("MPKODBC"));

            try
            {
                conn.Open();
                using (OdbcCommand ct = conn.CreateCommand())
                {
                    arriveTime = System.DateTime.Now.ToString("yyyyMMdd:HHmmss");
                    string sqlUpdate = "update stop set arrive='" + arriveTime + "' where stop_id='" + currentStop + "'";
                    ct.CommandText = sqlUpdate;
                    ct.ExecuteNonQuery();
                }
                conn.Close();
            }
            catch (OdbcException exc)
            {
                conn.Close();
                log.InfoFormat("Error accessing DB {0}", exc.Message);
            }
            catch (Exception exc)
            {
                conn.Close();
                log.InfoFormat("Error in ConfirmArrive - {0}", exc.Message);
            }

            // If current_stop is same as next_stop we've completed the route
            // send the <stop_visit> to MPK
            if (this.currentStop.Equals(this.nextStop))
            {
                this.departTime = System.DateTime.Now.ToString("yyyyMMdd:HHmmss");
                VehStopVisit();
                TPakMsg myTPakMsg = new TPakMsg(vehID.ToString(), "H", "T");
                myTPakMsg.Msg = "==REITTI LOPPUUN SUORITETTU==";
                myTPakMsg.Send();

                // update the vehicle record so current stop is null
                try
                {
                    conn.Open();
                    using (OdbcCommand ct = conn.CreateCommand())
                    {
                        string sqlUpdate = "update vehicle set current_stop='' where veh_id=" + this.vehID.ToString();
                        ct.CommandText = sqlUpdate;
                        ct.ExecuteNonQuery();
                    }
                    conn.Close();
                }
                catch (OdbcException exc)
                {
                    conn.Close();
                    log.InfoFormat("Error accessing DB {0}", exc.Message);
                }
                catch (Exception exc)
                {
                    conn.Close();
                    log.InfoFormat("Error in ConfirmArrive - {0}", exc.Message);
                }
            }
        }
Beispiel #3
0
        public void SendFirstStop(string routeID)
        {
            string firstStopID = "";

            OdbcConnection conn = new OdbcConnection(ConfigurationSettings.AppSettings.Get("MPKODBC"));

            try
            {
                conn.Open();
                using (OdbcCommand ct = conn.CreateCommand())
                {
                    string sqlQuery = "select * from stop, vehicle where stop.route_id='" + routeID + "' and stop.route_id=vehicle.route_id order by sequence_nbr";
                    ct.CommandText = sqlQuery;
                    OdbcDataReader dr = ct.ExecuteReader();
                    if (dr.Read())
                    {
                        firstStopID = dr["stop_id"].ToString();
                    }
                    else
                    {
                        log.Error(String.Format("Error retrieving stops for vehicle {0} route {1}",
                                                this.vehID.ToString(), routeID));
                        dr.Close();
                        conn.Close();
                        return;
                    }
                    dr.Close();
                }
                conn.Close();
            }
            catch (OdbcException exc)
            {
                conn.Close();
                log.InfoFormat("Error accessing DB {0}", exc.Message);
            }
            catch (Exception exc)
            {
                conn.Close();
                log.InfoFormat("Error in SendFirstStop - {0}", exc.Message);
            }

            log.InfoFormat("Sending first stop {0} to vehicle {1}", firstStopID, this.vehID.ToString());


            string msgText    = "";
            string pickupAddr = "";

            try
            {
                conn.Open();
                using (OdbcCommand ct = conn.CreateCommand())
                {
                    string sqlQuery = "select * from stop,route,passenger where stop_id='" + firstStopID + "' and route.route_id=stop.route_id and (pickup=stop_id)";
                    ct.CommandText = sqlQuery;
                    OdbcDataReader dr = ct.ExecuteReader();
                    while (dr.Read())
                    {
                        pickupAddr = String.Format("{0} {1}%R", dr["ad_str_name"].ToString(), dr["ad_city"].ToString());
                        // Pickup Node
                        if (dr["pickup"].ToString().Equals(dr["stop_id"].ToString()))
                        {
                            msgText += VehFormatPickup(dr);
                        }
                    }
                    msgText = String.Format("{0}{1}", pickupAddr, msgText);
                }
                conn.Close();
            }
            catch (OdbcException exc)
            {
                conn.Close();
                log.InfoFormat("Error accessing DB {0}", exc.Message);
            }
            catch (Exception exc)
            {
                conn.Close();
                log.InfoFormat("Error in SendFirstStop - {0}", exc.Message);
            }



            TPakMsg myTPakMsg = new TPakMsg(vehID.ToString(), "H", "T");

            myTPakMsg.Msg = msgText;
            myTPakMsg.Send();
        }