public static ListView PopulateDvdsSearchViewList(ListView l, Media m)
        {
            Media media = m;

            if (media is Dvd)
            {
                Dvd          itemAsDvd = (Dvd)m;
                ListViewItem itm;
                string[]     bk = new String[4];

                bk[0] = itemAsDvd.Id.ToString();
                bk[1] = itemAsDvd.Title;
                bk[2] = itemAsDvd.Director;
                // Is it in stock?
                if (itemAsDvd.IsCheckedOut())
                {
                    bk[3] = "Out of Stock";
                }
                else
                {
                    bk[3] = "In Stock";
                }
                itm = new ListViewItem(bk);
                l.Items.Add(itm);

                return(l);
            }
            else
            {
                return(l);
            }
        }
        public static ListView PopulateMainDvdsViewList(ListView l, List <Media> mediaItems)
        {
            List <Media> mediaFromFile = mediaItems;

            foreach (Media d in mediaFromFile)
            {
                if (d is Dvd)
                {
                    Dvd          itemAsDvd = (Dvd)d;
                    ListViewItem itm;
                    string[]     bk = new String[4];

                    bk[0] = itemAsDvd.Id.ToString();
                    bk[1] = itemAsDvd.Title;
                    bk[2] = itemAsDvd.Director;
                    // Is it in stock?
                    if (itemAsDvd.IsCheckedOut())
                    {
                        bk[3] = "Out of Stock";
                    }
                    else
                    {
                        bk[3] = "In Stock";
                    }
                    itm = new ListViewItem(bk);
                    l.Items.Add(itm);
                }
            }
            return(l);
        }
Esempio n. 3
0
        private void checkoutDvdButton_Click(object sender, EventArgs e)
        {
            if (idTextBox.Text != "" && customerComboBox.SelectedIndex > -1)
            {
                int      dvdId        = Convert.ToInt32(idTextBox.Text);
                Object   selectedItem = customerComboBox.SelectedItem;
                string   dId          = selectedItem.ToString();
                string[] id           = dId.Split(' ');
                int      customerId   = Convert.ToInt32(id[0]);
                foreach (Media d in mediaItems)
                {
                    if (d is Dvd)
                    {
                        Dvd itemAsDvd = (Dvd)d;
                        if (itemAsDvd.Id == dvdId)
                        {
                            if (!itemAsDvd.IsCheckedOut())
                            {
                                itemAsDvd.CheckOut();
                            }
                        }
                    }
                }
                bool success = true;

                if (success)
                {
                    MessageBox.Show(successString);
                    ClearDvdFields();

                    mediaListView.Clear();

                    populateListView();
                    MediaController.PopulateMainDvdsViewList(mediaListView, mediaItems);
                    customerComboBox.SelectedIndex = -1;
                }
                else
                {
                    MessageBox.Show(noSuccessString);
                }
            }
            else
            {
                MessageBox.Show(noSuccessString);
            }
        }
        private void checkInDvdButton_Click(object sender, EventArgs e)
        {
            if (idTextBox.Text != "")
            {
                int dvdId = Convert.ToInt32(idTextBox.Text);

                foreach (Media d in mediaItems)
                {
                    if (d is Dvd)
                    {
                        Dvd itemAsDvd = (Dvd)d;
                        if (itemAsDvd.Id == dvdId)
                        {
                            if (itemAsDvd.IsCheckedOut())
                            {
                                itemAsDvd.CheckIn();
                            }
                        }
                    }
                }

                bool success = true;

                if (success)
                {
                    MessageBox.Show(successString);
                    ClearDvdFields();

                    mediaListView.Clear();

                    populateListView();
                    MediaController.PopulateMainDvdsViewList(mediaListView, mediaItems);
                }
                else
                {
                    MessageBox.Show(noSuccessString + "1");
                }
            }
            else
            {
                MessageBox.Show(noSuccessString);
            }
        }