PreviousNext.cs :  » Bloggers » SubText » Subtext » Web » UI » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » Subtext » Web » UI » Controls » PreviousNext.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Subtext.Extensibility;
using Subtext.Framework.Components;
using Subtext.Framework.Data;

namespace Subtext.Web.UI.Controls{
    /// <summary>
    /// Summary description for PreviousNext.
    /// </summary>
    public class PreviousNext : BaseControl
    {
        protected Control LeftPipe;
        protected HyperLink MainLink;
        protected HyperLink NextLink;
        protected HyperLink PrevLink;
        protected Control RightPipe;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //Get the entry
            Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext);

            //if found
            if(entry != null)
            {
                //Sent entry properties
                MainLink.NavigateUrl = Url.BlogUrl();
                var entries = Cacher.GetPreviousNextEntry(entry.Id, PostType.BlogPost, SubtextContext);

                //Remember, the NEXT entry is the MORE RECENT entry.
                switch(entries.Count)
                {
                    case 0:
                    {
                        //you have no entries. You should blog more
                        if(PrevLink != null)
                        {
                            PrevLink.Visible = false;
                            
                        }
                        if(NextLink != null)
                        {
                            NextLink.Visible = false;
                        }
                        break;
                    }
                    case 1:
                    {
                        //since there is only one record, you are at an end
                        //Check EntryId to see if it is greater or less than
                        //the current ID
                        if (entries.First().DateSyndicated > entry.DateSyndicated)
                        {
                            //this is the oldest blog
                            if(PrevLink != null)
                            {
                                PrevLink.Visible = false;
                            }
                            if(LeftPipe != null)
                            {
                                LeftPipe.Visible = false;
                            }
                            SetNav(NextLink, entries.First());
                        }
                        else
                        {
                            //this is the latest blog
                            if(NextLink != null)
                            {
                                NextLink.Visible = false;
                            }
                            if(RightPipe != null)
                            {
                                RightPipe.Visible = false;
                            }
                            SetNav(PrevLink, entries.First());
                        }
                        break;
                    }
                    case 2:
                    {
                        //two records found. The first record will be NEXT
                        //the second record will be PREVIOUS
                        //This is because the query is sorted by EntryId
                        SetNav(NextLink, entries.First());
                        SetNav(PrevLink, entries.ElementAt(1));
                        break;
                    }
                }
            }
            else
            {
                //No post? Deleted? Help :)
                Controls.Clear();
                Controls.Add(
                    new LiteralControl("<p><strong>The entry could not be found or has been removed</strong></p>"));
            }
        }


        private void SetNav(HyperLink navLink, EntrySummary entry)
        {
            if(navLink == null)
            {
                return;
            }
            string format = navLink.Attributes["Format"];
            if(String.IsNullOrEmpty(format))
            {
                format = "{0}";
            }

            navLink.Attributes.Remove("Format");

            string entryTitle = HttpUtility.HtmlDecode(entry.Title);
            string sizeLimitText = navLink.Attributes["TextSizeLimit"];
            if(!String.IsNullOrEmpty(sizeLimitText))
            {
                int sizeLimit;
                if(int.TryParse(sizeLimitText, out sizeLimit))
                {
                    if(sizeLimit > 0 && sizeLimit < entryTitle.Length)
                    {
                        entryTitle = entryTitle.Substring(0, sizeLimit) + "...";
                    }
                }
            }
            navLink.Attributes.Remove("TextSizeLimit");

            navLink.Text = HttpUtility.HtmlEncode(string.Format(format, entryTitle));
            navLink.NavigateUrl = Url.EntryUrl(entry);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.