private void caseTotal_TextChanged(object sender, EventArgs e) // method to accept user input { try { declareNum = Convert.ToDouble(caseTotal.Text); // checks user input for integers, sets input to declareNum this.caseInvalid.Visible = false; // hides invalid input message } catch (System.FormatException) // catches exception if user did not input integers { this.caseInvalid.Visible = true; // display invalid message this.caseInvalid.Text = "Please enter a number."; // sets invalid message text } Duty obj = new Duty(); // creates instance of class Duty.isFine del_obj = new Duty.isFine(obj.calcDuty); // instantiates delegate, calls calcDuty method del_obj(declareNum); this.displayFine.Visible = true; // displays Fine this.displayFine.Text = Duty.getFine().ToString("C2", CultureInfo.CurrentCulture); // calls getFine method, converts to string, and shows text to user }
private void declareSubmit_Click(object sender, EventArgs e) // method for submit button { if (yesCheck) // is user entered duty information { string message = "The total duty fine is " + Duty.getFine().ToString("C2", CultureInfo.CurrentCulture); string title = "Submit"; // message box for user to confirm inputs MessageBoxButtons buttons = MessageBoxButtons.OKCancel; DialogResult selection = MessageBox.Show(message, title, buttons); if (selection == DialogResult.OK) // saves to file { //check if there is a fine, if there is, then formats data for save then saves to file if (Duty.Fine != 0) { string fileLine = ToString(); FileStream writeFile = new FileStream("Fines.txt", FileMode.Append, FileAccess.Write, FileShare.ReadWrite); StreamWriter fileWrite = new StreamWriter(writeFile); fileWrite.WriteLine(fileLine); fileWrite.Flush(); writeFile.Close(); } //ask if user wants to add another entry string assessment = "Would you like to enter another assessment?"; string caption = "Another entry"; DialogResult result1 = MessageBox.Show(assessment, caption, MessageBoxButtons.YesNo); //if user says yes, then opens Form2 to begin new assessment if (result1 == DialogResult.Yes) { this.Hide(); Form2 vForm = new Form2(); vForm.ShowDialog(); this.Close(); } //if user says no, closes this window and opens main menu else { this.Hide(); Form1 wForm = new Form1(); wForm.ShowDialog(); this.Close(); } } else // returns to form { } } else // if user selected No and clicked submit, will not save any data and go back to main page { string message = "Please confirm that you do not need to declare any cases."; string title = "Submit"; // confirms user does not need to declare cases MessageBoxButtons buttons = MessageBoxButtons.OKCancel; DialogResult selection = MessageBox.Show(message, title, buttons); if (selection == DialogResult.OK) // saves to file { this.Hide(); Form1 wForm = new Form1(); wForm.ShowDialog(); this.Close(); } else // returns to form { } } }