using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BLL;
using Model;
using Helper;

namespace WEB
{
    public partial class demo : System.Web.UI.Page
    {
        public List<Music> Result
        {
            get { return ViewState["result"] as List<Music>; }
            set { ViewState["result"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) { return; }
            Response.Write("<script type=\"text/javascript\">\nalert(\"病毒无情人有情,露一下脸行不行?\\n世界上最遥远的距离不是天涯海角,\\n而是我站在你面前,却看不见你的容颜.\");</script>");
            LoadSources();
        }
        /// <summary>
        /// 加载音乐源
        /// </summary>
        public void LoadSources()
        {
            cboSource.Items.Clear();
            foreach (MusicSource item in DAL.Info.Sources)
            {
                if (item.Enabled)
                {
                    cboSource.Items.Add(new ListItem(item.DisplayName, item.Value, item.SuppwotWeb));
                }
            }
            if (cboSource.Items.Count > 0)
            { cboSource.SelectedIndex = 0; }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            MusicBLL bll = new MusicBLL(cboSource.SelectedValue);
            Result = bll.Search(txtWord.Text, 1, 20);
            dgvMusic.DataSource = Music.ModelToTable(Result);
            dgvMusic.DataBind();
        }
        protected void dgvMusic_DataBinding(object sender, EventArgs e)
        {

        }
        protected void dgvMusic_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Music m = Result[Convert.ToInt32(e.CommandArgument)];
            switch (e.CommandName)
            {
                case "play":
                    MusicBLL bll = new MusicBLL(m.Source);
                    bll.GetData(m);
                    Response.Redirect(m.Url);
                    break;
                case "detail":
                    Session["temp"] = m;
                    Response.Redirect("detail.aspx?");
                    break;
                default:
                    break;
            }
        }
    }
}