Exemple #1
0
        public Booking()
        {
            InitializeComponent();
            Cur_customer_Singleton cur_cust = Cur_customer_Singleton.Instance();

            this.cust_ref = cur_cust.GetRefNum().ToString();
            dbcon.OpenCon();
        }
        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);
        }
Exemple #3
0
        customer_class cust;                            //calling the customer class and setting it to cust

        public static Cur_customer_Singleton Instance()
        //Used for the creation of an instance of this class
        {
            if (instance == null)
            //the following if statemnts will check if the instance already exist
            //if the instance doesn't exist then a new instance is created
            {
                instance = new Cur_customer_Singleton();
                return(instance);
            }
            else
            //otehrwise the current existing instance will be returned
            {
                return(instance);
            }
        }
        public customer_class Select_Cust(int cust_ref)
        {
            //cust_ref = Int32.Parse(txtBox_select_cust.Text); //sets the value of variable cust ref to what is in the select text box
            bool custExists = false;

            sql             = "SELECT * FROM customer WHERE cust_ref = " + cust_ref + ";"; //Sql query to set the value of the sql variable in the database_facade
            cmd.CommandText = sql;                                                         //set the cmd command text to the sql statement
            sdr             = cmd.ExecuteReader();                                         // set the data reader equal tot the execute reader method
            customer_class cust = new customer_class();

            while (sdr.Read())
            {
                if (sdr.GetString(0) == cust_ref.ToString()) //if the value of the first column of the database table is equal to the customer reference
                {
                    custExists     = true;
                    cust.Ref       = Int32.Parse(sdr.GetString(0)); //Get the value of the first column from the database table
                    cust.LastName  = sdr.GetString(1);              //Get the value of the second column from the database table
                    cust.Firstname = sdr.GetString(2);
                    cust.Address   = sdr.GetString(3);
                }
            }

            if (custExists == false) //if the customer does not exist
            {
                MessageBox.Show("Customer does not exist. Try a diffrent customer reference");
            }
            else
            {
                Cur_customer_Singleton cur_cust = Cur_customer_Singleton.Instance(cust);
                Customer cust_Win = new Customer(); //create a new customer window
                //cust_Win.Owner = this;
                cust_Win.Show();

                /*
                 * The next lines will set the value of the text boxes to the previously save values
                 * This will make the text boxes fill in with their correct values
                 */
                cust_Win.txtBox_cust_ref.Text     = cust.Ref.ToString();
                cust_Win.txtBox_cust_last.Text    = cust.LastName;
                cust_Win.txtBox_cust_first.Text   = cust.Firstname;
                cust_Win.txtBox_cust_address.Text = cust.Address;
            }
            sdr.Close(); //closes the data reader - prevents leaks
            return(cust);
        }
Exemple #5
0
 public static Cur_customer_Singleton Instance(customer_class cust)
 //Instance of customer where the customer data exists
 //a new instance of customer will be made, calling the previous method
 //if the customer instance is already non-existant
 {
     if (instance == null)
     {
         instance      = new Cur_customer_Singleton();
         instance.cust = cust;
         return(instance);
     }
     else
     //otherwise the existing instance of customer will be called
     {
         instance.cust = cust;
         return(instance);
     }
 }
        public int place_cust_ref()
        {
            int result = 0;

            sql             = "SELECT MAX(cust_ref) FROM customer;"; //ovverides the sql cariable contents
            cmd.CommandText = sql;                                   //set command text equal to the sql variable
            sdr             = cmd.ExecuteReader();
            while (sdr.Read())
            {
                result = Int32.Parse(sdr.GetString(0)); //set variable equal to the first column of the table
            }
            sdr.Close();

            //creating a new instance of the customer singelton
            customer_class         cust     = Select_Cust(result);
            Cur_customer_Singleton cust_sin = Cur_customer_Singleton.Instance(cust);

            return(result);
        }