Click here to Skip to main content
15,895,836 members
Articles / Mobile Apps / Windows Mobile

Resort Companion

Rate me:
Please Sign up or sign in to vote.
3.95/5 (20 votes)
2 Jun 2004CPOL7 min read 55.3K   178   18  
Presenting the Resort Companion, a data-navigation application for vacation resorts
// Resort Companion Data Manager
// Copyright (c) 2004 Wolf Logan

using System;
using System.Collections;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.Text;

namespace org.CircleCross.ResortCompanion.Data {
	/// <summary>
	/// Summary description for PlaceRecord.
	/// </summary>
	abstract public class PlaceRecord: RCDataRecord {

		protected const int FIELD_LOCATION = 4;
		protected const int FIELD_NEARBY = 5;
		protected const string ATTRACTION_RELATION = "Place_Attraction";
		protected const string FOOD_RELATION = "Place_Food";
		protected const string TRANSPORT_RELATION = "Place_Transport";
		protected const string SHOP_RELATION = "Place_Shop";
		protected const string SHOW_RELATION = "Place_Show";
		protected const string SERVICE_RELATION = "Place_Service";

		protected Point location;
		public RegionRecord Region {
			get {
				return (RegionRecord)this.Parent;
			}
		}
		protected PlaceRecord[] nearbyPlaces = null;
		public PlaceRecord[] NearbyPlaces {
			get {
				if(this.nearbyPlaces == null) {
					this.nearbyPlaces = this.selectByIDs((string)this.myRow.ItemArray[FIELD_NEARBY]);
				}
				return this.nearbyPlaces;
			}
		}
		public Point Location {
			get {
				return this.location;
			}
		}

		override protected RCDataRecord newParentRecord(DataRow row) {
			return RegionRecord.Maker(row);
		}
		override protected RCDataRecord[] newChildRecords(int count) {
			return null;
		}
		override protected RCDataRecord newChildRecord(DataRow row) {
			return null;
		}

		protected PlaceRecord(DataRow row): base(row) {
			this.parentRelation = "Region_Place";

			string[] ordinals = ((string)this.myRow.ItemArray[FIELD_LOCATION]).Split(',');
			int x = Convert.ToInt32(ordinals[0]);
			int y = Convert.ToInt32(ordinals[1]);
			this.location = new Point(x, y);
		}
		static PlaceRecord() {
			PlaceRecord.memo = new Hashtable();
		}

		static protected Hashtable memo;
		static public PlaceRecord Maker(DataRow row) {
			if(!(PlaceRecord.memo.ContainsKey(row))) {
				PlaceRecord newRecord = null;
				// check related tables to determine this row's type
				if(row.GetChildRows(ATTRACTION_RELATION).Length > 0) {
					newRecord = new AttractionPlaceRecord(row);
				} else if(row.GetChildRows(FOOD_RELATION).Length > 0) {
					newRecord = new FoodPlaceRecord(row);
				} else if(row.GetChildRows(SHOP_RELATION).Length > 0) {
					newRecord = new ShopPlaceRecord(row);
				} else if(row.GetChildRows(SHOW_RELATION).Length > 0) {
					newRecord = new ShowPlaceRecord(row);
				} else if(row.GetChildRows(SERVICE_RELATION).Length > 0) {
					newRecord = new ServicePlaceRecord(row);
				} else if(row.GetChildRows(TRANSPORT_RELATION).Length > 0) {
					newRecord = new TransportPlaceRecord(row);
				}
				PlaceRecord.memo[row] = newRecord;
			} 
			return (PlaceRecord)PlaceRecord.memo[row];
		}

		protected PlaceRecord[] selectByIDs(string idRefs) {
			// convert a space-separated list of IDs "ID ID ID" (XML-style) 
			// to the form "('ID', 'ID', 'ID')" (SQL-style) and append it to "ID IN "
			// to create the SQL query for the DataSet
			StringBuilder query = new StringBuilder("ID IN ('");
			string nearbyList = idRefs.Replace(" ", "', '");
			query.Append(nearbyList);
			query.Append("')");
			DataRow[] placeRows = this.myRow.Table.Select(query.ToString());
			PlaceRecord[] results = new PlaceRecord[placeRows.Length];
			for(int i=0; i<placeRows.Length; i++) {
				results[i] = PlaceRecord.Maker(placeRows[i]);
			}
			return results;
		}
	}

	public class AttractionPlaceRecord: PlaceRecord {
		public const string DETAIL_TABLE = "Attraction";
		protected const int FIELD_SCALE = 0;
		protected const int FIELD_TYPE = 1;
		protected const int FIELD_WARNING = 2;
		protected const int FIELD_HEIGHT = 3;
		protected const int FIELD_FASTPASS = 4;
		protected const int FIELD_RATING = 5;
		protected const int FIELD_ACCESS = 6;
		
