protected void editButton_Click(object sender, EventArgs e) { try { Announcement a = new Announcement(); a.Title = announcemenTitle.Text; a.Text = announcementText.Text; a.locked = announcementLocked.Checked; GlobalHandlers.Debugger.write("text: " + a.Text); int outParse = 0; Int32.TryParse(idOfAnnouncement.Value, out outParse); a.ID = outParse; GlobalHandlers.Debugger.write("Announcement title: " + a.Title + " Text: " + a.Text + " Id: " + a.ID); bool isUpdated = GlobalHandlers.DatabaseHandler.updateAnnouncement(a); if (isUpdated) { Response.AppendCookie(new HttpCookie("edited", a.Title)); Response.Redirect("default.aspx", false); } } catch (Exception ee) { GlobalHandlers.Debugger.write(ee.ToString()); } }
public List<Announcement> getAnnouncements() { List<Announcement> n = new List<Announcement>(); if (MySqlConnection.State == System.Data.ConnectionState.Open) { try { MySqlCommand cmd = new MySqlCommand("SELECT * FROM `announcements`", MySqlConnection); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows == false) { reader.Close(); cmd.Dispose(); return n; } while (reader.Read()) { string txt = reader["text"].ToString().HtmlDecode(); string title = reader["title"].ToString(); int id = Int32.Parse(reader["id"].ToString()); string locked = reader["locked"].ToString(); Announcement ac = new Announcement(); ac.Text = txt; ac.ID = id; ac.Title = title; if (locked == "True") ac.locked = true; n.Add(ac); } reader.Close(); return n; } } catch (MySqlException expc) { GlobalHandlers.Debugger.write(expc.ToString()); } } return n; }
public bool updateAnnouncement(Announcement announcement) { try { if (MySqlConnection.State == System.Data.ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand("UPDATE `announcements` SET `text` = ?text, `title` = ?title, `locked` = ?locked WHERE `id` = ?id", MySqlConnection); cmd.Parameters.AddWithValue("?text", announcement.Text); cmd.Parameters.AddWithValue("?title", announcement.Title); cmd.Parameters.AddWithValue("?locked", announcement.locked.ToString()); cmd.Parameters.AddWithValue("?id", announcement.ID.ToString()); var result = cmd.ExecuteNonQuery(); cmd.Dispose(); if (!result.Equals(0)) return true; return false; } return false; } catch (Exception eee) { Debug.WriteLine(eee); } return false; }