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) 
        {
            viewModel = new PgMainVm();
            viewModel.Init(mGage);
            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 PgMainVm()
        {
            SetupCmd = new RelayCommand(Setup);
        }

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

        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();
        }
    }
}
