Hello:(
I have an assignment to build the booking and payment part of a Thearte Booking System. I have four classes linked to an MDF database
- well they should be - the two that we have been given will will be and the two that I have done might be!
The first thing that I have to do is test the classes on a test form.
As an example I have put the SheduledEvents class at the bottom of the post (one that I have been given so it should be correct).
So, as I understand it - I have to return a lsit of scheduled events to the test form, say in a list box, from a ScheduledEventSortedList.
I have spent two days trying to return the data row for scheduledEventID on my test form and failed. There is an example of one attempt
of many below, and like all the others, it doesn't work.
namespace TheatreTicketBooking
{
public partial class ScheduledEventsTestForm : Form
{
int ScheduledEventID = 0;
ScheduledEventsTestForm[] TestEvent;
public ScheduledEventsTestForm(int SEID)//SEID for ScheduledEventID
{
InitializeComponent();
lstEventData.Text = " Scheduled Event ID: " + ScheduledEventID;
return drEventList[0];
}
}
Could someone please point me in the right direction
All the best John:)
Here is the class that I am testing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//added these
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace TheatreTicketBooking
{
class ScheduledEvent
{
private int m_ScEventID;
private string m_EventName;
private DateTime m_DateOfEvent;
private string m_TimeOfEvent;
private decimal m_AdultPrice;
private decimal m_ConcessionPrice;
private decimal m_FriendPrice;
private string m_Confirmed;
private string m_Artist;
private string m_Location;
// Declare an ScheduledEventID property of type int:
public int ScheduledEventID
{
get
{
return m_ScEventID;
}
set
{
m_ScEventID = value;
}
}
// Declare an EventName property of type string:
public string EventName
{
get
{
return m_EventName;
}
set
{
m_EventName = value;
}
}
// Declare a DateOfEvent property of type DateTime:
public DateTime DateOfEvent
{
get
{
return m_DateOfEvent;
}
set
{
m_DateOfEvent = value;
}
}
// Declare a TimeOfEvent property of type string:
public string TimeOfEvent
{
get
{
return m_TimeOfEvent;
}
set
{
m_TimeOfEvent = value;
}
}
// Declare an AdultPrice property of type decimal:
public decimal AdultPrice
{
get
{
return m_AdultPrice;
}
set
{
m_AdultPrice = value;
}
}
// Declare a ConcessionPrice property of type decimal:
public decimal ConcessionPrice
{
get
{
return m_ConcessionPrice;
}
set
{
m_ConcessionPrice = value;
}
}
// Declare a FriendPrice property of type decimal:
public decimal FriendPrice
{
get
{
return m_FriendPrice;
}
set
{
m_FriendPrice = value;
}
}
// Declare a Confirmed property of type string:
public string Confirmed
{
get
{
return m_Confirmed;
}
set
{
m_Confirmed = value;
}
}
// Declare an Artist property of type string:
public string Artist
{
get
{
return m_Artist;
}
set
{
m_Artist = value;
}
}
// Declare a Location property of type string:
public string Location
{
get
{
return m_Location;
}
set
{
m_Location = value;
}
}
//For a given ScheduledEventID, retrieve a ScheduledEvent object
public void GetEventByID(int ScheduledEventID)//being passed this ID (intCutomer No oncustomers
{
string TBConnectionString = ConfigurationManager.ConnectionStrings["TicketBookingConnectionString"].ConnectionString;
SqlConnection cnTB = new SqlConnection(TBConnectionString);
cnTB.Open();
SqlCommand cmEvent = new SqlCommand();
cmEvent.Connection = cnTB;
cmEvent.CommandType = CommandType.Text;
cmEvent.CommandText = "Select * from ScheduledEvents where ScheduledEventID = " + ScheduledEventID;//star - read it all
SqlDataReader drEvent = cmEvent.ExecuteReader();
drEvent.Read();// go and read the data
//the variables
m_ScEventID = (int)drEvent[0];
m_EventName = drEvent[1].ToString();//
m_DateOfEvent = (DateTime)drEvent[2];
m_TimeOfEvent = drEvent[3].ToString();
m_AdultPrice = (decimal)drEvent[4];
m_ConcessionPrice = (decimal)drEvent[5];
m_FriendPrice = (decimal)drEvent[6];
m_Confirmed = drEvent[7].ToString();
m_Artist = drEvent[8].ToString();
m_Location = drEvent[9].ToString();
drEvent.Close();
cnTB.Close();
}
//Return a SortedList of ScheduledEvent objects for a given date
public SortedList ListEventsByDateOfEvent(DateTime EventDate)
{
string TBConnectionString = ConfigurationManager.ConnectionStrings["TicketBookingConnectionString"].ConnectionString;
string EventDateString = EventDate.ToString("MM/dd/yyyy");
SqlConnection cnTB = new SqlConnection(TBConnectionString);
cnTB.Open();
SqlCommand cmEventList = new SqlCommand();
cmEventList.Connection = cnTB;
cmEventList.CommandType = CommandType.Text;
cmEventList.CommandText = "Select ScheduledEventID, EventName, ArtistName, Location, Confirmed from ScheduledEvents where DateOfEvent = '" + EventDateString + "'";
SqlDataReader drEventList = cmEventList.ExecuteReader();
SortedList EventList = new SortedList();//creating a new sorted list
while (drEventList.Read())// while it reads the data rows one at a time
{
if (drEventList[4].ToString() == "Y")
{
EventList.Add(drEventList[0], drEventList[1].ToString() + " - " + drEventList[2].ToString() + " - " + drEventList[3].ToString());// list the fields
}
}
drEventList.Close();
cnTB.Close();
return EventList;
}
}
}