using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Admin { /// this is a content blocker page just to make db access easy public partial class EditEventContent : WebBlocks.AdministrativePage { private int EventID { get { return (ViewState["EventID"] == null ? 0 : (int)ViewState["EventID"]); } set { ViewState["EventID"] = value; } } private void Page_Load(object sender, System.EventArgs e) { // if there was a content ID supplied, grab contents from database if (!Page.IsPostBack) { // store the return path for later if (Request.UrlReferrer != null) Session["returnPath"] = Request.UrlReferrer.AbsoluteUri; if (Request.QueryString["EventID"] != null) { EventID = Int32.Parse(Request.QueryString["EventID"]); // check if we are deleting. if we are, we'll delete and bail the rest of the page if (Request.QueryString["delete"] != null) { // delete Database.Events_Delete(EventID); if (Session["returnPath"] != null) Response.Redirect(Session["returnPath"].ToString(), true); else Response.Redirect("ShowEventContents.aspx", true); } DataRow dr = Database.Events_GetByEventID(EventID); if (dr != null) { if (dr["Date"] == DBNull.Value) calDate.SelectedValue = null; else { calDate.SelectedDate = (DateTime)dr["Date"]; calDate.VisibleDate = (DateTime)dr["Date"]; } txtTitle.Text = (string)dr["Title"]; txtCategory.Text = (string)dr["Category"]; txtEventDescription.Value = (string)dr["FullText"]; } } } } protected void btnSubmit_Click1(object sender, EventArgs e) { if (EventID == 0) Database.Events_Add(txtTitle.Text, calDate.SelectedValue, txtCategory.Text, txtEventDescription.Value); else Database.Events_Update(EventID, txtTitle.Text, calDate.SelectedValue, txtCategory.Text, txtEventDescription.Value); if (Session["returnPath"] != null) Response.Redirect(Session["returnPath"].ToString(), false); else Response.Redirect("ShowEventContents.aspx", false); } } }