Click here to Skip to main content
15,891,896 members
Articles / Web Development / IIS

Rapid Web Application Development

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
27 Sep 200510 min read 204K   4.2K   86  
An article about the Multiformity Open Source project.
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;

namespace rasp.SQL.DBInfo
{
	/// <summary>
	/// Summary description for TabInfoCollection.
	/// </summary>
	public class TabInfoCollection :IEnumerator, IEnumerable {
		private ArrayList _Data = new ArrayList();
		private string _Table = "";
		private int _Position = -1;

		public int Count {
			get { return _Data.Count; }
		}
		public TabInfoCollection(TabInfoCollection tabs) {
			foreach(TabInfo ti in tabs) {
				this._Data.Add(ti);
			}
		}
		public TabInfoCollection(TableInfo tableinfo) {
			//TODO: Fix this up, it seems like really screwey logic, I mean, if there is a DBNull for the _Tabs_IDs or if it is -1 then we need a new TabInfo with the main tab
			// SELECT DISTINCT _TABS_ID fROM _FIELDS WHERE (_TABLES_ID = 65)
      string select = "select distinct _Tabs_ID from _Fields where _Tables_ID = " + tableinfo.ID;
			DataSet ds = SQLUtilities.SelectData(select);
			string ids = "";
			if(ds.Tables[0].Rows.Count == 0) {
				this._Data.Add(new TabInfo(1));
			} else {
				foreach(DataRow dr in ds.Tables[0].Rows) {
					try {
						string id = ((int)dr["_Tabs_ID"]).ToString();
						ids += id + ",";
					} catch {}
				}
				try {
					ids = ids.Substring(0, ids.Length-1);
				} catch {
					ids = "-1";
				}
				if (!ids.Equals("-1")) {
					// SELECT * FROM _TABS WHERE ID IN (1, 2, 3) ORDER BY _Tabs.DisplayOrder
					select = "select * from _Tabs where id in (" + ids + ") order by _Tabs.DisplayOrder";
					ds = SQLUtilities.SelectData(select);
			
					foreach(DataRow dr in ds.Tables[0].Rows) {
						this._Data.Add(new TabInfo(dr));
					}
				} else {
					this._Data.Add(new TabInfo(1));
				}
			}
			
		

		}


		
		#region Enumerator methods

		/// <summary>
		/// Implentation of the GetEnumerator method for the IEnumerable interface.
		/// </summary>
		/// <returns></returns>
		public IEnumerator GetEnumerator() {
			return  (TabInfoCollection)MemberwiseClone();
		}

		/// <summary>
		/// Returns the "current" FieldInfo object.
		/// </summary>
		public object Current {
			get {
				try {
					TabInfo ti = (TabInfo)_Data[_Position];
					return ti;
				} catch {
					throw new Exception("There is not a tab at the position at " + _Position);
				}
			}
		}
		/// <summary>
		/// Resets the collections enumerator.
		/// </summary>
		public void Reset() {
			_Position = -1;
		}
		/// <summary>
		/// Moves to the next position in the collection.
		/// </summary>
		/// <returns>A boolean valud indicating if we have moved past the bounds of the collection.</returns>
		public bool MoveNext() {
			bool ret = false;
			if(_Position + 1 < _Data.Count) {
				ret = true;
				++_Position;
			}
			return ret;
		}

		#endregion

	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions