private void btnAddCharter_Click(object sender, EventArgs e) { //validate customer name input data if (txtCustomer.Text == string.Empty) { MessageBox.Show("Enter Customer Name", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //vaidate yacht type input data if (cboYachtType.SelectedItem == null) { MessageBox.Show("Select a yacht type", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //validate yacht size input data if (lboxYachtSize.SelectedItem == null) { MessageBox.Show("Select a yacht size", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //declare method level variables and assign values string customerName = txtCustomer.Text; string yachtType = cboYachtType.SelectedItem.ToString(); int yachtSize = Convert.ToInt32(lboxYachtSize.SelectedItem); decimal hoursChartered = Convert.ToDecimal(nudHours.Value); Charter aCharter = new Charter(customerName, yachtType, yachtSize, hoursChartered); //instantiates a YatchManager object(one time only; when the first charter is added) if (aCharterManager == null) { aCharterManager = new CharterManager(); } //calls the appropriate method on the YachtManager object to add the charter aCharterManager.AddCharter(customerName, yachtType, yachtSize, hoursChartered); //enables the three menu items within the Display menu allChartersToolStripMenuItem.Enabled = true; numberOfChartersForYachtSIzeToolStripMenuItem.Enabled = true; chartersSummaryToolStripMenuItem.Enabled = true; //disables tools btnAddCharter.Enabled = false; txtCustomer.Enabled = false; nudHours.Enabled = false; lboxYachtSize.Enabled = false; cboYachtType.Text = null; }
//a method to a) instantiate a Charter object and add it to the List <Charter> collection public void AddCharter(string customerName, string yachtType, int yachtSize, decimal hoursChartered) { Charter aCharter = new Charter(customerName, yachtType, yachtSize, hoursChartered); CharterList.Add(aCharter); }