Exemplo n.º 1
0
 /// <summary>
 ///  
 /// </summary>
 public static void ClearDataBase()
 {
     DialogResult result = MessageBox.Show("Are you sure you want to delete the contents of the database?", "Are you sure...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
     if (result == DialogResult.Yes)
     {
         try
         {
             LoadFromDatabaseForm databaseForm = new LoadFromDatabaseForm();
             Database.DatabaseConnection conn = new Database.DatabaseConnection(databaseForm.ServerNameBox.Text,
             Convert.ToUInt32(databaseForm.PortBox.Text), databaseForm.DatabaseNameBox.Text,
             databaseForm.UserNameBox.Text, databaseForm.PasswordBox.Text);
             conn.openConnection();
             Database.DatabaseOperations.ClearDatabase(conn);
         }
         catch (Exception ex)
         {
             LogManager.Logger.Log(ex);
         }
     }
 }
Exemplo n.º 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);
                }
            }
        }