Esempio n. 1
0
 public static Cur_booking_Singleton Instance(booking_class book)
 {
     if (instance == null)
     {
         instance      = new Cur_booking_Singleton();
         instance.book = book;
         return(instance);
     }
     else
     {
         instance.book = book;
         return(instance);
     }
 }
        public booking_class Select_booking(int booking_ref, int cust_ref)
        //Method to select the booking, since each booking has a customer associated with it the customer reference must also be used
        {
            Cur_customer_Singleton cur_cust = Cur_customer_Singleton.Instance();

            sql             = "SELECT * FROM booking WHERE booking_ref=" + booking_ref + " AND cust_ref=" + cust_ref + ";"; //Query to find the correct booking given the correct customer reference
            cmd.CommandText = sql;
            sdr             = cmd.ExecuteReader();
            bool          bookExists = false;
            booking_class book       = new booking_class();

            while (sdr.Read()) //while the data reader is reading through the database
            {
                if (sdr.GetString(0) == booking_ref.ToString())

                /*
                 * This if statement will ensure that the booking reference in the database will be equal to the booking reference in the c#
                 * The booking class will have the data from the database saved to the corresponding variable in the booking_class
                 * Ref = first column of the database (i.e the booking reference) etc.
                 */
                {
                    bookExists         = true;
                    book.Ref           = Int32.Parse(sdr.GetString(0));
                    book.Arrivaldate   = sdr.GetString(1);
                    book.DepDate       = sdr.GetString(2);
                    book.Num_of_guests = sdr.GetString(3);
                }
            }
            sdr.Close(); //data reader is no longer in use, therfore close it

            if (bookExists == false)
            //Error checking ensuring that the booking reference exists.
            {
                MessageBox.Show("Booking does not exist given the selected reference number.");
            }
            else
            {
                Cur_booking_Singleton cur_booking = Cur_booking_Singleton.Instance(book);
                Booking bookingWin = new Booking();                         //creating a new booking window
                bookingWin.Show();                                          //open the booking window

                bookingWin.txtBox_booking_ref.Text   = book.Ref.ToString(); //set the text box value, booking ref, to the booking reference
                bookingWin.datepicker_arrival.Text   = book.Arrivaldate;    //The arrival date is already a string and therefore does not need to be converted into a string
                bookingWin.datepicker_dep.Text       = book.DepDate;
                bookingWin.txtBox_num_of_guests.Text = book.Num_of_guests;
            }
            return(book);
        }