using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Helper;
using Model;
using BLL;
using DAL;
namespace WinForm原生_美化
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            dgvMusic.AutoGenerateColumns = false;
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
            foreach (MusicSource item in DAL.Info.Sources)
            {
                if (item.Enabled && item.SupportLocal)
                { cboSource.Items.Add(item); }
            }
            cboSource.SelectedIndex = 0;
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                MusicSource source = (MusicSource)cboSource.SelectedItem;
                MusicBLL bll = new MusicBLL(source.Value);
                dgvMusic.DataSource = Music.ModelToTable(bll.Search(txtWord.Text, 1, 30));
                //lblStatus.Text = "搜索完毕";
            }
            catch (Exception ex)
            {
               // lblStatus.Text = ex.Message;
            }
        }
        private void dgvMusic_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                Music m = Music.FromDataGridView(dgvMusic.CurrentRow);
                MusicBLL bll = new MusicBLL(m.Source);
                bll.GetData(m);
                player.URL = m.Url;
                lrcView.Items.Clear();
                if (m.Lrc != null)
                {
                    foreach (var item in m.Lrc.Words)
                    {
                        lrcView.Items.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
              //  lblStatus.Text = ex.Message;
            }
        }

        private void panTop_MouseDown(object sender, MouseEventArgs e)
        {
            Win32Helper.MoveWindow(this);
        }
    }
}
