/// <summary>
 /// Handles the Click event of the cmdDeletePage control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
 protected void cmdDeletePage_Click(object sender, EventArgs e)
 {
     if ((lstPages.SelectedItem.Value != null) && (lstPages.SelectedItem.Value != "-1"))
     {
         EnhancedHtmlDB tdb1 = new EnhancedHtmlDB();
         tdb1.DeletePage(int.Parse(this.lstPages.SelectedItem.Value));
         if (lstPages.Items.Count > 0)
         {
             lstPages.SelectedIndex = 0;
             cmdEditPage.Enabled = true;
             cmdDeletePage.Enabled = true;
         }
         else
         {
             lstPages.SelectedIndex = -1;
             cmdEditPage.Enabled = false;
             cmdDeletePage.Enabled = false;
         }
         Response.Redirect(Request.Url.ToString(), true);
     }
 }
        /// <summary>
        /// Handles the Click event of the cmdEditPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void cmdEditPage_Click(object sender, EventArgs e)
        {
            pnlSelectPage.Visible = false;
            pnlEditPage.Visible = true;
            txtPageName.Text = string.Empty;
            txtViewOrder.Text = "100";

            EnhancedHtmlDB ehdb = new EnhancedHtmlDB();
            SqlDataReader dr =
                ehdb.GetSinglePage(int.Parse(lstPages.SelectedItem.Value), Appleseed.Framework.WorkFlowVersion.Staging);

            try
            {
                if (dr.Read())
                {
                    txtPageName.Text = ((string) dr["Title"]);
                    txtViewOrder.Text = dr["ViewOrder"].ToString();
                    foreach (ListItem li in listLanguages.Items)
                    {
                        li.Selected = li.Value.Equals(dr["CultureCode"].ToString());
                    }
                    DesktopText.Text = Server.HtmlDecode(((string) dr["DesktopHtml"]));
                    CreatedBy.Text = (string) dr["CreatedByUser"];
                    CreatedDate.Text = ((DateTime) dr["CreatedDate"]).ToShortDateString();
                }
            }
            finally
            {
                dr.Close();
            }
            if (DesktopText.Text.StartsWith(tokenModule))
            {
                kindOfContent.SelectedIndex = 1;
                int module = int.Parse(DesktopText.Text.Substring(tokenModule.Length));
                foreach (ListItem li in listModules.Items)
                    if (int.Parse(li.Value) == module)
                        li.Selected = true;
            }
            else if (DesktopText.Text.StartsWith(tokenPortalModule))
            {
                kindOfContent.SelectedIndex = 2;
                int module = int.Parse(DesktopText.Text.Substring(tokenPortalModule.Length));
                foreach (ListItem li in listAllModules.Items)
                    if (int.Parse(li.Value) == module)
                        li.Selected = true;
            }
            else
                kindOfContent.SelectedIndex = 0;
            kindOfContents_Click(sender, e);
        }
        /// <summary>
        /// Handles the Click event of the cmdPageUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void cmdPageUpdate_Click(object sender, EventArgs e)
        {
            string titlePage = txtPageName.Text;
            if (((titlePage == null) || (titlePage.Length < 1)) || (titlePage.Trim().Length < 1))
            {
                titlePage = "Page";
            }
            string orderView = txtViewOrder.Text;
            int order = 0;
            try
            {
                order = int.Parse(orderView);
            }
            catch
            {
            }
            if (order < 1)
            {
                orderView = "100";
                txtViewOrder.Text = orderView;
                order = 100;
            }
            string text = string.Empty;
            int i;

            switch (kindOfContent.SelectedValue)
            {
                case "Editor":
                    text = Server.HtmlEncode(DesktopText.Text);
                    if (text.StartsWith(tokenModule) || text.StartsWith(tokenPortalModule))
                        text = string.Empty;
                    break;
                case "Module":
                    i = int.Parse(listModules.SelectedValue);
                    if (i == 0 || i == this.ModuleID) return; // Cannot select this module
                    text = tokenModule + listModules.SelectedValue;
                    break;
                case "Portal":
                    i = int.Parse(listAllModules.SelectedValue);
                    if (i == 0 || i == this.ModuleID) return; // Cannot select this module
                    text = tokenPortalModule + listAllModules.SelectedValue;
                    break;
            }

            string user = PortalSettings.CurrentUser.Identity.UserName;
            EnhancedHtmlDB tdb1 = new EnhancedHtmlDB();
            if (lstPages.SelectedIndex >= 0)
            {
                int itemID = int.Parse(lstPages.SelectedItem.Value);
                tdb1.UpdatePage(ModuleID, itemID, user, titlePage, order, int.Parse(listLanguages.SelectedItem.Value),
                                text);
            }
            else
            {
                tdb1.AddPage(ModuleID, 0, user, titlePage, order, int.Parse(listLanguages.SelectedItem.Value), text);
            }
            pnlSelectPage.Visible = true;
            pnlEditPage.Visible = false;
            ShowList();
        }
        /// <summary>
        /// Shows the list.
        /// </summary>
        private void ShowList()
        {
            bool showAllPages = (int.Parse(lstLanguages.SelectedItem.Value) < 1);
            CultureInfo[] listaLang = LanguageSwitcher.GetLanguageList(true);
            EnhancedHtmlDB ehdb = new EnhancedHtmlDB();
            SqlDataReader dr;
            lstPages.Items.Clear();

            if (showAllPages)
            {
                dr = ehdb.GetAllPages(ModuleID, WorkFlowVersion.Staging);
            }
            else
            {
                dr =
                    ehdb.GetLocalizedPages(ModuleID, int.Parse(lstLanguages.SelectedItem.Value), WorkFlowVersion.Staging);
            }

            try
            {
                while (dr.Read())
                {
                    if (showAllPages)
                    {
                        int ccode = int.Parse(dr["CultureCode"].ToString());
                        string texto = string.Empty;

                        foreach (CultureInfo ci in listaLang)
                        {
                            if (ccode == ci.LCID) texto = ci.DisplayName;
                        }
                        if (texto.Length != 0)
                        {
                            lstPages.Items.Add(
                                new ListItem((string) dr["Title"] + " (" + texto + ")", dr["ItemID"].ToString()));
                        }
                    }
                    else
                    {
                        lstPages.Items.Add(new ListItem((string) dr["Title"], dr["ItemID"].ToString()));
                    }
                }
            }
            finally
            {
                dr.Close();
            }
            if (lstPages.Items.Count > 0)
            {
                lstPages.SelectedIndex = 0;
                cmdEditPage.Enabled = true;
                cmdDeletePage.Enabled = true;
            }
            else
            {
                cmdEditPage.Enabled = false;
                cmdDeletePage.Enabled = false;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gives the me pages.
        /// </summary>
        /// <param name="addInvariantCulture">
        /// if set to <c>true</c> [add invariant culture].
        /// </param>
        /// <returns>
        /// </returns>
        /// <remarks>
        /// </remarks>
        private DataTable GiveMePages(bool addInvariantCulture)
        {
            var selected = false;
            var selectedPage = -1;
            if (this.ehPageId != null)
            {
                selectedPage = int.Parse(this.ehPageId);
            }

            var tabla = new DataTable("LocalizedPages");

            tabla.Columns.Add(new DataColumn("ItemID", typeof(string)));
            tabla.Columns.Add(new DataColumn("Title", typeof(string)));
            tabla.Columns.Add(new DataColumn("DesktopHtml", typeof(string)));

            var ehdb = new EnhancedHtmlDB();

            using (
                var dr = ehdb.GetLocalizedPages(this.ModuleID, this.PortalSettings.PortalUILanguage.LCID, this.Version))
            {
                while (dr.Read())
                {
                    this.AddPageRow(tabla, dr["ItemID"].ToString(), (string)dr["Title"], (string)dr["DesktopHtml"]);
                    if (int.Parse(dr["ItemID"].ToString()) == selectedPage)
                    {
                        selected = true;
                    }
                }

                if (tabla.Rows.Count == 0)
                {
                    if (this.PortalSettings.PortalUILanguage.Parent.LCID != CultureInfo.InvariantCulture.LCID)
                    {
                        using (
                            var dr1 = ehdb.GetLocalizedPages(
                                this.ModuleID, this.PortalSettings.PortalUILanguage.Parent.LCID, this.Version))
                        {
                            while (dr1.Read())
                            {
                                this.AddPageRow(
                                    tabla, dr1["ItemID"].ToString(), (string)dr1["Title"], (string)dr1["DesktopHtml"]);
                                if (int.Parse(dr1["ItemID"].ToString()) == selectedPage)
                                {
                                    selected = true;
                                }
                            }
                        }
                    }
                }

                if (addInvariantCulture || tabla.Rows.Count == 0)
                {
                    using (
                        var dr2 = ehdb.GetLocalizedPages(this.ModuleID, CultureInfo.InvariantCulture.LCID, this.Version)
                        )
                    {
                        while (dr2.Read())
                        {
                            this.AddPageRow(
                                tabla, dr2["ItemID"].ToString(), (string)dr2["Title"], (string)dr2["DesktopHtml"]);
                            if (int.Parse(dr2["ItemID"].ToString()) == selectedPage)
                            {
                                selected = true;
                            }
                        }
                    }
                }
            }

            if (!selected)
            {
                this.ehPageId = null;
            }

            return tabla;
        }