PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/PigeonCms.Core/Modules/PigeonCms.Categories/CategoriesControl.cs

http://pigeoncms.googlecode.com/
C# | 162 lines | 142 code | 20 blank | 0 comment | 7 complexity | 4e71b696bc497794dfd380a9f15746e5 MD5 | raw file
  1using System;
  2using System.Data;
  3using System.Configuration;
  4using System.Web;
  5using System.Web.Security;
  6using System.Web.UI;
  7using System.Web.UI.WebControls;
  8using System.Web.UI.WebControls.WebParts;
  9using System.Web.UI.HtmlControls;
 10using System.Diagnostics;
 11using System.ComponentModel;
 12using System.IO;
 13using System.Collections.Generic;
 14using System.Threading;
 15using PigeonCms;
 16using System.Web.Routing;
 17
 18
 19namespace PigeonCms
 20{
 21    public class CategoriesControl: PigeonCms.BaseModuleControl
 22    {
 23        private PigeonCms.Menu menuTarget = null;
 24
 25
 26        #region public fields
 27
 28        private int sectionId = 0;
 29        public int SectionId
 30        {
 31            get
 32            {
 33                return GetIntParam("SectionId", sectionId);
 34            }
 35            set { sectionId = value; }
 36        }
 37
 38        private int itemsListTarget = 0;
 39        public int ItemsListTarget
 40        {
 41            get { return GetIntParam("ItemsListTarget", itemsListTarget); }
 42            set { itemsListTarget = value; }
 43        }
 44
 45        private bool showImages = false;
 46        public bool ShowImages
 47        {
 48            get { return GetBoolParam("ShowImages", showImages); }
 49            set { showImages = value; }
 50        }
 51
 52        private string previewSize = "s";
 53        public string PreviewSize
 54        {
 55            get { return GetStringParam("PreviewSize", previewSize); }
 56            set { previewSize = value; }
 57        }
 58
 59        private int customWidth = 0;
 60        public int CustomWidth
 61        {
 62            get { return GetIntParam("CustomWidth", customWidth); }
 63            set { customWidth = value; }
 64        }
 65
 66        private int customHeight = 0;
 67        public int CustomHeight
 68        {
 69            get { return GetIntParam("CustomHeight", customHeight); }
 70            set { customHeight = value; }
 71        }
 72
 73        bool showDescription = false;
 74        public bool ShowDescription
 75        {
 76            get { return GetBoolParam("ShowDescription", showDescription); }
 77            set { showDescription = value; }
 78        }
 79
 80        private int shortDescLen = 0;
 81        public int ShortDescLen
 82        {
 83            get { return GetIntParam("ShortDescLen", shortDescLen); }
 84            set { shortDescLen = value; }
 85        }
 86
 87        private string headerText = "";
 88        public string HeaderText
 89        {
 90            get { return GetStringParam("HeaderText", headerText); }
 91            set { headerText = value; }
 92        }
 93
 94        private string footerText = "";
 95        public string FooterText
 96        {
 97            get { return GetStringParam("FooterText", footerText); }
 98            set { footerText = value; }
 99        }
100
101        public List<Category> CategoriesList
102        {
103            get
104            {
105                var res = new List<Category>();
106                var filter = new CategoriesFilter();
107                filter.Enabled = Utility.TristateBool.True;
108                filter.SectionId = this.SectionId;
109                res = new CategoriesManager().GetByFilter(filter, "");
110                foreach (var item in res)
111                {
112                    if (!this.ShowImages)
113                        item.Images.Clear();
114                    if (!this.ShowDescription)
115                        item.DescriptionTranslations.Clear();
116                }
117                return res;
118            }
119        }
120
121        #endregion
122
123        protected string GetLinkAddress(Category item)
124        {
125            string res = "javascript:void(0);";
126
127            if (this.ItemsListTarget > 0)
128            {
129                if (menuTarget == null)
130                {
131                    menuTarget = new MenuManager().GetByKey(this.ItemsListTarget);
132                }
133
134                try
135                {
136                    if (menuTarget.RoutePattern.Contains("categoryname"))
137                    {
138                        string name = item.Alias;
139                        if (string.IsNullOrEmpty(name))
140                            item.TitleTranslations.TryGetValue(Config.CultureDefault, out name);
141                        res = Utility.GetRoutedUrl(
142                        menuTarget, new RouteValueDictionary { { "categoryname", name } }, "", true);
143                    }
144                    else
145                    {
146                        res = Utility.GetRoutedUrl(
147                        menuTarget, new RouteValueDictionary { { "categoryid", item.Id } }, "", true);
148                    }
149                }
150                catch (Exception ex)
151                {
152                    Tracer.Log("GetLinkAddress(): " + ex.ToString(), TracerItemType.Error);
153                }
154            }
155            return res;
156        }
157
158        protected void Page_Load(object sender, EventArgs e)
159        {
160        }
161    }
162}