/// <summary> /// Creates a new ticket for booking - saving user's id, show and list of seats /// </summary> /// <param name="user">User identification</param> /// <param name="show">Show object</param> /// <param name="seats">List of Seats</param> public Booking(String user, Show show, List<Seat> seats) { User = user; Show = show; Seats = seats; BookingTime = DateTime.Now; }
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"); } //} }
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 List<Seat> DeserializeSeats(String filePath, out Show show) { List<Seat> output = new List<Seat>(); show = new Show(); try { using (fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Object[] obj_info = (Object[])formatter.Deserialize(fs); fs.Flush(); fs.Close(); show = (Show)obj_info[0]; int sz = (int)obj_info[1]; // form.DisplayMsg(obj_info.Length.ToString()); // Add seats - potential indexoutofrange exception for (int i = 2 ; i < sz ; i++) { output.Add((Seat)obj_info[i]); } } } catch (Exception ex) { form.DisplayMsg(ex.ToString()); } return output; }