lovekeiiiy
Member
- Joined
- Dec 29, 2013
- Messages
- 12
- Programming Experience
- Beginner
I'm working on trying to understand classes better. I didn't feel like I got a good grasp of it in my programming class last semester. So, I'm using a textbox for a different class (Visual Basic) for the no-nothing assignments design to reinforce the lesson.
Anyway, I'm a bit stuck. I tried doing a search on the web, and just couldn't find the answer to get me over the hump. I also tried asking on another forum, not specifically focused on C# (Linky), but did not get a response. The assignment is to create some conference registration form. Form design was given. Also said to use a three-tier program design. There is a checkbox for preconferences, when checked shows three conference choices (each is course is the same fee).
What I did was create classes for the form, validating data, and database. What I was thinking I could do was pass the groupbox and the controls within it (three radio buttons). Then I could check to make sure the user picks one (passing to validation class), and get the radio button text to write to the text delimited file (passing to the database class). I've passed the groupbox, I think, but it's not letting me access the controls.
Here's the code to show what I was doing. I may have included some extra, unneeded information. I just wasn't sure.
I've create a class to create an object to hold customer information.
the form
I have worked on this more, working the database class/tier, and I'm getting, an StackOverFlowException was unhandled error. I figured this error is tied to my issue of not being about the pass which radio button selected and text into ConferenceRegistration class. If I code out the ConferenceName line, it works fine.
Any help or suggestions will be appreciated. Thanks in advance.
Anyway, I'm a bit stuck. I tried doing a search on the web, and just couldn't find the answer to get me over the hump. I also tried asking on another forum, not specifically focused on C# (Linky), but did not get a response. The assignment is to create some conference registration form. Form design was given. Also said to use a three-tier program design. There is a checkbox for preconferences, when checked shows three conference choices (each is course is the same fee).
What I did was create classes for the form, validating data, and database. What I was thinking I could do was pass the groupbox and the controls within it (three radio buttons). Then I could check to make sure the user picks one (passing to validation class), and get the radio button text to write to the text delimited file (passing to the database class). I've passed the groupbox, I think, but it's not letting me access the controls.
Here's the code to show what I was doing. I may have included some extra, unneeded information. I just wasn't sure.
I've create a class to create an object to hold customer information.
C#:
namespace NetworkConferenceRegistration
{
public class ConferenceRegistraction
{
//fields
private int corpID;
private string firstName;
private string lastName;
private int days;
//private string conferenceName;
[removed code]
//constructor
public ConferenceRegistraction(int intCorpID, string strFirstName, string strLastName, int intDays, GroupBox grpCourses)
{
corpID = intCorpID;
firstName = strFirstName;
lastName = strLastName;
days = intDays;
conferenceName = grpCourses.Controls.OfType<RadioButton>;
}
public ConferenceRegistraction(int intCorpID, string strFirstName, string strLastName, int intDays, RadioButton radCourse)
{
corpID = intCorpID;
firstName = strFirstName;
lastName = strLastName;
days = intDays;
conferenceName = radCourse.Text;
}
//properties
public int CorpID
{
get
{
return corpID;
}
set
{
corpID = value;
}
}
public string ConferenceName
{
get
{
return ConferenceName;
}
}
[removed code]
public string ConferenceName //readonly. don't think i'll need to set which radio button to use or change its text property
{
get
{
return ConferenceName;
}
}
//calculate conferense cost
public decimal GetCost(CheckBox chkPreconference)
{
//local variables
const decimal decConferenceRatePerDay = 350; //conference rate per day
decimal decConferenceCost = 0; //total cost of conference
//calculate the cost based on number of days
decConferenceCost = decConferenceRatePerDay * Days;
//add preconference cost
if (chkPreconference.Checked == true)
{
decConferenceCost += 675;
}
return decConferenceCost;
}
}
}
the form
C#:
namespace NetworkConferenceRegistration
{
public partial class frmNetworkRegistraction : Form
{
[code removed]
//get user information and calculate costs
private void btnCalculateCosts_Click(object sender, EventArgs e)
{
//check to see if user data is valid
if (txtCorpID.MaskFull & //did user input ID number
Validation.IsDataEntered(txtFirstName, "First Name", ref strErrorMessage) & //did user enter first name
Validation.IsDataEntered(txtLastName, "Last Name", ref strErrorMessage) & //did user enter last name
Validation.IsDataEntered(txtNumberOfDays, "Number of Days", ref strErrorMessage) & //did user enter number of days
Validation.IsDataWithinRange(txtNumberOfDays, 1, 4, "Number of Days", ref strErrorMessage) == true) //is number of days four or less
{
//create object and instantation
ConferenceRegistraction objNewConferenceRegistraction = new ConferenceRegistraction(Convert.ToInt32(txtCorpID.Text.Trim()), txtFirstName.Text.Trim(), txtLastName.Text.Trim(), Convert.ToInt16(txtNumberOfDays.Text.Trim()));
lblTotalCosts.Text = objNewConferenceRegistraction.GetCost(chkPreConferenceCourse).ToString();
}
else
{
MessageBox.Show(strErrorMessage, "Input Error");
//reset error message
strErrorMessage = string.Empty;
}
}
[code removed]
//change form to display preconferences course selection or not
private void chkPreConferenceCourse_CheckedChanged(object sender, EventArgs e)
{
if (this.grpCourses.Visible == false)
{
this.grpCourses.Visible = true;
}
else
{
this.grpCourses.Visible = false;
}
}
}
}
I have worked on this more, working the database class/tier, and I'm getting, an StackOverFlowException was unhandled error. I figured this error is tied to my issue of not being about the pass which radio button selected and text into ConferenceRegistration class. If I code out the ConferenceName line, it works fine.
C#:
namespace NetworkConferenceRegistration{
public static class Database
{
//class level variables
private static string strDirectory = Application.StartupPath;
private static string strFileName = "/ConfereenceRegistration.txt";
public static void Save(ConferenceRegistraction conferenceInformation)
{
//create output stream and file
StreamWriter outputInformation = new StreamWriter(new FileStream(strDirectory + strFileName, FileMode.Create, FileAccess.Write));
outputInformation.Write(conferenceInformation.CorpID + ",");
outputInformation.Write(conferenceInformation.FirstName + ",");
outputInformation.Write(conferenceInformation.LastName + ",");
outputInformation.Write(conferenceInformation.Days + ",");
outputInformation.Write(conferenceInformation.ConferenceName + "\n");
//close file
outputInformation.Close();
}
}
}
Any help or suggestions will be appreciated. Thanks in advance.