/// <summary>
 ///  Clears the database
 /// </summary>
 /// <param name="conn"></param>
 public static void ClearDatabase(DatabaseConnection conn)
 {
     MySqlCommand cmd = new MySqlCommand();
     cmd.Connection = conn.getConnection();
     cmd.CommandText = @"DELETE FROM track_segments";
     cmd.ExecuteNonQuery();
 }
Esempio n. 2
0
        public void runQuery(DatabaseConnection db_connection, MySqlCommand cmd)
        {
            try
            {
                db_connection.openConnection();

                MySqlDataReader reader = cmd.ExecuteReader();
                string row = null;
                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        row += reader.GetValue(i).ToString();
                    }
                    Console.WriteLine(row);

                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());
            }
            finally
            {
                if (db_connection != null)
                {
                    db_connection.closeConnection();
                }

            }
        }
Esempio n. 3
0
        public void databaseConnected()
        {
            DatabaseConnection connection = new DatabaseConnection(
                "andrew.cs.fit.edu",
                    3306,
                    "signalblockdesign",
                    "signalblockdesig",
                    "E2SnzbV922m6R51");

            bool connected = false;

                connection.openConnection();
                connected = true;
                Assert.True(connected);
        }
Esempio n. 4
0
        public void closeDatabaseConnection()
        {
            bool isClosed = false;
            DatabaseConnection connection = new DatabaseConnection(
               "andrew.cs.fit.edu",
                   3306,
                   "signalblockdesign",
                   "signalblockdesig",
                   "E2SnzbV922m6R51");

            connection.openConnection();

            connection.closeConnection();
            isClosed = true;

            Assert.True(isClosed);
        }
 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();
 }
Esempio n. 6
0
        //public void runQuery(DatabaseConnection db_connection, string queryText)
        //{
        //    db_connection.openConnection();
        //    MySqlCommand cmd = db_connection.getConnection().CreateCommand();
        //    cmd.CommandText = queryText;
        //    MySqlDataReader reader = cmd.ExecuteReader();
        //    while (reader.Read())
        //    {
        //        string row = "";
        //        for (int i = 0; i < reader.FieldCount; i++)
        //            row += reader.GetValue(i).ToString() + ", ";
        //        Console.WriteLine(row);
        //    }
        //    db_connection.closeConnection();
        //}
        public List<string> runQuery(DatabaseConnection db_connection, string queryText)
        {
            List<string> result = new List<string>();
            db_connection.openConnection();

            MySqlCommand cmd = db_connection.getConnection().CreateCommand();
            cmd.CommandText = queryText;
            MySqlDataReader reader = cmd.ExecuteReader();

            // string row = "";
            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                    result.Add(reader.GetValue(i).ToString());
                // result.Add(row);
            }

            db_connection.closeConnection();

            return result;
        }
Esempio n. 7
0
        /// <summary>
        /// Loads a track from an excel file
        /// </summary>
        /// <param name="filename"></param>
        private static void LoadExcelFile(object filename)
        {
            ExcelParser parser = new ExcelParser(filename.ToString());
            parser.processData();
            try
            {
                ProgressBoxForm progress = new ProgressBoxForm();
                progress.CurCircuit.Text = "";
                progress.Show();

                DatabaseConnection conn = new DatabaseConnection(
                    Config.ConfigManager.Database,
                    Config.ConfigManager.Port,
                    Config.ConfigManager.DatabaseName,
                    Config.ConfigManager.UserName,
                    Config.ConfigManager.Password);
                conn.openConnection();

                progress.progressBar1.Maximum = TrackLayout.Track.Count - 1;
                progress.progressBar1.Step = 1;
                int current = 1;
                Cursor.Current = Cursors.WaitCursor;
                foreach (TrackSegment t in TrackLayout.Track)
                {
                    DatabaseOperations.InsertIntoDatabase(conn, t);
                    progress.progressBar1.PerformStep();
                    progress.CurCircuit.Text = "Currently processing Track Circuit " + current + " of " + TrackLayout.Track.Count + "...";
                    current++;
                    progress.CurCircuit.Refresh();
                    Thread.Sleep(500);
                }
                Cursor.Current = Cursors.Default;
                progress.Close();
                conn.closeConnection();
            }
            catch (Exception ex)
            {
                LogManager.Logger.Log(ex);
            }
            parser.cleanUp();
        }