Ejemplo n.º 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (cboTypes.SelectedIndex == -1)//Nothing selected
            {
                MessageBox.Show("A Room Type must be selected", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboTypes.Focus();
                return;
            }

            if (dtpFrom.Text == dtpTo.Text)// makes sure the users arrival and depature date are not the same
            {
                MessageBox.Show("You cannot make a resrvation for the same day", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (dtpTo.MinDate < dtpFrom.Value)//makes sure that the depature date isnt before date of arrival
            {
                MessageBox.Show("You cannot make a resrvation for a date before the date of arrival", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtpTo.Focus();
                return;
            }

            else
            {
                //if it passes the validation create a dataset. call the method get available rooms. This method checks to confirm a booking has not been made on that date for that room
                DataSet ds = new DataSet();


                ds = Reservations.getAvailableRooms(ds, dtpFrom.Value.ToString("yyyy-MM-dd"), dtpTo.Value.ToString("yyyy-MM-dd"), cboTypes.Text.Substring(0, 3));
                // if no rooms pass that validation displays approiate error message otherwise fills the room no box with the available rooms
                if (ds.Tables["ss"].Rows.Count == 0)
                {
                    MessageBox.Show("Sorry there are no available rooms for the period selected. Please select another Date/Type", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    cboTypes.SelectedIndex = -1;
                    cboTypes.Focus();
                }
                else
                {
                    cmbRoomNo.Items.Clear();
                    for (int i = 0; i < ds.Tables["ss"].Rows.Count; i++)
                    {
                        cmbRoomNo.Items.Add(ds.Tables[0].Rows[i][0].ToString());
                    }

                    Reservations makeRes = new Reservations();

                    //res id to string
                    txtResID.Text = Reservations.nextResId().ToString("000000");
                    //calculating the cost of the reservation giving the user a price be4 confirming reservation
                    // finding days between storing in p
                    double p = (Convert.ToDateTime(dtpTo.Text) - Convert.ToDateTime(dtpFrom.Text)).TotalDays;
                    // finding the rate
                    decimal x = Reservations.findRateprov(cboTypes.Text);
                    // making x a double so that it can be multiplied by totaldays between
                    double dbl = Convert.ToDouble(x);



                    double ans = Convert.ToDouble(p * dbl);
                    txtCost.Text = Convert.ToString(ans);



                    grpReservaion.Visible = true;
                }
            }
        }