private void btnConfirm_Click(object sender, EventArgs e) { if (txtCustName.Text == String.Empty) { //Checking if customersname has been entered correctly and putting cursor there if it isnt MessageBox.Show("Customers Name must be Entered", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCustName.Focus(); return; } if (txtEmail.Text == String.Empty) { //Checking if E-mail has been entered correctly and putting cursor there if it isnt MessageBox.Show("E-mail must be entered", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return; } if (txtCustName.Text.Any(Char.IsDigit)) { MessageBox.Show("CustName only accepts letters"); txtCustName.Focus(); return; } //Checking if RoomNo has been selected correctly and putting cursor there if it isnt if (cmbRoomNo.SelectedIndex == -1)//Nothing selected { MessageBox.Show("A Room No must be selected", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); cmbRoomNo.Focus(); return; } else { //adding details to reservation and calculating total cost of stay Reservations makeRes = new Reservations(); makeRes.setRes_ID(Reservations.nextResId()); makeRes.setRoom_No(Convert.ToInt32(cmbRoomNo.Text)); makeRes.setCust_Name(txtCustName.Text.ToUpper()); makeRes.setE_Mail(txtEmail.Text.ToUpper()); makeRes.setDate_Arrive(dtpFrom.Value.ToString("yyyy-MM-dd")); makeRes.setDate_Depart(dtpTo.Value.ToString("yyyy-MM-dd")); makeRes.setTotal_Cost((Convert.ToDateTime(dtpTo.Text) - Convert.ToDateTime(dtpFrom.Text)).TotalDays * Reservations.findRate(makeRes.getRoom_No(Convert.ToInt32(cmbRoomNo.Text)))); makeRes.setCheck_In("A"); makeRes.setCheck_Out("A"); makeRes.setRes_Status("A"); makeRes.makeReservation(); //Clearing the ui MessageBox.Show("A Reservation has been successfully made"); txtCustName.Clear(); txtEmail.Clear(); cmbRoomNo.SelectedIndex = -1; cboTypes.SelectedIndex = -1; grpReservaion.Visible = false; } }
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; } } }