using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using FObjBase;
using FLY.FilmCasting.AutoDie.IService;

namespace FLY.FilmCasting.AutoDie.UI.Client
{
    /// <summary>
    /// Window_Load.xaml 的交互逻辑
    /// </summary>
    public partial class WdLoadHeatsFile : FLY.ControlLibrary.WindowBigClose
    {
        IFeedbackHeatService mFeedbackHeatService;
        public ObservableCollection<string> mList = new ObservableCollection<string>();

        public WdLoadHeatsFile()
        {
            InitializeComponent();
        }

        public void Init(IFeedbackHeatService feedbackHeatService)
        {

            this.listview_profile.ItemsSource = mList;
            mFeedbackHeatService = feedbackHeatService;

            feedbackHeatService.GetHeatsFileList(
                new AsyncCBHandler(
                    delegate(object AsyncState, object retData)
                    {
                        List<string> list = (List<string>)retData;
                        mList.Clear();
                        for (int i = 0; i < list.Count(); i++)
                            mList.Add(list[i]);

                        if (mList.Contains(feedbackHeatService.HeatsProductName))
                        {
                            listview_profile.SelectedItem = mList.First(s => s == feedbackHeatService.HeatsProductName);
                        }
                    }), null);
        }

        private void button_read_Click(object sender, RoutedEventArgs e)
        {
            if (listview_profile.SelectedItem != null)
            {
                string productname = listview_profile.SelectedItem as string;
                mFeedbackHeatService.LoadHeatsFile(
                    productname);
                FLY.ControlLibrary.Window_Tip.Show("加载成功",
                    productname,
                    TimeSpan.FromSeconds(2));
            }
        }

        private void button_del_Click(object sender, RoutedEventArgs e)
        {
            if (listview_profile.SelectedItem != null)
            {
                string productname = listview_profile.SelectedItem as string;
                mFeedbackHeatService.DelHeatsFile(productname);
                mList.Remove(productname);
                FLY.ControlLibrary.Window_Tip.Show("删除成功",
                    productname,
                    TimeSpan.FromSeconds(2));
            }
        }
    }
}
