using framework_business; using framework_library; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; public partial class controls_module_calendarStatus : System.Web.UI.UserControl { public int CalendarId { get { if (ViewState["calendarId"] == null) return 0; else return (int)ViewState["calendarId"]; } set { ViewState["calendarId"] = value; } } #region methods /// /// Reload Control /// /// public void ReloadControl(int calId) { this.CalendarId = calId; BindGrid(); } /// /// Bind Statuses Grid /// private void BindGrid() { try { DataTable dt = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oCalendarStatus), "calendarId", this.CalendarId.ToString()); rtpEventStatus.DataSource = dt; rtpEventStatus.DataBind(); } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("Error.aspx", false); } } private void TogglePanels(string panelName) { switch (panelName) { case "pnlForm": pnlForm.Visible = true; pnlGrid.Visible = false; lblHeading.Visible = true; break; case "pnlGrid": pnlForm.Visible = false; pnlGrid.Visible = true; lblHeading.Visible = false; break; } //clear result pnlResult.Visible = false; pnlGridResult.Visible = false; } private void PopulateFormValues(oCalendarStatus _stat) { try { txtStatus.Text = _stat.status; chkActive.Checked = _stat.isActive; ddIcon.ClearSelection(); if (_stat.icon != String.Empty) { ddIcon.SelectedValue = _stat.icon; iconPreview.Attributes.Remove("class"); iconPreview.Attributes.Add("class", ddIcon.SelectedValue + " big-icon"); } } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Save form values /// /// private void SaveFormValues(ref oCalendarStatus _stat) { try { _stat.status = txtStatus.Text; _stat.isActive = chkActive.Checked; _stat.icon = ddIcon.SelectedValue; _stat.calendarId = this.CalendarId; } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } #endregion #region events /// /// /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { BindGrid(); } ScriptManager.RegisterStartupScript(Page, Page.GetType(), "setLoadOptions", "if(typeof(setLoadOptions) == \"function\"){window.onload = setLoadOptions()};", true); } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// /// /// /// protected void btnNewType_Click(object sender, EventArgs e) { try { utils.disposeSession("EventStat"); oCalendarStatus eventStatus = new oCalendarStatus(); PopulateFormValues(eventStatus); TogglePanels("pnlForm"); } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { try { oCalendarStatus eventType = new oCalendarStatus(); ArrayList list = new ArrayList(); if (sender.GetType() == typeof(LinkButton)) { int recId = int.Parse(((LinkButton)sender).CommandArgument); if (recId > 0) { //get cat list = xData.GetTypedByCriteriaSpecific("recId", typeof(oCalendarStatus), "recId", recId.ToString()); //enumerate list foreach (oCalendarStatus t in list) { //assign object eventType = t; //populate page form PopulateFormValues(eventType); Session["EventStat"] = eventType; break; } TogglePanels("pnlForm"); } } } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// /// /// /// protected void lnkRemove_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int recId = int.Parse(((LinkButton)sender).CommandArgument); //first check if there are any events linked to this type ArrayList events = xData.GetTypedByCriteriaSpecific("recId", typeof(oCalendarEvent), "calendarEventTypeId", recId.ToString()); if (events != null && events.Count > 0) { pnlGridResult.Visible = true; lblGridResult.Text = "the selected Event Type has Events linked to it and cannot be deleted."; } //Delete event type else if (xData.DeleteTyped("recId", recId.ToString(), typeof(oCalendarStatus))) { //rebind pages grid BindGrid(); pnlResult.Visible = true; //display successful result lblResult.Text = "the selected Event Type was deleted successfully."; } } } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// /// /// /// protected void btnSave_Click(object sender, EventArgs e) { try { oCalendarStatus eventStat = new oCalendarStatus(); if (utils.verifySession("EventStat"))//update mode { eventStat = (oCalendarStatus)Session["EventStat"]; //save form values SaveFormValues(ref eventStat); if (xData.UpdateTyped("recId", eventStat.recId.ToString(), typeof(oCalendarStatus), eventStat)) { Session["EventStat"] = eventStat; BindGrid(); pnlResult.Visible = true; lblResult.Text = "your changes were updated successfully."; } } else { if (!xData.VerifyExists("recId", typeof(oCalendarStatus), "status,calendarId", txtStatus.Text + "," + this.CalendarId)) { //save form values SaveFormValues(ref eventStat); eventStat.recId = xData.SaveTyped("recId", typeof(oCalendarStatus), eventStat); if (eventStat.recId > 0) { Session["EventStat"] = eventStat; BindGrid(); pnlResult.Visible = true; lblResult.Text = "your Event Status was created successfully."; } } else { pnlResult.Visible = true; lblResult.Text = "An Event Status with this name already exists on the system"; } } } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { utils.disposeSession("EventStat"); BindGrid(); TogglePanels("pnlGrid"); } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Item Data Bound event /// /// /// protected void rtpEventStatus_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lblIcon = (Label)e.Item.FindControl("lblIcon"); if (lblIcon != null) { HiddenField hfIcon = (HiddenField)e.Item.FindControl("hfIcon"); if (hfIcon != null && hfIcon.Value != String.Empty) { lblIcon.Text = ""; } } } } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Selected Index Changed /// /// /// protected void ddIcon_SelectedIndexChanged(object sender, EventArgs e) { try { iconPreview.Attributes.Remove("class"); iconPreview.Attributes.Add("class", ddIcon.SelectedValue + " big-icon"); } catch (Exception ex) { exception.HandleException("CalendarStatus:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } #endregion }