示例#1
0
 public static SingletonFileHandler Instance(Booking booking, Customer cust, List <Guest> guests, Extras extra)
 {
     if (_instance == null)
     {
         _instance = new SingletonFileHandler(booking, cust, guests, extra);
     }
     return(_instance);
 }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            //On click of addall to booking
            //Unit test is carried out to show functionality of classes
            //Tests are outputted to the Console.
            UnitTest test = new UnitTest();
            bool     flag = false;

            booking = new Booking(); //flush booking/cust to remove any old data
            cust    = new Customer();
            try
            {
                booking.ArrivalDate     = txtArrivalDate.Text;
                booking.DepartureDate   = txtDepDate.Text;
                cust.Name               = txtCustName.Text;
                cust.Address            = txtCustAdd.Text;
                booking.ReferenceNumber = int.Parse(File.ReadLines(@"D:\refno.txt").Last()) + 1; //get refno and ++
                if (!isGuestSet())
                {
                    throw new ArgumentException("Please Add at least one Guest", "Guest");
                }
                if (Convert.ToDateTime(booking.DepartureDate) < Convert.ToDateTime(booking.ArrivalDate))
                {
                    throw new ArgumentException("Departure Date must be after arrival date", "Date");
                }
                flag = true;
            }
            catch (Exception excep)
            {
                //catch errors thrown by class properties
                MessageBox.Show(excep.Message, "Error");
            }
            if (flag)
            {
                //If no errors in data
                double price = CalculateCost();
                lblCost.Content = "Cost: " + price;
                Guest[]      guestlist = { Window1.guestOne, Window1.guestTwo, Window1.guestThree, Window1.guestFour };
                List <Guest> SetGuests = new List <Guest>();
                foreach (Guest x in guestlist)
                {
                    if (!String.IsNullOrEmpty(x.Name))
                    {
                        SetGuests.Add(x);
                    }
                }
                SingletonFileHandler.RESET(); //reset singleton so new data can be added
                SingletonFileHandler fh = SingletonFileHandler.Instance(booking, cust, SetGuests, extrasWind);
            }
        }
示例#3
0
 public static void RESET()
 {
     //if booking already created, flush class
     _instance = null;
 }