コード例 #1
0
        public static ReservationManager loadFromFileReservation()
        {
            ReservationManager rm = new ReservationManager(500, 100);
            int          numResos, resoId, eventDay, eventMonth, eventYear, eventHour, eventMinute, eventMaxAttendees, eventId, custId, custBookings;
            string       eventName, eventVenue, resDate, custFName, custLName, custPhone;
            Date         eventDate;
            StreamReader sr;

            string fileName = "reservationData.txt";
            string path     = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), @"Data\", fileName);

            if (File.Exists(path))
            {
                sr = new StreamReader(path);
            }
            else
            {
                return(rm);
            }

            if (sr.ReadLine() == null)
            {
                StreamWriter sw = new StreamWriter(path);
                sw.WriteLine("0");
            }

            sr.DiscardBufferedData();
            sr.BaseStream.Position = 0;
            numResos = Convert.ToInt32(sr.ReadLine());
            for (int x = 0; x < numResos; x++)
            {
                resoId            = Convert.ToInt32(sr.ReadLine());
                resDate           = sr.ReadLine();
                eventId           = Convert.ToInt32(sr.ReadLine());
                eventName         = sr.ReadLine();
                eventVenue        = sr.ReadLine();
                eventDay          = Convert.ToInt32(sr.ReadLine());
                eventMonth        = Convert.ToInt32(sr.ReadLine());
                eventYear         = Convert.ToInt32(sr.ReadLine());
                eventHour         = Convert.ToInt32(sr.ReadLine());
                eventMinute       = Convert.ToInt32(sr.ReadLine());
                eventDate         = new Date(eventDay, eventMonth, eventYear, eventHour, eventMinute);
                eventMaxAttendees = Convert.ToInt32(sr.ReadLine());
                custId            = Convert.ToInt32(sr.ReadLine());
                custFName         = sr.ReadLine();
                custLName         = sr.ReadLine();
                custPhone         = sr.ReadLine();
                custBookings      = Convert.ToInt32(sr.ReadLine());
                Event    resEvent    = new Event(eventId, eventName, eventVenue, eventDate, eventMaxAttendees);
                Customer resCustomer = new Customer(custId, custFName, custLName, custPhone, custBookings);
                rm.addReservation(resoId, resDate, resEvent, resCustomer);
            }
            sr.Close();
            return(rm);
        }
コード例 #2
0
 public bool addReservation(string currTime, Event resEvent, Customer resCust)
 {
     return(resMan.addReservation(currTime, resEvent, resCust));
 }