// THIS IS TO ADD PLANET PAGES TO THE PLANET PAGES protected void Add_Planet(object sender, EventArgs e) { PLANETSDB db = new PLANETSDB(); planet new_planet = new planet(); new_planet.SetPtitle(planets_title.Text); new_planet.SetPbody(planets_body.Text); db.Addplanet(new_planet); Response.Redirect("planetpages.aspx"); }
// THIS IS THE FUNCTION TO UPDATE THE PLANET WITH THEIR DETAILS protected void Update_Planet(object sender, EventArgs e) { PLANETSDB db = new PLANETSDB(); bool valid = true; string planetid = Request.QueryString["planets_id"]; if (String.IsNullOrEmpty(planetid)) { valid = false; } if (valid) { planet new_planet = new planet(); new_planet.SetPtitle(planets_title.Text); new_planet.SetPbody(planets_body.Text); try { db.Updateplanet(Int32.Parse(planetid), new_planet); Response.Redirect("planetpages.aspx?planetid=" + planetid); } catch { valid = false; } } if (!valid) { planet.InnerHtml = "There was an error updating that planet."; } }
//HERE IS THE FUNCTIONALITY TO FIND A PLANET FROM THE DATABASE public planet Findplanet(int id) { Debug.WriteLine("method started"); MySqlConnection Connect = new MySqlConnection(ConnectionString); planet result_planet = new planet(); try { string query = "select * from planets where planets_id = " + id; Debug.WriteLine("Connection Initialized..."); Connect.Open(); MySqlCommand cmd = new MySqlCommand(query, Connect); MySqlDataReader resultset = cmd.ExecuteReader(); List <planet> planets = new List <planet>(); while (resultset.Read()) { planet currentplanet = new planet(); for (int i = 0; i < resultset.FieldCount; i++) { string key = resultset.GetName(i); string value = resultset.GetString(i); Debug.WriteLine("Attempting to transfer " + key + " data of " + value); switch (key) { case "planets_title": currentplanet.SetPtitle(value); break; case "planets_body": currentplanet.SetPbody(value); break; } } planets.Add(currentplanet); } result_planet = planets[0]; } catch (Exception ex) { Debug.WriteLine("Something went wrong in the find planet method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_planet); }