ATM application

XML file contains Account data - I need to read/write to the XML file

Page 1 of 1

1 Replies - 10119 Views - Last Post: 25 April 2010 - 10:22 AM Rate Topic: -----

#1 Rex13   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-October 09

ATM application

Posted 25 April 2010 - 09:59 AM


Here's my problem...

I was given an assignment to write a very simple ATM interface that will check for a user's PIN entry against an XML file.

I am having a lot of difficulty with using the collection (retrieved from XML and put into a: List(Of )) to get the user's PIN from a text box and compare it to 1 of 5 accounts found within my xml file.

Here's what I have so far:

An account class

Public Class Account

    Private m_AccountNumber As String
    Private m_AccountFirstName As String
    Private m_AccountLastName As String
    Private m_PIN As String
    Private m_AccountBalance As Decimal

    Public Sub New()

    End Sub

    Public Property AccountNumber() As String
            Return m_AccountNumber
        End Get
        Set(ByVal value As String)
            m_AccountNumber = value
        End Set
    End Property

    Public Property AccountFirstName() As String
            Return m_AccountFirstName
        End Get
        Set(ByVal value As String)
            m_AccountFirstName = value
        End Set
    End Property

    Public Property AccountLastName() As String
            Return m_AccountLastName
        End Get
        Set(ByVal value As String)
            m_AccountLastName = value
        End Set
    End Property

    Public Property PIN() As String
            Return m_PIN
        End Get
        Set(ByVal value As String)
            m_PIN = value
        End Set
    End Property

    Public Property AccountBalance() As Decimal
            Return m_AccountBalance
        End Get
        Set(ByVal value As Decimal)
            m_AccountBalance = value
        End Set
    End Property

'I just included this to see if the XML data was being read correctly and it's posted to a listbox
    Public Function DisplayText(ByVal sep As String) As String
        Dim text As String = AccountFirstName & " " & PIN & " " & AccountNumber & " " & AccountBalance
        Return text
    End Function
End Class 

>>then I have my login form code:
Public Class frmLogin

    'not sure if all this is needed
    Public Account As Account
    Dim accounts As New List(Of Account)
    Dim cardNumber As String

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        accounts = AccountDB.ReadAccountData()

    End Sub

    'procedure just used to see if the XML data is being read correctly
    Private Sub FillListBoxWithAccountData()
        For Each a As Account In accounts
            ListBox1.Items.Add(a.DisplayText(" "))
    End Sub

    Private Sub selectCard_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
                Handles btnFrank.Click, btnJoe.Click, btnLasky.Click, btnGiada.Click, btnSuzie.Click
        Dim cardNumber As String

        'here the user clicks on a button to get account data -this simulates the user
        'sliding an atm card in the machine.  The account number is automatically populated for them.
        Select Case True
            Case sender Is btnSuzie
                txtAccountNumber.Text = "0987"
            Case sender Is btnBob
                txtAccountNumber.Text = "1234"
            Case sender Is btnJoe
                txtAccountNumber.Text = "1323"
            Case sender Is btnRich
                txtAccountNumber.Text = "2222"
            Case sender Is btnEllen
                txtAccountNumber.Text = "5432"
        End Select
        cardNumber = txtAccountNumber.Text

        CardsNotVisible() 'prohibits user from selecting another atm card 

    End Sub

    Private Function IsValidLogin() As Boolean
        Return Validation.IsPresentMasked(txtPIN) AndAlso _
               Validation.IsCorrectLengthMasked(txtPIN, 4)
    End Function

    Private Sub CardsNotVisible()
        btnSuzie.Visible = False
        btnLasky.Visible = False
        btnJoe.Visible = False
        btnFrank.Visible = False
        btnGiada.Visible = False

    End Sub

    Private Sub CardsVisible()
        btnSuzie.Visible = True
        btnLasky.Visible = True
        btnJoe.Visible = True
        btnFrank.Visible = True
        btnGiada.Visible = True
    End Sub

    'I have tried everything I can think of here -this is my latest mess
    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
        If Account.PIN = txtPIN.Text Then

            MessageBox.Show("Login Successful!", "Login Attempt")
            'launch banking option menu

            MessageBox.Show("Login Incorrect" & vbCrLf & "Please enter your correct PIN", "Login Attempt")
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    End Sub
End Class

>>here's my XML IO class, which seems to be working just fine:
Imports System.Xml

Public Class AccountDB

    Private Const Path As String = "..\..\Accounts.xml"

    Public Shared Function ReadAccountData() As List(Of Account)
        Dim accounts As New List(Of Account)
        Dim settings As New XmlReaderSettings
        settings.IgnoreWhitespace = True
        settings.IgnoreComments = True

        Dim xmlIn As XmlReader = XmlReader.Create(Path, settings)
        If xmlIn.ReadToDescendant("Account") Then
                Dim account As New Account
                account.AccountNumber = xmlIn("AccountNumber")
                account.PIN = xmlIn.ReadElementContentAsString
                account.AccountFirstName = xmlIn.ReadElementContentAsString
                account.AccountLastName = xmlIn.ReadElementContentAsString
                account.AccountBalance = xmlIn.ReadElementContentAsDecimal
                accounts.Add(account)   'populate the accounts array
            Loop While xmlIn.ReadToNextSibling("Account")
        End If

        Return accounts
    End Function

    Public Shared Sub SaveAccountData(ByVal accounts As List(Of Account))

        Dim settings As New XmlWriterSettings
        settings.Indent = True
        settings.IndentChars = "    "

        Dim xmlOut As XmlWriter = XmlWriter.Create(Path, settings)

        For Each account As Account In accounts
            xmlOut.WriteAttributeString("AccountNumber", account.AccountNumber.ToString)
            xmlOut.WriteElementString("PIN", account.PIN.ToString)
            xmlOut.WriteElementString("AccountFirstName", account.AccountFirstName)
            xmlOut.WriteElementString("AccountLastName", account.AccountLastName)
            xmlOut.WriteElementString("AccountBalance", account.AccountBalance.ToString)

    End Sub

>>and finally, here's my XML file:
<?xml version="1.0" encoding="utf-8" ?>
  <Account AccountNumber ="0987">
  <Account AccountNumber ="1234">
  <Account AccountNumber ="1323">
  <Account AccountNumber ="2222">
  <Account AccountNumber ="5432">

I guess my major problem is finding out how to use the collection to find the correct account, compare the PINs to validate a login and from there I can go about launching another form...I need some serious help may be something simple -but I'm a newbie and the books I've referenced are just not helping me with this little problem.

Thanks in advance!

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: ATM application

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ATM application

Posted 25 April 2010 - 10:22 AM

This is VB.NET code, not VB6. Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1