public void History() { Booking b = new Booking(); Show s = new Show(); List<Seat> seats; Seat seat = new Seat(); List<Booking> bookingList = new List<Booking>(); bookingInfo.TryGetValue(user, out bookingList); String info_str = ""; if (bookingList == null) { // No History info_str = "You have no booking records. Please make a booking!"; } else { // Fetch History // Building String.. // e.g. [7/31/2015 10:40:33 AM] [The Dark Knight] 1 January 2015 > 0800 - 1000 : Seats A1 String seats_str = ""; for (int i = 0; i < bookingList.Count; i++) { b = bookingList[i]; s = b.Show; seats = b.Seats; seats_str = ""; for (int h = 0; h < seats.Count; h++) { seat = b.Seats[h]; seats_str += seat.Name + " "; } info_str += "[" + s.Movie.Title + " : " + String.Format("${0:0.00}", b.CalculateBaseCost(false)) + "] (Generated @ " + b.BookingTime + ")\n" + "[" + s.Date + "] " + s.TimeStart + " - " + s.TimeEnd + "\n" + "[" + b.Show.Hall.Name + "] " + seats_str; info_str += ENDOFF; } } SendString(info_str); }
public void Booking() { //lock (_object) { // get userid title time seatindex price Boolean bookingSuccess = true; Show show = new Show(); List<Seat> seats = new List<Seat>(); /* R */ // Receive booking info /* R */ ReceiveFile(bseatsFile); seats = DeserializeSeats(bseatsFile, out show); // Create booking from seats Booking bnew = new Booking(user, show, seats); // Get server movie Movie bookMovie = show.Movie; Movie serverMovie = null; foreach (Movie m in movieInfo.Values) { if (m.Title.Equals(bookMovie.Title)) { serverMovie = m; } } // Get server show Show serverShow = null; foreach (Show s in serverMovie.Shows) { if (s.Date.Equals(show.Date) && s.TimeStart.Equals(show.TimeStart)) { serverShow = s; } } List<Seat> serverSeats = serverShow.Hall.Seats; String seat_str = " [ "; foreach(Seat s in seats) { seat_str += "" + s.Name + " "; } seat_str += "]"; form.DisplayMsg("[" + user + "] :: [" + serverMovie.Title + "]\n" + "[" + user + "] :: [" + serverShow.Date + "] [" + serverShow.TimeStart + "]" + seat_str); // Turn seat to unavailable : (!) consider using Dictionary collection foreach(Seat seat in seats) { foreach (Seat serverSeat in serverSeats) { if (seat.Name.Equals(serverSeat.Name)) { if (!serverSeat.Vacant) { bookingSuccess = false; // form.DisplayMsg(seat.Name + " is not vacant"); // (!) Debug } } } } if (bookingSuccess) { lock (_object) { foreach (Seat seat in seats) { foreach (Seat serverSeat in serverSeats) { if (seat.Name.Equals(serverSeat.Name)) { serverSeat.Vacant = false; //form.DisplayMsg(serverSeat.Name + " has been updated to " + // (!) Debug // serverSeat.Vacant.ToString()); } } } } // Save movie info SerializeMovies(moviesFile); // Update booking history List<Booking> userBookingHistory = new List<Booking>(); if (!bookingInfo.TryGetValue(user, out userBookingHistory)) { userBookingHistory = new List<Booking>(); } userBookingHistory.Add(bnew); // Save into booking repository bookingInfo[user] = userBookingHistory; //form.DisplayMsg(userBookingHistory[0].Show.Movie.Title.ToString()); // (!) Debug // Save booking info SerializeBookings(bkHistFile); SendCommand(SUCCESS); form.DisplayMsg("[" + user + "] :: Booking success"); } else { SendCommand(FAILURE); form.DisplayMsg("[" + user + "] :: Booking failed"); } //} }
private void UpdateCinemaPrice(object sender, EventArgs e) { if (listMovies.GetItemText(listMovies.SelectedItem).Length > 0) { int count = 0; List<Seat> seatList = new List<Seat>(); for (int i = 0; i < checkBoxes.Length; i++) { if (checkBoxes[i].CheckState == CheckState.Checked) { seatList.Add(GetShow().Hall.Seats[i]); count++; } } // Always show the price of one ticket if (count == 0) count = 1; Booking b = new Booking(userID, GetShow(), seatList); lblBorder.BackColor = Color.Empty; grpBoxPrice.Visible = true; lblPrice.Text = String.Format("${0:0.00}", b.CalculateBaseCost(false)); } }