using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JonesJAsign9
{
    public partial class frmReservation : Form
    {
        const int PRICE_PER_DAY = 115;
        public frmReservation()
        {
            InitializeComponent();
        }
        private void frmReservations_Load(object sender, EventArgs e)
        {

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void frmReservation_Load(object sender, EventArgs e)
        {
            textBoxDepart.Text = DateTime.Today.ToString("d");
            textBoxArrive.Text = DateTime.Today.AddDays(3).ToString("d");
        }

        private void btnOk_Click(object sender, EventArgs e)
        {

            DateTime dtDepart;
            DateTime dtArrive;
            if (string.IsNullOrEmpty(textBoxDepart.Text) || !DateTime.TryParse(textBoxDepart.Text, out dtDepart))
            {
                MessageBox.Show("Invalid departure date!");
                return;
            }
            if (string.IsNullOrEmpty(textBoxArrive.Text) || !DateTime.TryParse(textBoxArrive.Text, out dtArrive))
            {
                MessageBox.Show("Invalid arrival date!");
                return;
            }
            dtDepart = dtDepart.Date; //Trim off the time portion if they entered it
            dtArrive = dtArrive.Date;
            if (dtDepart < DateTime.Today)
            {
                MessageBox.Show("The departure date cannot be before today");
                return;
            }
            //If it is less than dtDepart it is also less than today, so we dont need to check both
            if (dtArrive < dtDepart)
            {
                MessageBox.Show("The departure date cannot be before the departure date");
                return;
            }
            //Days in a year is technically 365.24something since every fourth year
            //is a leap year except every 100 years we don't have a leap year unless
            //it is the 400th year. So no leap year on 2100, 2200, but we do have
            //leap year on 2400. How exact do you need to be?
            DateTime dtUpperBoundary = DateTime.Today.AddDays(365 * 5);
            if (dtDepart > dtUpperBoundary)
            {
                MessageBox.Show("The departure date is more than 5 years in the future");
                return;
            }
            if (dtArrive > dtUpperBoundary)
            {
                MessageBox.Show("The arrival date is more than 5 years in the future");
                return;
            }
            //Do you want to check that?
            if (dtArrive == dtDepart)
            {
                MessageBox.Show("You cannot depart and arrive on the same date");
                return;
            }
            //At this point the dates should be good
            int duration = Convert.ToInt32(Math.Ceiling(Math.Abs(dtArrive.Subtract(dtDepart).TotalDays))) + 1;
            int price = duration * PRICE_PER_DAY;
            string sNumberOfDays = duration.ToString();
            string sArrivalDate = dtArrive.ToString("d");
            string sDeparture = dtDepart.ToString("d");
            string sTotalPrice = price.ToString("C2");
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Number of days: " + sNumberOfDays);
            sb.AppendLine("Arrival Date: " + sArrivalDate);
            sb.AppendLine("Departure Date: " + sDeparture);
            sb.AppendLine("Total Price: " + sTotalPrice);
            MessageBox.Show(sb.ToString());
            //MessageBox.Show(string.Format("The price will be {0:C2}", price));
        }
        }
    }

Okay guys I need help making the information that appears in the message box appear on the form instead. I've posted what I did. here are the specifications:

create a form that accepts an arrival and departure date for a reservation from the user and then calculates the number of nights and the total price for the reservation.

Specifications

The price per night should be $115.

This application should validate both entries to make sure they are dates that are on or after the current date. The application should also validate the departure date to be sure that it is after the arrival date.

This application should only accept reservations within five years of the current date.

When the application starts, it should display the current date in the first text box and the current date plus three days in the second text box. That way, the user can modify these default dates as necessary.

If the user enters invalid dates, the number of nights and total price are cleared.

Put a label on the form where you want it and then assign the .Text value of the label what you were putting in the messagebox.

Why not use a DateTimePicker control directly on your form?
Much less validation to do.
Just put a label Arrival date: and next to it a DateTimePicker etc.
And remember that within a period of 5 years, ther is at least one leap year.
The TimeSpan structure will help you out here.

Try to google first if you are having any problems. The code is quite large... When you get stuck wiht some piece of code that repost and everybody will be glad to help you...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.