Hello
Firstly - sorry to Mitja and kimbokasteniv who replied to this question a few days ago. I know your answers are correct, and I thought I understood but I don't. Or at least I don't know how
to apply what you have said. My fault.
Both my brain and my bottom have gone numb through staring at this for so long!
I wish that was a joke:icon_eek:
http://www.daniweb.com/software-development/csharp/threads/360517
I know that the class form and the sql it contains should be able to return all the data from the database but I don't 'get' how to make the test
form relate to the class form and return that data. I have tried to pass the schedledEvent variable to the test form but keep getting errors!
If I make the button clicks public and pass the ScheduledEventID for example I get event handler errors.
I am probably doing something basic wrong.
Whilst I recognise I am not very good at this - I am determined not to give up ... so would be grateful for any more help.
Thank you ... John.
My question again,
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.
The first thing that I have to do is test the classes on a test form.
I have put the SheduledEvents class at the bottom of the post.
This is the class cs
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;
}
}
}
This is my attempts (mainly with help) to test it
I have tried to return a scheduled events by ID, and events by date to the test form in a list boxes. This is the code on the back of my test form.
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;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
namespace TheatreTicketBooking
{
public partial class ScheduledEventsTestForm : Form
{
ScheduledEvent currentEvent;
int ScheduledEventID = 0;
public ScheduledEventsTestForm()//this is the constructer method - I think
{
InitializeComponent();
currentEvent = new ScheduledEvent();
}
private void btnGetAScheduledEvent_Click(object sender, EventArgs e)// to return a Scheduled Event by ID
{
try
{
currentEvent.GetEventByID(int.Parse(txtEventID.Text));
}
catch
{
MessageBox.Show("Please Enter an EventID Number");
}
// return ds.tickets.ScheduledEventID;
}
private void btnListEvents_Click(object sender, EventArgs e)
{
//foreach.DictionaryEntry.Equals
SortedList allEvents = currentEvent.ListEventsByDateOfEvent(DateTime.Now);
lstEventsOnDate.Items.Add(allEvents.GetByIndex(0));
//return ds.Tickets.ScheduedEvent:SortedList;
//return ScheduledEventID;
}
}
}