30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

818 Files and Streams Chapter 17<br />

59 Hide()<br />

60 ClearTextBoxes()<br />

61 showPreviousWindow()<br />

62 End Sub ' cmdSave_Click<br />

63<br />

64 ' insert record in file at position specified by accountNumber<br />

65 Private Sub InsertRecord(ByVal record As CRandomAccessRecord)<br />

66<br />

67 ' s<strong>to</strong>re TextBox values in String array<br />

68 Dim textBoxValues As String() = GetTextBoxValues()<br />

69<br />

70 ' s<strong>to</strong>re TextBox account field<br />

71 Dim accountNumber As Integer = _<br />

72 Convert.ToInt32(textBoxValues(TextBoxIndices.ACCOUNT))<br />

73<br />

74 ' notify user and return if record account is not empty<br />

75 If record.Account 0 Then<br />

76 MessageBox.Show( _<br />

77 "Record Already Exists or Invalid Number", "Error", _<br />

78 MessageBoxBut<strong>to</strong>ns.OK, MessageBoxIcon.Error)<br />

79<br />

80 Return<br />

81 End If<br />

82<br />

83 ' s<strong>to</strong>re values in record<br />

84 record.Account = accountNumber<br />

85 record.FirstName = textBoxValues(TextBoxIndices.FIRST)<br />

86 record.LastName = textBoxValues(TextBoxIndices.LAST)<br />

87 record.Balance = Convert.ToDouble( _<br />

88 textBoxValues(TextBoxIndices.BALANCE))<br />

89<br />

90 ' add record <strong>to</strong> file<br />

91 Try<br />

92<br />

93 If (transactionProxy.AddRecord( _<br />

94 record, accountNumber) = False ) Then<br />

95<br />

96 Return ' if error<br />

97 End If<br />

98<br />

99 ' notify user if error occurs in parameter mismatch<br />

100 Catch formattingException As FormatException<br />

101 MessageBox.Show("Invalid Balance", "Error", _<br />

102 MessageBoxBut<strong>to</strong>ns.OK, MessageBoxIcon.Error)<br />

103<br />

104 End Try<br />

105<br />

106 MessageBox.Show("Record Created", "Success", _<br />

107 MessageBoxBut<strong>to</strong>ns.OK, MessageBoxIcon.Information)<br />

108 End Sub ' InsertRecord<br />

109<br />

110 End Class ' FrmNewDialog<br />

Fig. 17.21 FrmNewDialog class enables users <strong>to</strong> create records in transactionprocessor<br />

case study (part 3 of 4).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!