/*
* Finding the difference between the start booking date and end booking date
* to calculate the cost of a booking
*/
public void calculateBookingCost(DateTimePicker startDate, DateTimePicker endDate, ComboBox cbo_Description, TextBox txt_Cost)
{
connection.Close();
DateTime dt1 = Convert.ToDateTime(startDate.Text);
DateTime dt2 = Convert.ToDateTime(endDate.Text);
TimeSpan timeSpan = dt2 - dt1;
int numberOfDays = timeSpan.Days;
string query_String = "SELECT Car_Rate FROM Car_Class WHERE Description ='" + cbo_Description.Text + "'";
connection.Open();
try
{
cmd = connection.CreateCommand();
cmd.CommandText = query_String;
data_reader = cmd.ExecuteReader();//the reader is used to read in the required record
if (data_reader.HasRows)
{
data_reader.Read();
txt_Cost.Text = ("" + data_reader.GetInt32(0) * numberOfDays);
}
connection.Close();
}
catch (Exception) { }
}