private void btnNext_Click(object sender, EventArgs e) { try { RecordSerrializable record = (RecordSerrializable)reader.Deserialize(input); string[] values = new string[] { record.Account.ToString(), record.FirstName.ToString(), record.LastName.ToString(), record.Balance.ToString() }; if (record.Protection == true) { checkBoxProtection.Checked = true; } else { checkBoxProtection.Checked = false; } SetTextBoxValues(values); } // end try catch (SerializationException) { input.Close(); // close FileStream if no Records in file btnLoad.Enabled = true; // enable Open File button //btnNext.Enabled = false; // disable Next Record button ClearTextBoxes(); MessageBox.Show("Error Reading from File", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // end catch }
private void btnEnter_Click(object sender, EventArgs e) { // store TextBox values string array string[] values = GetTextBoxValues(); // Record containing TextBox values to serialize RecordSerrializable record = new RecordSerrializable(); // determine whether TextBox account field is empty if (values[(int)TextBoxIndices.ACCOUNT] != "") { // store TextBox values in Record and serialize Record try { // get account number value from TextBox int accountNumber = Int32.Parse( values[(int)TextBoxIndices.ACCOUNT]); // determine whether accountNumber is valid if (accountNumber > 0) { // store TextBox fields in Record record.Account = accountNumber; record.FirstName = values[(int)TextBoxIndices.FIRST]; record.LastName = values[(int)TextBoxIndices.LAST]; record.Balance = Decimal.Parse( values[(int)TextBoxIndices.BALANCE]); if (checkBoxProtection.Checked) { record.Protection = true; } else { record.Protection = false; } // write Record to file, fields separated by commas formatter.Serialize(output, record); } // end if else { // notify user if invalid account number MessageBox.Show("Invalid Account Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // end else } // end try // notify user if error occurs in serialization catch (SerializationException) { MessageBox.Show("Error Writing to File", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // end catch // notify user if error occurs regarding parameter format catch (FormatException) { MessageBox.Show("Invalid Format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // end catch } // end if ClearTextBoxes(); }