using FLY.Thick.Base.Server;
using FLY.Thick.FilmCasting.Server;
using GalaSoft.MvvmLight.Command;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;

namespace FLY.Thick.FilmCasting.UI.Server
{
    /// <summary>
    /// PgMain.xaml 的交互逻辑
    /// </summary>
    public partial class PgMain : Page
    {
        PgMainVm viewModel;
        public PgMain()
        {
            InitializeComponent();
        }
        public void Init(TDGage mGage, PicHistory picHistory) 
        {
            viewModel = new PgMainVm();
            viewModel.Init(mGage, picHistory);
            this.DataContext = viewModel;
        }
    }
    public class PgMainVm : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public SysParam SysParam { get; set; }
        public InitParam InitParam { get; set; }

        public FlyADBase.FlyAD7 FlyAd { get; set; }

        public RelayCommand SetupCmd { get; private set; }
        public RelayCommand PicSetupCmd { get; private set; }

        PicHistory picHistory;
        public PgMainVm()
        {
            SetupCmd = new RelayCommand(Setup);
            PicSetupCmd = new RelayCommand(PicSetup);
        }

        private void PicSetup()
        {
            WdPicHistory w = new WdPicHistory();
            w.Init(picHistory);
            w.Owner = App.Current.MainWindow;
            w.ShowDialog();
        }

        public void Init(TDGage mGage, PicHistory picHistory)
        {
            SysParam = mGage.sysParam;
            InitParam = mGage.initParam;
            FlyAd = mGage.flyAd;
            this.picHistory = picHistory;
        }

        private void Setup()
        {
            //打开设置页面

            WdSetup w = new WdSetup();
            w.Init(SysParam, FlyAd, InitParam);
            w.Owner = App.Current.MainWindow;
            w.ShowDialog();
        }

    }

    public class ConnectionValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool? b = (bool?)value;
            if (b == null)
                return null;
            else if (b == true)
                return "连接成功";
            else
                return "连接断开";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
