Example #1
0
    private void lstMedia_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!isValid(lstMedia.SelectedIndex))
        {
            return; //If it isn't a valid record, ignore the input and return to the user
        }

        //Copy the information from the selected media to each input box.
        clsMedia selectedMedia = (clsMedia)clsLists.media[lstMedia.SelectedIndex - 1];

        txtMediaName.Text         = selectedMedia.Title;
        cboMediaType.Text         = selectedMedia.Type;
        txtMediaCreator.Text      = selectedMedia.Creator;
        txtMediaGenre.Text        = selectedMedia.Genre;
        txtMediaLength.Text       = selectedMedia.Length.ToString();
        txtMediaYear.Text         = selectedMedia.Release.ToString();
        cboPurchase.SelectedIndex = findPurchase(selectedMedia.PurchaseID);

        //Give the user information.
        MessageBox.Show("For more information on this media, click 'More Info.'\n\nTo update this record, change the details and click 'Update'.\n\nTo delete this record, click 'Delete'.");

        //Change the search engine based on the media's type.
        if (selectedMedia.Type.Equals("DVD") ||
            selectedMedia.Type.Equals("Blu-Ray") ||
            selectedMedia.Type.Equals("Video")
            )
        {
            searchEngine = "imdb";
        }

        else if (selectedMedia.Type.Equals("Book"))
        {
            searchEngine = "amazon";
        }

        else if (selectedMedia.Type.Equals("Music") ||
                 selectedMedia.Type.Equals("CD") ||
                 selectedMedia.Type.Equals("Album"))
        {
            searchEngine = "allmusic";
        }

        else if (selectedMedia.Type.Equals("Game"))
        {
            searchEngine = "mobygames";
        }

        else //Especially handy if the user manually entered a different type of media.
        {
            searchEngine = "google";
        }
    }
Example #2
0
    private void btnMediaUpdate_Click(object sender, EventArgs e)
    {
        //See btnMediaAdd_Click for comments.

        string mediaName;
        string mediaType;
        string mediaCreator;
        string mediaGenre;
        double mediaLength;
        int    mediaYear;
        int    purchaseId;

        //Validation below. Using OR arguments to simplify and abbreviate the code.
        if (!clsValidate.validateInput(txtMediaName, out mediaName) ||
            !clsValidate.validateInput(cboMediaType) ||
            !clsValidate.validateInput(txtMediaCreator, out mediaCreator) ||
            !clsValidate.validateInput(txtMediaGenre, out mediaGenre) ||
            !clsValidate.validateInput(txtMediaLength, 0, 5000, out mediaLength) ||
            !clsValidate.validateInput(txtMediaYear, 1500, 2200, out mediaYear) ||
            !clsValidate.validateInput(cboPurchase))
        {
            return;
        }

        if (!isValid(lstMedia.SelectedIndex))
        {
            return; //If it isn't a valid record, ignore the input and return to the user
        }

        mediaType = cboMediaType.Text;
        clsComboBoxItem item = (clsComboBoxItem)cboPurchase.SelectedItem;

        purchaseId = item.ID;

        clsMedia selectedMedia = (clsMedia)clsLists.media[lstMedia.SelectedIndex - 1];

        string sql = "UPDATE Media SET "
                     + "Title = " + clsSQL.ToSql(mediaName) + ", "
                     + "Type = " + clsSQL.ToSql(mediaType) + ", "
                     + "Creator = " + clsSQL.ToSql(mediaCreator) + ", "
                     + "Genre = " + clsSQL.ToSql(mediaGenre) + ", "
                     + "Length = " + clsSQL.ToSql(mediaLength) + ", "
                     + "ReleaseYear = " + clsSQL.ToSql(mediaYear) + ", "
                     + "PurchaseID = " + clsSQL.ToSql(purchaseId) + " "
                     + "WHERE MediaID = " + selectedMedia.ID;

        clsSQL.nonQuery(sql);
        MessageBox.Show("Updated record.");
        refreshMedia();
    }
Example #3
0
    private void btnMediaDelete_Click(object sender, EventArgs e)
    {
        if (!isValid(lstMedia.SelectedIndex))
        {
            return; //If it isn't a valid record, ignore the input and return to the user
        }

        clsMedia selectedMedia = (clsMedia)clsLists.media[lstMedia.SelectedIndex - 1];

        string sql = "DELETE FROM Media WHERE MediaID = " + selectedMedia.ID + ";";

        clsSQL.nonQuery(sql);
        MessageBox.Show("Deleted record.");
        refreshMedia();
    }
Example #4
0
    public static ArrayList queryMedia(string sql)
    {
        ArrayList media = new ArrayList();

        try
        {
            openDatabaseConnection();
            mdb.Open();
            OleDbCommand cmd;
            cmd = new OleDbCommand(sql, mdb);
            OleDbDataReader rdr;
            rdr = cmd.ExecuteReader();
            while (rdr.Read() == true)
            {
                clsMedia newMedia = new clsMedia((int)rdr["MediaID"],
                                                 (string)rdr["Title"],
                                                 (string)rdr["Type"],
                                                 (string)rdr["Creator"],
                                                 (string)rdr["Genre"],
                                                 (double)rdr["Length"],
                                                 (int)rdr["ReleaseYear"],
                                                 (int)rdr["PurchaseID"]);
                media.Add(newMedia);
            }
            rdr.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("There was an unexpected problem reading from the DB: " +
                            ex.Message);
        }
        finally
        {
            closeDatabaseConnection();
        }
        return(media);
    }
Example #5
0
    //Opens the user's default browser to a search engine page relevant to their selected media.
    private void btnMediaMoreInfo_Click(object sender, EventArgs e)
    {
        if (!isValid(lstMedia.SelectedIndex)) //Check the selected item's validity.
        {
            MessageBox.Show("Please select media from the list box in order to retrieve information.");
            return;
        }

        clsMedia media  = (clsMedia)clsLists.media[lstMedia.SelectedIndex - 1];
        string   search = media.Title.Replace(' ', '+');

        if (searchEngine.Equals("amazon"))
        {
            System.Diagnostics.Process.Start("http://www.amazon.com/s/url=search-alias%3Daps&field-keywords=" + search);
        }

        else if (searchEngine.Equals("imdb"))
        {
            System.Diagnostics.Process.Start("http://www.imdb.com/find?ref_=nv_sr_fn&q=" + search);
        }

        else if (searchEngine.Equals("allmusic"))
        {
            System.Diagnostics.Process.Start("http://www.allmusic.com/search/all/" + search);
        }

        else if (searchEngine.Equals("mobygames"))
        {
            System.Diagnostics.Process.Start("http://www.mobygames.com/search/quick?q=" + search);
        }

        else
        {
            System.Diagnostics.Process.Start("https://www.google.com/?q=" + search);
        }
    }