using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using ButterfieldGardens.Web; public partial class admin_index : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] == null) { Response.Redirect("/admin/"); } Navigation objNav = new Navigation(); header.InnerHtml = objNav.GetAdminHeader(); adminNav.InnerHtml = objNav.GetAdminSubNavMenu("events"); footer.InnerHtml = objNav.GetFooter(false, false); Page.MaintainScrollPositionOnPostBack = true; } protected void SaveEvent(object sender, EventArgs e) { try { ValidateUserInput(); AddEvent(); DisplaySuccessMessage(); } catch (Exception ex) { DisplayErrorMessage(ex); } } public void ValidateUserInput() { Boolean isValid = true; if (txtEventTitle.Text.Equals("")) { isValid = false; } if (txtEventDescription.Text.Equals("")) { isValid = false; } if (txtLocation.Text.Equals("")) { isValid = false; } if (txtEventDate.Text.Equals("")) { isValid = false; } if (txtStartHour.Text.Equals("")) { isValid = false; } if (txtStartMinute.Text.Equals("")) { isValid = false; } if (txtEndHour.Text.Equals("")) { isValid = false; } if (txtEndMinute.Text.Equals("")) { isValid = false; } if (isValid.Equals(false)) { throw (new Exception("All fields are required for this form. Please try again.")); } } public void AddEvent() { cEventsDAO objEventDAO = new cEventsDAO(); cEvent objEvent = new cEvent(); int EventId = -1; objEvent.EventTitle = txtEventTitle.Text; objEvent.EventDescription = txtEventDescription.Text; objEvent.EventLocation = txtLocation.Text; objEvent.IsActive = Convert.ToBoolean(ddActive.SelectedValue); objEvent.StartDateTime = Convert.ToDateTime(txtEventDate.Text + " " + txtStartHour.Text + ":" + txtStartMinute.Text + " " + ddStartAMPM.SelectedValue); objEvent.EndDateTime = Convert.ToDateTime(txtEventDate.Text + " " + txtEndHour.Text + ":" + txtEndMinute.Text + " " + ddEndAMPM.SelectedValue); EventId = Convert.ToInt32(objEventDAO.AddEvent(objEvent)); } public void DisplaySuccessMessage() { Literal lit = new Literal(); lit.Text = "The event was successfully added to the calendar. To add another event, complete the form below."; lblNotify.Controls.Add(lit); lblNotify.CssClass = "success"; lblNotify.Visible = true; txtEventTitle.Text = ""; txtEventDescription.Text = ""; txtLocation.Text = ""; txtEventDate.Text = ""; txtStartHour.Text = "12"; txtStartMinute.Text = "00"; ddStartAMPM.SelectedIndex.Equals(0); txtEndHour.Text = "12"; txtEndMinute.Text = "00"; ddEndAMPM.SelectedIndex.Equals(1); ddActive.SelectedIndex.Equals(0); } public void DisplayErrorMessage(Exception exError) { Literal lit = new Literal(); lit.Text = exError.Message; lblNotify.Controls.Add(lit); lblNotify.CssClass = "error"; lblNotify.Visible = true; } }