예제 #1
0
 public MediaNode(string songName, double songPrice)
 {
     this.songName  = songName;
     this.songPrice = songPrice;
     prev           = null;
     next           = null;
 }
예제 #2
0
        public Object getNext(ListBox list)
        {
            MediaNode oldCurrent = current;

            current = current.Prev;
            list.Items.Add(oldCurrent.SongName);
            return(list);
        }
예제 #3
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
예제 #4
0
        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;
        }
예제 #5
0
 public MediaAccount(MediaNode data)
 {
     this.data = data;
     head      = null;
     size      = 0;
 }
예제 #6
0
 public MediaIterator(MediaAccount collection)
 {
     this.collection = collection;
     size            = collection.Size;
     current         = collection.Head;
 }