//instatiate charter object public void AddCharter(string customerName, string yachtType, int yachtSize, decimal charterHours) { Charter aCharter = new Charter(customerName, yachtType, yachtSize, charterHours); CharterList.Add(aCharter); }
private void btnAddCharter_Click(object sender, EventArgs e) { // declare local (i.e., method-level) variables string customerName, yachtType; int yachtSize; decimal charterHours; Charter aCharter; //errors for missing inputs if (txtCustomer.Text == string.Empty) { MessageBox.Show("Enter a customer please!", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboYT.Text == string.Empty) { MessageBox.Show("Enter a yacht please!", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboYS.Text == string.Empty) { MessageBox.Show("Enter a yacht size please!", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (nudCH.Value < 0) { MessageBox.Show("Enter charter hours please!", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // assign input to variables customerName = txtCustomer.Text; yachtType = cboYT.Text; yachtSize = Convert.ToInt32(cboYS.Text); charterHours = Convert.ToDecimal(nudCH.Value); //instatiate a charter object aCharter = new Charter(customerName, yachtType, yachtSize, charterHours); //instatiate aCharterManager if (aCharterManager is null) { aCharterManager = new CharterManager(); } //call addcharter method aCharterManager.AddCharter(aCharter); //enable menu tools allChartersToolStripMenuItem.Enabled = true; numberOfChartersToolStripMenuItem.Enabled = true; chartersSummaryToolStripMenuItem.Enabled = true; //disable object inputs txtCustomer.Enabled = false; cboYT.Enabled = false; cboYS.Enabled = false; nudCH.Enabled = false; }
//add charter object to the CharterList collection public void AddCharter(Charter aCharter) { CharterList.Add(aCharter); }