Ejemplo n.º 1
0
        public ListBookings(Welcome welcomeForm, OdbcConnection odbcConnection, HashSet<BookingInformation> bookings)
            : this()
        {
            objectWelcomeForm = welcomeForm;
            objectOdbcConnection = odbcConnection;
            bookingsListView.Columns.Add("Guest ID");
            bookingsListView.Columns.Add("First Name");
            bookingsListView.Columns.Add("Last Name");
            bookingsListView.Columns.Add("Phone");
            bookingsListView.Columns.Add("CheckIn Date");
            bookingsListView.Columns.Add("CheckOut Date");
            bookingsListView.Columns.Add("Room Number");
            bookingsListView.Columns.Add("Booking Status");

            bookingsListView.Columns[0].Width = 100;
            bookingsListView.Columns[1].Width = 125;
            bookingsListView.Columns[2].Width = 125;
            bookingsListView.Columns[3].Width = 100;
            bookingsListView.Columns[4].Width = 80;
            bookingsListView.Columns[5].Width = 80;
            bookingsListView.Columns[6].Width = 80;
            bookingsListView.Columns[7].Width = 100;

            //bookingsListBox.Items.Add(lv);
            for(int i= 0; i<bookings.Count; i++)
            {
                string[] listColumns = new string[8];
                listColumns[0] = bookings.ElementAt(i).bookedGuest.guestId;
                listColumns[1] = bookings.ElementAt(i).bookedGuest.firstName;
                listColumns[2] = bookings.ElementAt(i).bookedGuest.lastName;
                listColumns[3] = bookings.ElementAt(i).bookedGuest.phone;
                listColumns[4] = bookings.ElementAt(i).checkInDate.ToShortDateString();
                listColumns[5] = bookings.ElementAt(i).checkOutDate.ToShortDateString();
                listColumns[6] = bookings.ElementAt(i).bookedRoom.roomNumber;
                listColumns[7] = bookings.ElementAt(i).status;
                ListViewItem li = new ListViewItem(listColumns);
                if (i % 2 == 0)
                {
                    li.BackColor = Color.Gainsboro;
                }
                bookingsListView.Items.Add(li);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///  Establish a DSN connection with HotelReservationSystem database using 
 ///  ODBCConnection class and validate userID and Password. If a user is
 ///  authorized, it logon the user to the Welcome page of the HotelReservationSystem
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void logonButton_Click(object sender, EventArgs e)
 {
     try
     {
         //Establish connection with database using OdbcConnection class
         OdbcConnection objectOdbcConnection = new OdbcConnection(CONNECTION_STRING);
         objectOdbcConnection.Open();
         //Create an OdbcCommand object using CreateCommand of the OdbcConnection object
         OdbcCommand objectOdbcCommand = objectOdbcConnection.CreateCommand();
         objectOdbcCommand.CommandText = "SELECT * FROM USERS WHERE userId = ? and password= ?";
         objectOdbcCommand.Parameters.Add("userid", OdbcType.NVarChar).Value = userIDTextBox.Text;
         objectOdbcCommand.Parameters.Add("pasword", OdbcType.NVarChar).Value = passwordTextBox.Text;
         OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();
         dbReader.Read();
         if (dbReader.HasRows)
         {
             //This is a valid userId/password, show the welcome page
             Welcome objectWelcomeForm;
             objectWelcomeForm = new Welcome();
             objectWelcomeForm.Show();
             this.Hide();
             dbReader.Close();
             objectOdbcCommand.Dispose();
             objectOdbcConnection.Close();
             return;
         }
         //The user id or password is not valid
         dbReader.Close();
         objectOdbcCommand.Dispose();
         objectOdbcConnection.Dispose();
         objectOdbcConnection.Close();
         MessageBox.Show("Please enter a valid user and password");
     }
     catch (Exception exp)
     {
         MessageBox.Show("An exception in the code: \n" + exp.Message.ToString());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Overloaded Constructor: 
 /// This constructor will accept object of Welcome class, an opened 
 /// OdbcConnection and BookingInformation object as input. When this
 /// form is closed, it uses the Welcome object passed on via this
 /// constructor to "show" the hidden Welcome form back to the user.
 /// </summary>
 /// <param name="welcomeForm">WlecomeForm</param>
 /// <param name="odbcConnection">OdbcConnection</param>
 /// <param name="bookingInformation">BookingInformation</param>
 public Booking(Welcome welcomeForm, 
     OdbcConnection odbcConnection,
     BookingInformation bookingInformation)
     : this()
 {
     objWelcomeForm = welcomeForm;
     objectOdbcConnection = odbcConnection;
     objectBookingInformation = bookingInformation;
 }