public static void removeFromDatabase(DatabaseConnection conn, Query q, TrackSegment obj)
 {
     MySqlCommand cmd = new MySqlCommand();
     cmd.CommandText =
         @"Delete from track_segments (trackCircuit, brakeLocation, targetLocation, worst_case_grade_during_stop, max_entry_speed, overSpeed, vehicleAccel, reactionTime, brakeRate, runwayAccel, propulsion, build_up_brake, overhang) VALUES (@trackCircuit, @brakeLocation, @targetLocation, @worst_case_grade_during_stop, @max_entry_speed, @overSpeed, @vehicleAccel, @reactionTime, @brakeRate, @runwayAccel, @propulsion, @build_up_brake, @overhang)";
     cmd.Parameters.AddWithValue("@trackCircuit", obj.TrackCircuit);
     cmd.Parameters.AddWithValue("@brakeLocation", obj.StartPoint);
     cmd.Parameters.AddWithValue("@targetLocation", obj.EndPoint);
     cmd.Parameters.AddWithValue("@worst_case_grade_during_stop", obj.GradeWorst);
     cmd.Parameters.AddWithValue("@max_entry_speed", obj.SpeedMax);
     cmd.Parameters.AddWithValue("@overSpeed", obj.OverSpeed);
     cmd.Parameters.AddWithValue("@vehicleAccel", obj.VehicleAccel);
     cmd.Parameters.AddWithValue("@reactionTime", obj.ReactionTime);
     cmd.Parameters.AddWithValue("@brakeRate", obj.BrakeRate);
     cmd.Parameters.AddWithValue("@runwayAccel", obj.RunwayAccelSec);
     cmd.Parameters.AddWithValue("@propulsion", obj.PropulsionRemSec);
     cmd.Parameters.AddWithValue("@build_up_brake", obj.BrakeBuildUpSec);
     cmd.Parameters.AddWithValue("@overhang", obj.OverhangDist);
     cmd.Connection = conn.getConnection();
     cmd.ExecuteNonQuery();
 }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        public static void LoadFromDatabase()
        {
            TrackLayout.Track.Clear();
            LoadFromDatabaseForm databaseForm = new LoadFromDatabaseForm();
            if (databaseForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    // TODO: Set up the database
                    Database.DatabaseConnection conn = new Database.DatabaseConnection(databaseForm.ServerNameBox.Text,
                        Convert.ToUInt32(databaseForm.PortBox.Text), databaseForm.DatabaseNameBox.Text,
                        databaseForm.UserNameBox.Text, databaseForm.PasswordBox.Text);

                    Query q = new Query();
                    List<string> list;

                    String p = Prompt.ShowDialog("Enter A Track Circuit\n\n Type 'ALL' to Display Every Track Circuit", "Track Information Needed!");
                    if (p.Trim().ToUpper() == "ALL")
                    {
                        list = q.runQuery(conn, "SELECT * FROM track_segments");
                    }
                    else
                    {
                        list = q.runQuery(conn, "SELECT * FROM track_segments where trackCircuit = '" + p.Trim() + "'");
                    }

                    int numRows = list.Count / 15;
                    TrackSegment ts;

                    for (int i = 0; i < numRows; i++)
                    {
                        var offset = 15*i;
                        bool exists = false;
                        ts = new TrackSegment(list[offset + 0].ToString(), list[offset + 1].ToString(), list[offset + 2].ToString(), Convert.ToInt32(list[offset + 3].ToString()), Convert.ToInt32(list[offset + 4].ToString()), Convert.ToDouble(list[offset + 5].ToString()),
                             Convert.ToDouble(list[offset + 6].ToString()), Convert.ToDouble(list[offset + 7].ToString()), Convert.ToDouble(list[offset + 8].ToString()), Convert.ToDouble(list[offset + 9].ToString()),
                             Convert.ToDouble(list[offset + 10].ToString()), Convert.ToDouble(list[offset + 11].ToString()), Convert.ToDouble(list[offset + 12].ToString()), Convert.ToInt32(list[offset + 13].ToString()),
                             Convert.ToInt32(list[offset + 14].ToString()));
                         foreach(TrackSegment segment in TrackLayout.Track)
                         {
                              if (ts.IsSame(segment))
                              {
                                   exists = true;
                              }
                         }
                         if(!exists)
                         {
                              TrackLayout.Track.Add(ts);
                         }

                    }
                }
                catch (Exception ex)
                {
                    LogManager.Logger.Log(ex);
                }
            }
        }