Exemple #1
0
        }//btnWithdraw

        private void btnPurchase_Click(object sender, EventArgs e)
        {
            if (cacc != null && lstDisplaySongs.SelectedIndex != -1)
            {
                if (cacc.Balance >= ms.songs[lstDisplaySongs.SelectedIndex].SongPrice)
                {
                    ms.purchaseSongs(cacc, lstDisplaySongs);
                    lblAccountDetails.Text = cacc.viewAccountDetails();

                    MediaNode node = new MediaNode(ms.songs[lstDisplaySongs.SelectedIndex].SongName, ms.songs[lstDisplaySongs.SelectedIndex].SongPrice);
                    ma = new MediaAccount(node);
                    ma.InsertAtFront(ma, node);

                    IIterator it = ma.createIterator();
                    while (it.hasMore())
                    {
                        it.getNext(lstPurchasedSongs);
                    }
                }
                else
                {
                    MessageBox.Show("Please ensure that you have enough money in your current account before purchasing a song", "Error!");
                }
            }
            else if (sacc != null && lstDisplaySongs.SelectedIndex != -1)
            {
                if (sacc.Balance >= ms.songs[lstDisplaySongs.SelectedIndex].SongPrice)
                {
                    ms.purchaseSongs(sacc, lstDisplaySongs);
                    lblAccountDetails.Text = sacc.viewAccountDetails();

                    MediaNode node = new MediaNode(ms.songs[lstDisplaySongs.SelectedIndex].SongName, ms.songs[lstDisplaySongs.SelectedIndex].SongPrice);
                    ma = new MediaAccount(node);
                    ma.InsertAtFront(ma, node);

                    IIterator it = ma.createIterator();
                    while (it.hasMore())
                    {
                        it.getNext(lstPurchasedSongs);
                    }
                }
                else
                {
                    MessageBox.Show("Please ensure that you have enough money in your savings account before purchasing a song", "Error!");
                }
            }
            else
            {
                MessageBox.Show("Please ensure that you have selected a song from the list before trying to purchase", "Error!");
            }
            clearText();
        }//btnPurchase
        public void InsertAtFront(MediaAccount dList, MediaNode newData)
        {
            MediaNode newNode = new MediaNode(newData.SongName, newData.SongPrice);

            newNode.Next = dList.head;
            newNode.Prev = null;
            if (dList.head != null)
            {
                dList.head.Prev = newNode;
                size++;
            }
            dList.head = newNode;
        }
 public MediaIterator(MediaAccount collection)
 {
     this.collection = collection;
     size            = collection.Size;
     current         = collection.Head;
 }