コード例 #1
0
    /// <summary>
    /// this is the effect of pressing the 'add rating' button.
    /// it adds the ddl rating as a reference to the song that is being updated
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AddRatingButton_Click(object sender, EventArgs e)
    {
        int songID = int.Parse(EditingSongID.Text);
        RatingToSongController rtos = new RatingToSongController();
        int ratingID = int.Parse(RatingToAddDDL.SelectedValue);

        if (songID != -1)
        {
            try
            {
                if (songID == -1)
                {
                    Message.Text = "Song not yet created; pleas create the song before adding Ratings(s)";
                }
                else if (ratingID == 0)
                {
                    Message.Text = "No Rating has been selected; please select a Rating to add";
                }
                else if (rtos.CheckRefExists(songID, ratingID))
                {
                    Message.Text = "Rating has already been added; please select a different Rating to add";
                }
                else
                {
                    rtos.CreateReference(songID, ratingID);
                    LoadEditData();
                    Message.Text = "The Rating '" + RatingToAddDDL.SelectedItem.ToString() + "' has been sucessfuly added";

                    //reset the value to 'select...'
                    RatingToAddDDL.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                Message.Text = GetInerException(ex).Message;
            }
        }
        else
        {
            Message.Text = "Song not yet created; pleas create the song before adding Rating(s)";
        }
    }
コード例 #2
0
    /// <summary>
    /// this is for removing and viewing raitings of the song that is currently being edited
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void EditingRatings_GridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            e.Handled = true;
            int   index = Convert.ToInt32(e.CommandArgument);
            Label ratingIDController    = (Label)EditingRatings_GridView.Rows[index].FindControl("EditingRatingID");
            Label ratingNameController  = (Label)EditingRatings_GridView.Rows[index].FindControl("EditingRating");
            RatingToSongController rtos = new RatingToSongController();
            try
            {
                rtos.RemoveReference(int.Parse(EditingSongID.Text), int.Parse(ratingIDController.Text));
                LoadEditData();

                Message.Text = "The Rating '" + ratingNameController.Text + "' has been sucessfuly removed";
            }
            catch (Exception ex)
            {
                Message.Text = GetInerException(ex).ToString();
            }
        }
    }
コード例 #3
0
    private void LoadEditData()
    {
        ArtistToSongController atos = new ArtistToSongController();
        FiletypeController     fc   = new FiletypeController();
        GenreToSongController  gtos = new GenreToSongController();
        RatingToSongController rtos = new RatingToSongController();
        SongController         sc   = new SongController();

        try
        {
            //reset the ddl so that its on the first one which is 'Select...'
            //manualy adding all the rows so that Select... is the first one and Editing FiletypeDDL doesn't get stacking data
            DataTable t = new DataTable();
            t.Columns.Add("FiletypeID");
            t.Columns.Add("Filetype");
            t.Rows.Add(new string[] { "0", "Select..." });
            foreach (DataRow dr in fc.GetFiletypes().Rows)
            {
                t.Rows.Add(new string[] { dr.Field <int>("FiletypeID").ToString(), dr.Field <string>("Filetype") });
            }

            EditingFiletypeDDL.DataSource     = t;
            EditingFiletypeDDL.DataTextField  = "Filetype";
            EditingFiletypeDDL.DataValueField = "FiletypeID";
            EditingFiletypeDDL.DataBind();

            //no song selected
            if (EditingSongID.Text == "-1")
            {
                //clear the song information
                EditingSongName.Text = "";

                //make sure its on 'select'
                EditingFiletypeDDL.SelectedIndex = 0;

                //make sure that all of the editing gridviews show emty if there aren't any
                EditingArtists_GridView.DataBind();
                EditingRatings_GridView.DataBind();
                EditingGenres_GridView.DataBind();

                //determine which button will be used on the edit/add tab
                Update_SongNameAndFiletype.Visible = false;
                Create_NewSong.Visible             = true;
            }
            //a song is being edited
            else
            {
                int       songid = int.Parse(EditingSongID.Text);
                DataTable songT  = sc.fetchSong(songid);
                EditingSongName.Text = songT.Rows[0].Field <string>("SongName");
                //make sure its on the right value
                EditingFiletypeDDL.SelectedValue = songT.Rows[0].Field <int>("FiletypeID").ToString();

                #region Load and Bind Artists
                DataTable artistT = atos.GetArtistToSongInfo(songid);
                EditingArtists_GridView.DataSource = artistT;
                EditingArtists_GridView.DataBind();
                #endregion

                #region Load and Bind Ratings
                DataTable ratingT = rtos.GetRatingToSongInfo(songid);
                EditingRatings_GridView.DataSource = ratingT;
                EditingRatings_GridView.DataBind();
                #endregion

                #region Load and Bind Genres

                DataTable genreT = gtos.GetGenreToSongInfo(songid);
                EditingGenres_GridView.DataSource = genreT;
                EditingGenres_GridView.DataBind();
                #endregion

                //set the update button to being visable, and turn the add/create button invisable
                Update_SongNameAndFiletype.Visible = true;
                Create_NewSong.Visible             = false;
            }
            EditingFiletypeDDL.DataBind();
        }
        catch (Exception ex)
        {
            Message.Text = GetInerException(ex).ToString();
        }
    }