PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/PigeonCms.Core/Modules/PigeonCms.Photogallery/PhotogalleryControl.cs

http://pigeoncms.googlecode.com/
C# | 249 lines | 211 code | 33 blank | 5 comment | 10 complexity | 2c681cbe6f992af64d35d5a61ac51f18 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;
 16
 17
 18namespace PigeonCms
 19{
 20    public class PhotogalleryControl: PigeonCms.BaseModuleControl
 21    {
 22        #region private fields
 23        private PhotogalleryControl.SourceTypeEnum sourceType = SourceTypeEnum.FolderSource;
 24        private bool showChildList = false;
 25        private string basePath = "";
 26        private string folderName = "";
 27        private int sectionId = 0;
 28        private int categoryId = 0;
 29        private int itemId = 0;
 30        private string layoutCssFile = "";
 31        private string headerText = "";
 32        private string footerText = "";
 33        private string errorText = "";
 34        List<FileMetaInfo> imagesList = new List<FileMetaInfo>();
 35        #endregion
 36
 37
 38        public struct LinksList
 39        {
 40            public int Id;
 41            public string Title;
 42
 43            public LinksList(int id, string title)
 44            {
 45                this.Id = id;
 46                this.Title = title;
 47            }
 48        }
 49
 50        public enum SourceTypeEnum
 51        {
 52            FolderSource = 0,
 53            SectionSource = 1,
 54            CategorySource = 2, 
 55            ItemSource = 3
 56        }
 57
 58        #region public fields
 59
 60        public PhotogalleryControl.SourceTypeEnum SourceType
 61        {
 62            get 
 63            {
 64                int res = 0;
 65                res = GetIntParam("SourceType", res);
 66                return (SourceTypeEnum)res;
 67            }
 68            set { sourceType = value; }
 69        }
 70
 71        public bool StaticFilesTracking
 72        {
 73            get
 74            {
 75                int staticFilesTracking = (int)Utility.TristateBool.NotSet;
 76                bool res = false;
 77                staticFilesTracking = GetIntParam("StaticFilesTracking", staticFilesTracking);
 78                if ((Utility.TristateBool)staticFilesTracking == Utility.TristateBool.True)
 79                    res = true;
 80                else if ((Utility.TristateBool)staticFilesTracking == Utility.TristateBool.NotSet)
 81                {
 82                    bool.TryParse(AppSettingsManager.GetValue("StaticFilesTracking"), out res);
 83                }
 84                return res;
 85            }
 86        }
 87
 88        public bool ShowChildList
 89        {
 90            get { return GetBoolParam("ShowChildList", showChildList); }
 91            set { showChildList = value; }
 92        }
 93
 94        /// <summary>
 95        /// folder taht contains images
 96        /// </summary>
 97        public string BasePath
 98        {
 99            get { return GetStringParam("BasePath", basePath); }
100            set { basePath = value; }
101        }
102
103        public string FolderName
104        {
105            get { return GetStringParam("FolderName", folderName); }
106            set { folderName = value; }
107        }
108
109        public int SectionId
110        {
111            get { return GetIntParam("SectionId", sectionId); }
112            set { sectionId = value; }
113        }
114
115        public int CategoryId
116        {
117            get { return GetIntParam("CategoryId", categoryId); }
118            set { categoryId = value; }
119        }
120
121        public int ItemId
122        {
123            get { return GetIntParam("ItemId", itemId); }
124            set { itemId = value; }
125        }
126
127        public string HeaderText
128        {
129            get { return GetStringParam("HeaderText", headerText); }
130            set { headerText = value; }
131        }
132
133        public string FooterText
134        {
135            get { return GetStringParam("FooterText", footerText); }
136            set { footerText = value; }
137        }
138
139        public string ErrorText
140        {
141            get { return GetStringParam("ErrorText", errorText); }
142            set { errorText = value; }
143        }
144
145        public List<FileMetaInfo> ImagesList
146        {
147            get
148            {
149                switch (this.SourceType)
150                {
151                    case SourceTypeEnum.FolderSource:
152                        imagesList = new Photogallery(this.BasePath, this.FolderName).GetAll();
153                        break;
154
155                    case SourceTypeEnum.SectionSource:
156                        if (this.ShowChildList)
157                            imagesList = new Photogallery("", "categories/" + this.CategoryId).GetAll();
158                        else
159                            imagesList = new Photogallery("", "sections/"+ this.SectionId).GetAll();
160                        break;
161
162                    case SourceTypeEnum.CategorySource:
163                        if (this.ShowChildList)
164                            imagesList = new Photogallery("", "items/" + this.ItemId).GetAll();
165                        else
166                            imagesList = new Photogallery("", "categories/" + this.CategoryId).GetAll();
167                        break;
168
169                    case SourceTypeEnum.ItemSource:
170                        imagesList = new Photogallery("", "items/" + this.ItemId).GetAll();
171                        break;
172                    default:
173                        break;
174                }
175                
176                return imagesList;
177            }
178        }
179
180        public List<LinksList> ChildList
181        {
182            get
183            {
184                List<LinksList> res = new List<LinksList>();
185                if (this.ShowChildList)
186                {
187                    switch (this.SourceType)
188                    {
189                        case SourceTypeEnum.FolderSource:
190                            break;
191                        case SourceTypeEnum.SectionSource:
192                            res = getCategoriesList();
193                            break;
194                        case SourceTypeEnum.CategorySource:
195                            res = getItemsList();
196                            break;
197                        case SourceTypeEnum.ItemSource:
198                            break;
199                        default:
200                            break;
201                    }
202                }
203                return res;
204            }
205        }
206
207        
208        #endregion
209
210        protected void Page_Load(object sender, EventArgs e)
211        { }
212
213        private List<LinksList> getCategoriesList()
214        {
215            List<LinksList> res = new List<LinksList>();
216            List<Category>list = new List<Category>();
217            CategoriesFilter filter = new CategoriesFilter();
218
219            filter.Enabled = Utility.TristateBool.True;
220            filter.SectionId = this.SectionId;
221
222            list = new CategoriesManager().GetByFilter(filter, "");
223            foreach (Category item in list)
224            {
225                res.Add(new LinksList(item.Id, item.Title));
226                //res.Add(item.Title);
227            }
228            return res;
229        }
230
231        private List<LinksList> getItemsList()
232        {
233            List<LinksList> res = new List<LinksList>();
234            List<Item> list = new List<Item>();
235            ItemsFilter filter = new ItemsFilter();
236
237            filter.Enabled = Utility.TristateBool.True;
238            filter.CategoryId = this.CategoryId;
239
240            list = new ItemsManager<Item,ItemsFilter>().GetByFilter(filter, "");
241            foreach (Item item in list)
242            {
243                res.Add(new LinksList(item.Id, item.Title));
244                //res.Add(item.Title);
245            }
246            return res;
247        }
248    }
249}