Click here to Skip to main content
15,895,746 members
Articles / Web Development / HTML

Gallery Server Pro - An ASP.NET Gallery for Sharing Photos, Video, Audio and Other Media

Rate me:
Please Sign up or sign in to vote.
4.86/5 (131 votes)
18 Oct 2013GPL331 min read 829.2K   539  
Gallery Server Pro is a complete, stable ASP.NET gallery for sharing photos, video, audio and other media. This article presents the overall architecture and major features.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using GalleryServerPro.WebControls.Tools;


namespace GalleryServerPro.WebControls
{

	/// <summary>
	/// Collection of individual DataBindingItems. Implemented explicitly as
	/// a CollectionBase class rather than using List#wwDataBindingItems#
	/// so that Add can be overridden
	/// </summary>
	public class wwDataBindingItemCollection : CollectionBase
	{
		/// <summary>
		/// Internal reference to the wwDataBinder object
		/// that is passed to the individual items if available
		/// </summary>
		wwDataBinder _ParentDataBinder = null;

		/// <summary>
		/// Preferred Constructor - Add a reference to the wwDataBinder object here
		/// so a reference can be passed to the children.
		/// </summary>
		/// <param name="Parent"></param>
		public wwDataBindingItemCollection(wwDataBinder Parent)
		{
			this._ParentDataBinder = Parent;
		}

		/// <summary>
		/// Not the preferred constructor - If possible pass a reference to the
		/// Binder object in the overloaded version.
		/// </summary>
		public wwDataBindingItemCollection()
		{
		}

		/// <summary>
		/// Public indexer for the Items
		/// </summary>
		/// <param name="index"></param>
		/// <returns></returns>
		public wwDataBindingItem this[int index]
		{
			get
			{
				return this.InnerList[index] as wwDataBindingItem;
			}
			set
			{
				this.InnerList[index] = value;
			}
		}


		/// <summary>
		/// Add a wwDataBindingItem to the collection
		/// </summary>
		/// <param name="Item"></param>
		public void Add(wwDataBindingItem Item)
		{
			if (_ParentDataBinder != null)
			{
				Item.Page = _ParentDataBinder.Page;
				Item.Binder = _ParentDataBinder;

				// *** VS Designer adds new items as soon as their accessed
				// *** but items may not be valid so we have to clean up
				if (this._ParentDataBinder.DesignMode)
				{
					// *** Remove any blank items
					UpdateListInDesignMode();
				}
			}

			this.InnerList.Add(Item);
		}


		/// <summary>
		/// Add a wwDataBindingItem to the collection
		/// </summary>
		/// <param name="index"></param>
		/// <param name="Item"></param>
		public void AddAt(int index, wwDataBindingItem Item)
		{
			if (_ParentDataBinder != null)
			{
				Item.Page = _ParentDataBinder.Page;
				Item.Binder = _ParentDataBinder;

				// *** VS Designer adds new items as soon as their accessed
				// *** but items may not be valid so we have to clean up
				if (this._ParentDataBinder.DesignMode)
				{
					UpdateListInDesignMode();
				}
			}

			InnerList.Insert(index, Item);
		}

		/// <summary>
		/// We have to delete 'empty' items because the designer requires items to be 
		/// added to the collection just for editing. This way we may have one 'extra'
		/// item, but not a whole long list of items.
		/// </summary>
		private void UpdateListInDesignMode()
		{
			if (this._ParentDataBinder == null)
				return;

			bool Update = false;

			// *** Remove empty items - so the designer doesn't create excessive empties
			for (int x = 0; x < this.Count; x++)
			{
				if (string.IsNullOrEmpty(this[x].BindingSource) && string.IsNullOrEmpty(this[x].BindingSourceMember))
				{
					this.RemoveAt(x);
					Update = true;
				}
			}

			if (Update)
				this._ParentDataBinder.NotifyDesigner();
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Tech Info Systems
United States United States
I have nearly 20 years of industry experience in software development, architecture, and Microsoft Office products. My company Tech Info Systems provides custom software development services for corporations, governments, and other organizations. Tech Info Systems is a registered member of the Microsoft Partner Program and I am a Microsoft Certified Professional Developer (MCPD).

I am the creator and lead developer of Gallery Server Pro, a free, open source ASP.NET gallery for sharing photos, video, audio, documents, and other files over the web. It has been developed over several years and has involved thousands of hours. The end result is a robust, configurable, and professional grade gallery that can be integrated into your web site, whether you are a large corporation, small business, professional photographer, or a local church.

Comments and Discussions