using framework_business; using framework_library; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class controls_admin_content : System.Web.UI.UserControl { #region methods /// /// Method to Bind Content Data /// private void BindContentData() { try { ArrayList contentList = xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "", "", "sequence"); rptContentPages.DataSource = contentList; rptContentPages.DataBind(); } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Templates /// private void BindTemplates() { ArrayList templates = new ArrayList(); try { templates = xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", "2", "templateName"); ddTemplates.DataSource = templates; ddTemplates.DataTextField = "templateName"; ddTemplates.DataValueField = "recId"; ddTemplates.DataBind(); ddTemplates.Items.Insert(0, new ListItem("None Selected", "0")); } catch (Exception ex) { exception.HandleException("Admin:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("Error.aspx", false); } } /// /// Method to Bind the slide Order Drop down /// private void BindSequence() { try { for (int i = 0; i < 20; i++) { //append sequence item ddSequence.Items.Add(new ListItem(i.ToString(), i.ToString())); } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulatePageFormValues(ref oContent _Content) { try { txtTitle.Value = _Content.title; chkActive.Checked = _Content.isActive; if (_Content.sequence > 0) ddSequence.SelectedValue = _Content.sequence.ToString(); edContent.Content = _Content.contentHTML; } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// private void SavePageFormValues(ref oContent _Content) { try { _Content.title = txtTitle.Value; _Content.isActive = chkActive.Checked; _Content.sequence = int.Parse(ddSequence.SelectedValue); _Content.contentHTML = edContent.Content; } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Method to Toggle Panels /// /// private void TogglePanels(string panelName) { switch (panelName) { case "pnlContentPage": pnlContentPage.Visible = true; pnlContentList.Visible = false; break; case "pnlContentList": pnlContentPage.Visible = false; pnlContentList.Visible = true; break; } //clear result pnlResult.Visible = false; } #endregion #region events /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { BindContentData(); BindSequence(); BindTemplates(); } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Content Click /// /// /// protected void btnNewContent_Click(object sender, EventArgs e) { try { //show Content Specific TogglePanels("pnlContentPage"); Session["ContentId"] = 0; utils.disposeSession("Content"); oContent Content = new oContent(); PopulatePageFormValues(ref Content); } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit the Content page /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { oContent _Content = new oContent(); ArrayList catList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); if (recId > 0) { Session["ContentId"] = recId; //get cat catList = xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "recId", recId.ToString()); //enumerate list foreach (oContent cat in catList) { //assign object _Content = cat; //populate page form PopulatePageFormValues(ref _Content); Session["Content"] = _Content; break; } //show Content Form TogglePanels("pnlContentPage"); } } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove the Content /// /// /// protected void lnkRemove_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); //Delete cat if (xData.DeleteTyped("recId", recId.ToString(), typeof(oContent))) { //rebind pages grid BindContentData(); pnlResult.Visible = true; //display successful result lblResult.Text = "the selected Content was deleted successfully."; } } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { Session["ContentId"] = 0; utils.disposeSession("Content"); BindContentData(); //show cat list TogglePanels("pnlContentList"); } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Click /// /// /// protected void btnSave_Click(object sender, EventArgs e) { oContent Content = new oContent(); try { if (utils.verifySession("Content"))//update mode { Content = (oContent)Session["Content"]; //save form values SavePageFormValues(ref Content); if (xData.UpdateTyped("recId", Content.recId.ToString(), typeof(oContent), Content)) { Session["ContentId"] = Content.recId; Session["Content"] = Content; BindContentData(); pnlResult.Visible = true; lblResult.Text = "your changes were updated successfully."; } } else { if (!xData.VerifyExists("recId", typeof(oContent), "title", txtTitle.Value)) { Content.isActive = true; //save form values SavePageFormValues(ref Content); Content.recId = xData.SaveTyped("recId", typeof(oContent), Content); if (Content.recId > 0) { Session["ContentId"] = Content.recId; Session["Content"] = Content; BindContentData(); pnlResult.Visible = true; lblResult.Text = "your Content Page was created successfully."; } } else { pnlResult.Visible = true; lblResult.Text = "A content page with this title already exists on the system"; } } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Selected Index Changed /// /// /// protected void ddTemplates_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddTemplates.SelectedValue != "0") { ArrayList templateList = new ArrayList(); templateList = xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "recId", ddTemplates.SelectedValue); foreach (oTemplate template in templateList) { //apply template to editor edContent.Content = template.templateContent; } } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("Error.aspx", false); } } #endregion }