//Clear button even hanler clears the data as specified private void BtnClear_Click(object sender, EventArgs e) { try { if (!SalesPersonUtility.IsEmpty(aSalesPerson.FirstName) && !SalesPersonUtility.IsEmpty(aSalesPerson.LastName) && SalesPersonUtility.IsSalesPersonFound(aSalesPerson, salesPersonRepo)) { salesPersonRepo.Remove(aSalesPerson); aSalesPerson.FirstName = ""; aSalesPerson.LastName = ""; countTotalPolicies--; individualSalesPersonInfoCleared = true; } else { individualSalesPersonInfoCleared = false; } textBoxFirstName.Text = ""; textBoxLastName.Text = ""; textBoxInsuranceAmount.Text = ""; textBoxLastName.Focus(); } catch (Exception ex) { MessageBox.Show("There's nothing to clear off.."); } }
//Clear button event handler delete all information from the salePersonList repository private void BtnClearAll_Click(object sender, EventArgs e) { DialogResult responseDialogResult; string outputString = ""; if (salesPersonRepo.Count > 0) { outputString = aSalesPerson.Display(); richTextBoxForResult.Text = outputString; if (individualSalesPersonInfoCleared) { outputString = "Current sales person's information removed or cleared"; } else { //Perform operation if the properties have appropriate values and exists in the repo if (!SalesPersonUtility.IsEmpty(aSalesPerson.FirstName) && !SalesPersonUtility.IsEmpty(aSalesPerson.LastName) && SalesPersonUtility.IsSalesPersonFound(aSalesPerson, salesPersonRepo)) { //Grab individual info outputString = aSalesPerson.Display(); richTextBoxForResult.Text = outputString; } else { outputString = "Current sales person's information removed or cleared"; } } outputString = DisplaySummary(outputString); responseDialogResult = MessageBox.Show(outputString, "Life Insurance Applicaiton summary", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (responseDialogResult == DialogResult.Yes) { salesPersonRepo.Clear(); countTotalPolicies = 0; richTextBoxForResult.Clear(); textBoxFirstName.Clear(); textBoxLastName.Clear(); textBoxInsuranceAmount.Clear(); textBoxLastName.Focus(); } } else { MessageBox.Show("There's nothing to clear"); } Clear_Error_Message(); individualSalesPersonInfoCleared = false; }
//Show the summary in the message box private void BtnSummary_Click(object sender, EventArgs e) { string outputString = ""; //check data exists in the repo if (salesPersonRepo.Count > 0) { //if individual information is not cleared the show the appropriate result to messagebox if (individualSalesPersonInfoCleared) { outputString = "Current sales person's information removed or cleared"; } else { //Check current sales person exists or not if (!SalesPersonUtility.IsEmpty(aSalesPerson.FirstName) && !SalesPersonUtility.IsEmpty(aSalesPerson.LastName) && SalesPersonUtility.IsSalesPersonFound(aSalesPerson, salesPersonRepo)) { outputString = ""; outputString = aSalesPerson.Display(); richTextBoxForResult.Text = outputString; } else { outputString = "Current sales person's information removed or cleared"; } } //grab and hold the value from displaySummary and also pass outputString extracted from above logic outputString = DisplaySummary(outputString); MessageBox.Show(outputString); richTextBoxForResult.Text = outputString; } //if no data found in the repo display appropriate message else { richTextBoxForResult.Text = "No data found to display"; MessageBox.Show("No data found to display"); } Clear_Error_Message(); individualSalesPersonInfoCleared = false; }