public void LoadChart(SeatingChart chart)
        {
            visibleChart = chart;

            for (int i = 0; i < SeatingChart.Height; i++)
            {
                for (int j = 0; j < SeatingChart.Width; j++)
                {
                    Color color;
                    switch (chart.seats[i, j].seatStatus)
                    {
                    case SeatStatus.Available: color = Color.White; break;

                    case SeatStatus.Reserved: color = Color.Firebrick; break;

                    case SeatStatus.Taken: color = Color.Gray; break;

                    case SeatStatus.Null: color = new Color(0, 0, 0, 0); break;

                    default: color = Color.White; break;
                    }

                    seatButtons[i, j].IsEnabled       = chart.seats[i, j].seatStatus == SeatStatus.Available;
                    seatButtons[i, j].BackgroundColor = color;
                }
            }
        }
Example #2
0
		/// <summary>
		/// Loads all the movies from the movies folder. 
		/// This is very expensive and should only be called at the start of program or to reset the movie list.
		/// </summary>
		public static void Initialize()
		{
			seatingCharts.Clear();
			movies.Clear();

			//Search resources for movie definitions to load
			Random random = new Random();
			var assembly = Assembly.GetExecutingAssembly();
			string[] resources = assembly.GetManifestResourceNames();
			foreach (string resource in resources)
			{
				if (resource.StartsWith("Theater-Application.Movies."))
				{
					//Parse movie information from the file.
					Stream stream = assembly.GetManifestResourceStream(resource);
					StreamReader reader = new StreamReader(stream);
					string json = reader.ReadToEnd();
					string name = resource.Remove(0, "Theater-Application.Movies.".Length);
					Movie movie = JsonConvert.DeserializeObject<Movie>(json);
					movies.Add(name, movie);

					//Generate movie seating randomly.
					List<SeatingChart> unsorted = new List<SeatingChart>();
					int showings = random.Next(2, 5);
					for (int i = 0; i < showings; i++)
					{
						SeatingChart newChart = new SeatingChart(random.NextDouble() / 2 + 0.05);
						unsorted.Add(newChart);
					}

					//Create a sorted list to order movies by time (earliest to latest)
					List<SeatingChart> sorted = new List<SeatingChart>();
					while (unsorted.Count > 0)
					{
						SeatingChart earliest = unsorted[0];
						int earliestTimescore = 1440;
						foreach (SeatingChart chart in unsorted)
						{
							int timeScore = (chart.hour * 60) + chart.minute;
							if (timeScore < earliestTimescore)
							{
								earliest = chart;
								earliestTimescore = timeScore;
							}
						}

						unsorted.Remove(earliest);
						sorted.Add(earliest);
					}

					//Post sorted array to seating chart lookup
					seatingCharts.Add(movie, sorted);
				}
			}

			initialized = true;
		}
        private void Button_TimeSelect(object sender, EventArgs e)
        {
            Button       buttonSender = (Button)sender;
            SeatingChart chart        = (SeatingChart)buttonSender.BindingContext;

            if (visibleChart != chart)
            {
                foreach (Button button in timeButtons)
                {
                    button.TextColor   = Color.Firebrick;
                    button.BorderColor = Color.Firebrick;
                }

                LoadChart(chart);

                buttonSender.TextColor   = Color.White;
                buttonSender.BorderColor = Color.White;
            }
        }