using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace MyTunes.DatabaseBinding
{
    public partial class Songs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["artist"] != null)
                MyTuesSqlDataSource.FilterExpression = "artist_id = '" + Request.Params["artist"] + "'";
            if (Request.Params["album"] != null)
                MyTuesSqlDataSource.FilterExpression = "album_id = '" + Request.Params["album"] + "'";
        }

        protected string LookupArtistName(object artistID)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = new SqlConnection(MyTuesSqlDataSource.ConnectionString);
            cmd.CommandText = "SELECT artist FROM artist WHERE artist_id = '" + artistID.ToString() + "'";
            cmd.Connection.Open();

            return cmd.ExecuteScalar().ToString();
        }

        protected void SongGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Artist")
            {
                int artistID = Convert.ToInt32(e.CommandArgument);
                TransferToArtist(artistID);
            }
        }

        private void TransferToArtist(int artistID)
        {
            Server.Transfer("Albums.aspx?artist=" + artistID.ToString());
        }
    }
}