protected void filetypes_Gridview_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int   rowIndex           = (int)Convert.ChangeType(e.CommandArgument, TypeCode.Int32);
        Label filetypeIDControll = (Label)filetypes_Gridview.Rows[rowIndex].FindControl("FiletypeID");

        #region delete command
        if (e.CommandName == "Delete")
        {
            e.Handled = true;
            try
            {
                FiletypeController fc = new FiletypeController();

                //delete filetype
                fc.DeleteFiletype(int.Parse(filetypeIDControll.Text));

                //reload data
                LoadData();
            }
            catch (Exception ex)
            {
                Message.Text = GetInnerException(ex).Message;
            }
        }
        #endregion
        #region edit command
        else if (e.CommandName == "Edit")
        {
            e.Handled = true;
            ChangeEditMode(true, filetypeIDControll.Text);
        }
        #endregion
    }
    private void ChangeEditMode(bool isUpdating, string filetypeID)
    {
        //change buttons to 'create new artist' layout
        UpdateFyletypeButton.Visible = isUpdating;
        AddFiletypeButton.Visible    = !isUpdating;
        CancelUpdateButton.Visible   = isUpdating;

        //change label's text
        FiletypeInputLabel.Text = isUpdating ? "update Filetype name" : "new Filetype name";

        //claer or change info
        FiletypeInput.Text = "";
        if (isUpdating)
        {
            try
            {
                FiletypeController     fc       = new FiletypeController();
                MusicDatabase_Filetype filetype = fc.fetchFiletypeByID(int.Parse(filetypeID));
                FiletypeInput.Text = filetype.filetype;
            }
            catch (Exception ex)
            {
                Message.Text = "Change edit mode failed. Could not edit filetype. Reason: " + GetInnerException(ex).Message;
            }
        }

        UpdatingFiletypeID.Text = filetypeID;
    }
    protected void AddFiletypeButton_Click(object sender, EventArgs e)
    {
        #region My validation to ensure a name is presented for the filetype
        string name = FiletypeInput.Text.Trim();
        if (string.IsNullOrEmpty(name))
        {
            //have it trigger the invalid validation
            FiletypeInput.Text        = "!!!Invalid_!_Name!!!";
            CompareValidator1.IsValid = false;
            Page.Validate();

            //clar the text i put in
            FiletypeInput.Text = "";
        }
        #endregion
        try
        {
            FiletypeController fc = new FiletypeController();
            int newFtp            = fc.AddFiletype(FiletypeInput.Text);
            LoadData();
            Message.Text = "Filetype " + FiletypeInput.Text + " has been sucessfuly been added with an ID of " + newFtp;
        }
        catch (Exception ex)
        {
            Message.Text = GetInnerException(ex).Message;
        }
    }
    protected void UpdateFyletypeButton_Click(object sender, EventArgs e)
    {
        #region My validation to ensure a name is presented for the filetype
        string name = FiletypeInput.Text.Trim();
        if (string.IsNullOrEmpty(name))
        {
            FiletypeInput.Text        = "!!!Invalid_!_Name!!!";
            CompareValidator1.IsValid = false;
            Page.Validate();
            FiletypeInput.Text = "";
        }
        #endregion

        if (Page.IsValid)
        {
            try
            {
                FiletypeController fc = new FiletypeController();
                fc.UpdateFiletype(int.Parse(UpdatingFiletypeID.Text), FiletypeInput.Text);
                LoadData();
                Message.Text = "Filetype of ID " + UpdatingFiletypeID.Text + " has sucessfuly been renamed as " + FiletypeInput.Text;

                ChangeEditMode(false, "-1");
            }
            catch (Exception ex)
            {
                Message.Text = GetInnerException(ex).Message;
            }
        }
    }
Beispiel #5
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();
        }
    }