protected void AddButton_Click(object sender, EventArgs e) { WebsiteDB db = new WebsiteDB(); Webpage webpage = new Webpage(); //set the title, body and author from the textbox to the webpage class webpage.set_W_title(txtpage_title.Text); webpage.set_W_body(txtpage_body.InnerText); webpage.set_W_author(ddpage_author.SelectedValue); //if user checks the publish checkbox set the state to published and publish date to the current date and time if (chkpublish.Checked == true) { webpage.set_W_publish_state("Published"); //convert date and time to ex.(Saturday, 15 July 2019 5:00 AM) webpage.set_W_publish_date(DateTime.Now.ToString("dddd, dd MMMM yyyy h:mm tt")); } //if user doesnt check the checkbox set the state to not published else { webpage.set_W_publish_state("Not Published"); } //use the webpage class to pass the variables to the addwebpage method in the database class db.AddWebpage(webpage); Response.Redirect("ListWebpages.aspx"); }
public Webpage FindWebPage(int id) { MySqlConnection sqlCon = new MySqlConnection(ConnectionString); Webpage result_page = new Webpage(); try { string query = "select * from PAGES where page_id = " + id; sqlCon.Open(); MySqlCommand cmd = new MySqlCommand(query, sqlCon); MySqlDataReader resultset = cmd.ExecuteReader(); List <Webpage> page = new List <Webpage>(); while (resultset.Read()) { Webpage currentpage = new Webpage(); 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 "page_title": currentpage.set_W_title(value); break; case "page_body": currentpage.set_W_body(value); break; case "publish_author": currentpage.set_W_author(value); break; case "publish_state": currentpage.set_W_publish_state(value); break; case "publish_date": currentpage.set_W_publish_date(value); break; } } page.Add(currentpage); } result_page = page[0]; } catch (Exception ex) { Debug.WriteLine("Check the findWebpage()"); Debug.WriteLine(ex.ToString()); } sqlCon.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_page); }