		protected DataRow attractionRow;

		public int Rating {
			get {
				return Convert.ToInt32(this.attractionRow.ItemArray[FIELD_RATING]);
			}
		}
		public bool FastPass {
			get {
				return Convert.ToBoolean(this.attractionRow.ItemArray[FIELD_FASTPASS]);
			}
		}
		public string HeightRestricted {
			get {
				return Convert.ToString(this.attractionRow.ItemArray[FIELD_HEIGHT]);
			}
		}
		public bool Warning {
			get {
				return Convert.ToBoolean(this.attractionRow.ItemArray[FIELD_WARNING]);
			}
		}
		public int Scale {
			get {
				return Convert.ToInt32(this.attractionRow.ItemArray[FIELD_SCALE]);
			}
		}
		public string Type {
			get {
				return Convert.ToString(this.attractionRow.ItemArray[FIELD_TYPE]);
			}
		}
		public string Access {
			get {
				return Convert.ToString(this.attractionRow.ItemArray[FIELD_ACCESS]);
			}
		}
		public AttractionPlaceRecord(DataRow row): base(row) {
			this.attractionRow = this.myRow.GetChildRows(ATTRACTION_RELATION)[0];
		}
	
	}

	public class FoodPlaceRecord: PlaceRecord {
		public const string DETAIL_TABLE = "Food";
		protected const int FIELD_CUISINE = 0;
		protected const int FIELD_PRICE = 1;
		protected const int FIELD_SERVICE = 2;

		protected DataRow foodRow;

		public int Price {
			get {
				return Convert.ToInt32(this.foodRow.ItemArray[FIELD_PRICE]);
			}
		}

		public string[] Cuisine {
			get {
				return Convert.ToString(this.foodRow.ItemArray[FIELD_CUISINE]).Split('|');
			}
		}
		public string Service {
			get {
				return Convert.ToString(this.foodRow.ItemArray[FIELD_SERVICE]);
			}
		}

		public FoodPlaceRecord(DataRow row): base(row) {
			this.foodRow = this.myRow.GetChildRows(FOOD_RELATION)[0];
		}
	
	}

	public class TransportPlaceRecord: PlaceRecord {
		public const string DETAIL_TABLE = "Transport";
		protected const int FIELD_DEPARTURES = 0;
		protected const int FIELD_CONNECTIONS = 1;

		protected DataRow transportRow;

		public PlaceRecord[] Connections {
			get {
				return this.selectByIDs(Convert.ToString(this.transportRow.ItemArray[FIELD_CONNECTIONS]));
			}
		}
		public string Departures {
			get {
				return Convert.ToString(this.transportRow.ItemArray[FIELD_DEPARTURES]);
			}
		}

		public TransportPlaceRecord(DataRow row): base(row) {
			this.transportRow = this.myRow.GetChildRows(TRANSPORT_RELATION)[0];
		}

	
	}

	public class ShopPlaceRecord: PlaceRecord {
		public const string DETAIL_TABLE = "Shop";
		protected const int FIELD_STOCK = 0;

		protected DataRow shopRow;

		public string[] Stock {
			get {
				return Convert.ToString(this.shopRow.ItemArray[FIELD_STOCK]).Split('|');
			}
		}

		public ShopPlaceRecord(DataRow row): base(row) {
			this.shopRow = this.myRow.GetChildRows(SHOP_RELATION)[0];
		}

	
	}

	public class ShowPlaceRecord: PlaceRecord {
		public const string DETAIL_TABLE = "Show";
		protected const int FIELD_SHOWTIME = 0;
		protected const int FIELD_VENUE = 1;

		protected DataRow showRow;

		public string[] Showtime {
			get {
				return Convert.ToString(this.showRow.ItemArray[FIELD_SHOWTIME]).Split('|');
			}
		}
		public string Venue {
			get {
				return Convert.ToString(this.showRow.ItemArray[FIELD_VENUE]);
			}
		}

		public ShowPlaceRecord(DataRow row): base(row) {
			this.showRow = this.myRow.GetChildRows(SHOW_RELATION)[0];
		}

	
	}

	public class ServicePlaceRecord: PlaceRecord {
		public const string DETAIL_TABLE = "Service";
		protected const int FIELD_SERVICES = 0;

		protected DataRow serviceRow;

		public string[] Services {
			get {
				return Convert.ToString(this.serviceRow.ItemArray[FIELD_SERVICES]).Split('|');
			}
		}

		public ServicePlaceRecord(DataRow row): base(row) {
			this.serviceRow = this.myRow.GetChildRows(SERVICE_RELATION)[0];
		}

	
	}
}

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 Code Project Open License (CPOL)


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