protected void Update_Page(object sender, EventArgs e) { //this connection instance is for editing data Dbconnection db = new Dbconnection(); bool valid = true; string Pageid = Request.QueryString["pageid"]; if (!String.IsNullOrEmpty(Pageid)) { HttpPage new_HttpPage = new HttpPage(); //set that Page data new_HttpPage.SetPageTitle(pagetitle.Text); new_HttpPage.SetPageContent(pagecontent.Text); new_HttpPage.SetPageAuthor(pageauthor.Text); //add the Page data to the database try { db.UpdatePage(Int32.Parse(Pageid), new_HttpPage); Response.Redirect("ViewPage.aspx?pageid=" + Pageid); } catch { valid = false; } } }
protected void Add_Page(object sender, EventArgs e) { //create connection Dbconnection db = new Dbconnection(); //create a new particular student HttpPage new_HttpPage = new HttpPage(); //set that student data new_HttpPage.SetPageTitle(pagetitle.Text); new_HttpPage.SetPageContent(pagecontent.Text); new_HttpPage.SetPageAuthor(pageauthor.Text); DateTime dateTimeVariable = DateTime.Now; string date = dateTimeVariable.ToString("yyyy-MM-dd H:mm:ss"); new_HttpPage.SetPagePublish_Date(date); //add the student to the database db.AddPage(new_HttpPage); Response.Redirect("ListPages.aspx"); }
//Get All Pages From Databas public HttpPage FindHttpPage(int id) { MySqlConnection Connect = new MySqlConnection(ConnectionString); HttpPage result_HttpPage = new HttpPage(); try { string query = "select * from pages where pageid = " + id; Debug.WriteLine("Connection Initialized..."); Connect.Open(); MySqlCommand cmd = new MySqlCommand(query, Connect); MySqlDataReader resultset = cmd.ExecuteReader(); List <HttpPage> Pages = new List <HttpPage>(); while (resultset.Read()) { HttpPage currentHttpPage = new HttpPage(); 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 "pagetitle": currentHttpPage.SetPageTitle(value); break; case "pagebody": currentHttpPage.SetPageContent(value); break; case "author": currentHttpPage.SetPageAuthor(value); break; case "Publish_Date": currentHttpPage.SetPagePublish_Date(value); break; } } Pages.Add(currentHttpPage); } result_HttpPage = Pages[0]; } catch (Exception ex) { Debug.WriteLine("Something went wrong in the find page method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_HttpPage); }