-
Dec 27th, 2013, 07:29 AM
#1
Thread Starter
Member
Passing a groupbox and its controls to another class
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. 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.
Code:
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>;
}
//properties
public int CorpID
{
get
{
return corpID;
}
set
{
corpID = value;
}
}
[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
Code:
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;
}
}
}
}
Any help or suggestions will be appreciated. Thanks in advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|