//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; }
/* * Method name: IsValidLastName * Version: 1.1.1 * Author: Md Ahsanul Hoque #Description: Check lastName validation * Inputs: Parameters- lName * Outputs: flag as boolean * Dependencies: N/A * Return value: flag * Change History: 20190930 By Md Ahsanul Hoque */ public bool IsValidLastName(string lName) { bool flag = false; this.ErrorText = ""; if (!SalesPersonUtility.IsEmpty(lName)) { flag = true; } else { this.ErrorText = "Last name cannot be empty"; } return(flag); }
/* * Method name: CheckInsuranceAmount * Version: 1.1.1 * Author: Md Ahsanul Hoque #Description: Check validatin for appropriate insurance amount * Inputs: Parameters- insuranceAmount * Outputs: flag as boolean * Dependencies: N/A * Return value: flag * Change History: 20190930 By Md Ahsanul Hoque */ public bool CheckInsuranceAmountAmount(string insuranceAmount) { bool flag = false; this.ErrorText = ""; if (Double.TryParse(insuranceAmount, out double amount)) { this.InsuranceAmount = amount; flag = true; } else if (SalesPersonUtility.IsEmpty(insuranceAmount)) { this.ErrorText = "Amount cannot be empty"; } else { this.ErrorText = ErrorMessage("Enter numeric value"); } this.IsValidInsuranceAmount = flag; return(flag); }