// THIS FUNCTION IS TO SHOW THE PLANET INFORMATION WHICH IS STORED BY ADD PAGE . // HERE WE TAKING VALUES FROM DATABASE FOR PLANET TITLE AND PLANET DETAILS. protected void ShowplanetInfo(PLANETSDB db) { bool valid = true; string planetsid = Request.QueryString["planets_id"]; if (String.IsNullOrEmpty(planetsid)) { valid = false; } if (valid) { planet planets_record = db.Findplanet(Int32.Parse(planetsid)); planets_title.InnerHtml += planets_record.GetPtitle(); planets_body.InnerHtml += planets_record.GetPbody(); } else { valid = false; } if (!valid) { planet.InnerHtml = "There was an error finding that planet."; } }
protected void pageNav(PLANETSDB db) { pagenav1.InnerHtml = ""; string searchkey = ""; // THIS IS THE QUERY WE USE TO ACESS DATA FROM TABLE PLANET string query = "select * from planets"; if (searchkey != "") { query += " WHERE planets_id like '%" + searchkey + "%' "; query += " or planets_title like '%" + searchkey + "%' "; query += " or planets_body like '%" + searchkey + "%' "; } // HERE WE ADD DATA TO THE UL WE DEFINED IN THE IN ASCX PAGE. //var db = new PLANETSDB(); List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { pagenav1.InnerHtml += "<div class=\"listitem\">"; // THIS IS TO GET PLANET ID FROM THE DATABASE string planet_id = row["planets_id"]; //planets_result.InnerHtml += "<div class=\"col1\">" + planet_id + "</div>"; // THIS IS TO GET PLANET TITLE FROM THE DATABASE string planet_title = row["planets_title"]; pagenav1.InnerHtml += "<a href=\"showplanets.aspx?planets_id=" + planet_id + "\">" + planet_title + "</a>"; //string planet_body = row["planets_body"]; //planets_result.InnerHtml += "<div class=\"col\">" + planet_body + "</div>"; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { PLANETSDB db = new PLANETSDB(); ShowPlanetInfo(db); } }
// 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"); }
// ALSO ON THIS PAGE I HAVE ADDED A FUNCTIONALITY TO DELETE THE PLANET IF ITS NOT NEEDED ANYMORE. protected void Delete_planet(object sender, EventArgs e) { bool valid = true; string planetid = Request.QueryString["planets_id"]; if (String.IsNullOrEmpty(planetid)) { valid = false; } PLANETSDB db = new PLANETSDB(); //HERE WE ARE REDIRECTING IT TO THE MAIN PAGE. if (valid) { db.Delete_planet(Int32.Parse(planetid)); 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."; } }
protected void Page_Load(object sender, EventArgs e) { PLANETSDB db = new PLANETSDB(); ShowplanetInfo(db); }
protected void Page_Load(object sender, EventArgs e) { PLANETSDB db = new PLANETSDB(); pageNav(db); }