protected void ShowSeasonInfo(seasondb db) { bool valid = true; string season_id = Request.QueryString["seasonid"]; if (String.IsNullOrEmpty(season_id)) { valid = false; } if (valid) { http_page season_record = db.FindPage(Int32.Parse(season_id)); s_title.InnerHtml += season_record.GetStitle(); s_body.InnerHtml += season_record.GetSbody(); } else { valid = false; } if (!valid) { main_content.InnerHtml = "There was an error finding the season."; } }
protected void Update_Page(object sender, EventArgs e) { seasondb db = new seasondb(); bool valid = true; string season_id = Request.QueryString["seasonid"]; if (String.IsNullOrEmpty(season_id)) { valid = false; } if (valid) { http_page new_season = new http_page(); new_season.SetStitle(s_title.Text); new_season.SetSbody(s_body.Text); try { db.UpdatePage(Int32.Parse(season_id), new_season); Response.Redirect("listpages.aspx?seasonid=" + season_id); } catch { valid = false; } } }
public http_page FindPage(int seasonId) { MySqlConnection Connect = new MySqlConnection(ConnectionString); http_page result_season = new http_page(); try { //finding a particular season based on seasonid information string query = "select * from season where seasonid = " + seasonId; Debug.WriteLine("Connection Initialized..."); Connect.Open(); MySqlCommand cmd = new MySqlCommand(query, Connect); MySqlDataReader resultset = cmd.ExecuteReader(); List <http_page> seasons = new List <http_page>(); while (resultset.Read()) { http_page currentseason = new http_page(); 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 "seasontitle": currentseason.SetStitle(value); break; case "seasonbody": currentseason.SetSbody(value); break; } } seasons.Add(currentseason); } result_season = seasons[0]; } catch (Exception ex) { Debug.WriteLine("Something went wrong in the find season method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_season); }
protected void Add_Page(object sender, EventArgs e) { seasondb db = new seasondb(); http_page new_season = new http_page(); new_season.SetStitle(season_title.Text); new_season.SetSbody(season_body.Text); db.AddPage(new_season); Response.Redirect("listpages.aspx"); }
public void AddPage(http_page new_season) { Debug.WriteLine("Add query method started......"); //adding a new season string query = "insert into season (seasontitle, seasonbody) values ('{0}','{1}')"; query = String.Format(query, new_season.GetStitle(), new_season.GetSbody()); MySqlConnection Connect = new MySqlConnection(ConnectionString); MySqlCommand cmd = new MySqlCommand(query, Connect); try { Connect.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Debug.WriteLine("Something went wrong in the AddSeason Method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); }
public void UpdatePage(int season_id, http_page new_season) { Debug.WriteLine("Update query method started......"); //updating a particular season based on seasonid information string query = "update season set seasontitle ='{0}', seasonbody = '{1}' where seasonid = '{2}'"; query = String.Format(query, new_season.GetStitle(), new_season.GetSbody(), season_id); MySqlConnection Connect = new MySqlConnection(ConnectionString); MySqlCommand cmd = new MySqlCommand(query, Connect); try { Connect.Open(); cmd.ExecuteNonQuery(); Debug.WriteLine("Execute query " + query); } catch (Exception e) { Debug.WriteLine("Something went wrong in the Update Method"); Debug.WriteLine(e.ToString()); } Connect.Close(); }