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 Project_9_2
{
public partial class FrmReservations : Form
{
public FrmReservations()
{
InitializeComponent();
}
private void FrmReservations_Load(object sender, EventArgs e)
{
DateTime currentDate = DateTime.Today;
txtArrivalDate.Text = currentDate.ToString("d");
txtDepartureDate.Text = currentDate.AddDays(3).ToString("d");
}
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
if (IsValidData())
{
DateTime arrivalDate = DateTime.Parse(txtArrivalDate.Text);
DateTime departureDate = DateTime.Parse(txtDepartureDate.Text);
decimal totalPrice = numNights * 115;
if(arrivalDate > currentDate.AddYears(5))
{
MessageBox.Show("Arrival Date must be less than 5 years");
}
else
{
TimeSpan ts = departureDate.Subtract(arrivalDate);
int numNights = ts.Days;
}
txtArrivalDate.Text = arrivalDate.ToShortDateString();
txtDepartureDate.Text = departureDate.ToShortDateString();
txtNumNights.Text = numNights.ToString();
txtTotalPrice.Text = totalPrice.ToString("c");
txtArrivalDate.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" +
ex.GetType().ToString() + "\n" +
ex.StackTrace, "Exception");
}
}
}
public bool IsValidData()
{
return
//Validate that arrival and departure dates are on or after current date.
IsValidDate(txtArrivalDate, "Arrival Date") &&
//Validate that departure date is after arrival date
IsValidDate(txtDepartureDate, "Departure Date");
}
public bool IsValidDate(TextBox textBox, string name, currentDate)
{
if (textBox.Text < currentDate)
{
MessageBox.Show(name + " must be later than today, must enter current date or later.", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Reservations Form Error- Help C# .netGetting 3 instances of this error mesage
Page 1 of 1
9 Replies - 1275 Views - Last Post: 24 June 2010 - 06:13 PM
#1
Reservations Form Error- Help C# .net
Posted 23 June 2010 - 08:58 PM
I finally got the code to work, but now I am getting 3 instances of this error message: Expected class, delegate, enum, or struct. and it is going to the bool on public bool ...
Replies To: Reservations Form Error- Help C# .net
#2
Re: Reservations Form Error- Help C# .net
Posted 23 June 2010 - 09:42 PM
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" +
ex.GetType().ToString() + "\n" +
ex.StackTrace, "Exception");
}
}
}
That last '}' there closes your class statement. Don't think you wanted to do that yet.
#3
Re: Reservations Form Error- Help C# .net
Posted 23 June 2010 - 09:46 PM
I fixed that now it gives me 3 identifier error instances at the end of say public bool IsWithinRange(TextBox textBox, string name)
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 Project_9_2
{
public partial class FrmReservations : Form
{
public FrmReservations()
{
InitializeComponent();
}
private void FrmReservations_Load(object sender, EventArgs e)
{
DateTime currentDate = DateTime.Today;
txtArrivalDate.Text = currentDate.ToString("d");
txtDepartureDate.Text = currentDate.AddDays(3).ToString("d");
}
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
if (IsValidData())
{
DateTime currentDate = DateTime.Today;
DateTime arrivalDate = DateTime.Parse(txtArrivalDate.Text);
DateTime departureDate = DateTime.Parse(txtDepartureDate.Text);
TimeSpan ts = departureDate.Subtract(arrivalDate);
int numNights = ts.Days;
decimal totalPrice = numNights * 115;
txtArrivalDate.Text = arrivalDate.ToShortDateString();
txtDepartureDate.Text = departureDate.ToShortDateString();
txtNumNights.Text = numNights.ToString();
txtTotalPrice.Text = totalPrice.ToString("c");
txtArrivalDate.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" +
ex.GetType().ToString() + "\n" +
ex.StackTrace, "Exception");
}
}
public bool IsValidData()
{
return
//Validate that arrival and departure dates are on or after current date.
IsValidDate(txtArrivalDate, "Arrival Date") &&
IsWithinRange(txtArrivalDate, "Arrival Date")&&
//Validate that departure date is after arrival date
IsValidDate(txtDepartureDate, "Departure Date");
}
public bool IsValidDate(TextBox textBox, string name, currentDate)
{
if (textBox.Text < currentDate)
{
MessageBox.Show(name + " must be later than today, must enter current date or later.", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
public bool IsWithinRange(TextBox textBox, string name, arrivalDate, currentDate)
{
if (arrivalDate > currentDate.AddYears(5))
{
MessageBox.Show(name + " must be within 5 years", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
#4
Re: Reservations Form Error- Help C# .net
Posted 24 June 2010 - 01:28 AM
I tried to fix your code, but there is so many things that need to be changed, so I advise you to rethink the logic and rewrite this form. Use DateTimePickers for choosing your date instead of parsing the text from your ArrivateDate & DepartureDate textboxes.
#5
Re: Reservations Form Error- Help C# .net
Posted 24 June 2010 - 01:55 AM
OK, this is just a partially fixed solution, although there are still lines of code that would need rewriting...
If you need any additional information about the code, feel free to ask...
If you need any additional information about the code, feel free to ask...
namespace Project_9_2
{
public partial class FrmReservations : Form
{
public FrmReservations()
{
InitializeComponent();
}
private void FrmReservations_Load(object sender, EventArgs e)
{
DateTime currentDate = DateTime.Today;
txtArrivalDate.Text = currentDate.ToString("d");
txtDepartureDate.Text = currentDate.AddDays(3).ToString("d");
}
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
if (IsValidData)
{
DateTime currentDate = DateTime.Today;
DateTime arrivalDate = DateTime.Parse(txtArrivalDate.Text);
DateTime departureDate = DateTime.Parse(txtDepartureDate.Text);
TimeSpan ts = departureDate.Subtract(arrivalDate);
int numNights = ts.Days;
decimal totalPrice = numNights * 115;
txtArrivalDate.Text = arrivalDate.ToShortDateString();
txtDepartureDate.Text = departureDate.ToShortDateString();
txtNumNights.Text = numNights.ToString();
txtTotalPrice.Text = totalPrice.ToString("c");
txtArrivalDate.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" +
ex.GetType().ToString() + "\n" +
ex.StackTrace, "Exception");
}
}
public bool IsValidData
{
get
{
if (IsDate(txtArrivalDate.Text) && IsDate(txtDepartureDate.Text))
{
return IsValidDate(txtArrivalDate, "Arrival Date", DateTime.Today) &&
IsWithinRange(txtArrivalDate, "Arrival Date", DateTime.Parse(txtArrivalDate.Text), DateTime.Now) &&
IsValidDate(txtDepartureDate, "Departure Date", DateTime.Today);
}
return false;
}
}
public bool IsDate(string text)
{
DateTime date;
return DateTime.TryParse(text, out date);
}
public bool IsValidDate(TextBox textBox, string dateName, DateTime currentDate)
{
if (IsDate(textBox.Text))
{
if (DateTime.Parse(textBox.Text) >= currentDate)
{
return true;
}
else
{
MessageBox.Show(dateName + " must be later than today, must enter current date or later.", "Entry Error");
textBox.Focus();
}
}
return false;
}
public bool IsWithinRange(TextBox textBox, string dateName, DateTime arrivalDate, DateTime currentDate)
{
if (arrivalDate > currentDate.AddYears(5))
{
MessageBox.Show(dateName + " must be within 5 years", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
#6
Re: Reservations Form Error- Help C# .net
Posted 24 June 2010 - 05:52 AM
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 Project_9_2
{
public partial class FrmReservations : Form
{
public FrmReservations()
{
InitializeComponent();
}
private void FrmReservations_Load(object sender, EventArgs e)
{
DateTime currentDate = DateTime.Today;
txtArrivalDate.Text = currentDate.ToString("d");
txtDepartureDate.Text = currentDate.AddDays(3).ToString("d");
}
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
if (IsValidData())
{
DateTime arrivalDate = DateTime.Parse(txtArrivalDate.Text);
DateTime departureDate = DateTime.Parse(txtDepartureDate.Text);
decimal totalPrice = numNights * 115;
if(arrivalDate > currentDate.AddYears(5))
{
MessageBox.Show("Arrival Date must be less than 5 years");
}
else
{
TimeSpan ts = departureDate.Subtract(arrivalDate);
int numNights = ts.Days;
}
txtArrivalDate.Text = arrivalDate.ToShortDateString();
txtDepartureDate.Text = departureDate.ToShortDateString();
txtNumNights.Text = numNights.ToString();
txtTotalPrice.Text = totalPrice.ToString("c");
txtArrivalDate.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" +
ex.GetType().ToString() + "\n" +
ex.StackTrace, "Exception");
}
}
}
public bool IsValidData()
{
return
//Validate that arrival and departure dates are on or after current date.
IsValidDate(txtArrivalDate, "Arrival Date") &&
//Validate that departure date is after arrival date
IsValidDate(txtDepartureDate, "Departure Date");
}
public bool IsValidDate(TextBox textBox, string name, currentDate)
{
if (Convert.ToDateTime(textBox.Text) < currentDate)
{
MessageBox.Show(name + " must be later than today, must enter current date or later.", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
for solve complication use datetimepicker control Instead of textbox
#7
Re: Reservations Form Error- Help C# .net
Posted 24 June 2010 - 06:27 AM
Thank you for your help. I hate that I am so lost on this, my instructor is virtually non existent. I made some corrections on my code, but still am lost as to where to go from there. We don't have anything in our book about the DateTimePicker,
#9
Re: Reservations Form Error- Help C# .net
Posted 24 June 2010 - 12:37 PM
Great! Thank you for the link.
#10
Re: Reservations Form Error- Help C# .net
Posted 24 June 2010 - 06:13 PM
Thank You everyone for your help, I finally got the program working properly. I don't know what I would have done without you
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|