public void SendVehNextStop(string preamble) { string msgText = ""; string pickupAddr = ""; SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings.Get("ConnString2")); try { conn.Open(); using (SqlCommand 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)"; log.InfoFormat("{0}", sqlQuery); ct.CommandText = sqlQuery; SqlDataReader 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); log.InfoFormat("{0}", msgText); } conn.Close(); } catch (SqlException 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(); }
public void SendFirstStop(string routeID) { string firstStopID = ""; SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings.Get("MPKODBC")); try { conn.Open(); using (SqlCommand 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; SqlDataReader 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 (SqlException 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 (SqlCommand 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; SqlDataReader 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); } } dr.Close(); 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(); }