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.Navigation;
using System.Windows.Shapes;
using System.Net;
using FLY.Thick.Base.Client;

namespace ThickTcpUiInWindow
{
    /// <summary>
    /// Page_ErrorTable.xaml 的交互逻辑
    /// </summary>
    public partial class PgErrorTable : Page
    {
        FLY.OBJComponents.Client.WarningServiceClient mWarningService;
        FLY.OBJComponents.Client.BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory> mWindow;
        FlyADServiceClient mFlyADService;
        SysParam mSysParam;
        Type wdIoTipType;

        /// <summary>
        /// 
        /// </summary>
        public PgErrorTable()
        {
            InitializeComponent();

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="warningService"></param>
        /// <param name="warningReasonWindow"></param>
        /// <param name="flyADService"></param>
        /// <param name="wdIoTipType"></param>
        public void Init(
            FLY.OBJComponents.Client.WarningServiceClient warningService,
            FLY.OBJComponents.Client.BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory> warningReasonWindow,
            FlyADServiceClient flyADService,
            Type wdIoTipType
            )
        {
            this.wdIoTipType = wdIoTipType;
            mWarningService = warningService;
            mWindow = warningReasonWindow;
            mFlyADService = flyADService;
            gridFlows.ItemsSource = mWindow.Record;
        }

        private void button_back_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }



        private void button_reset_click(object sender, RoutedEventArgs e)
        {
            mWarningService.Reset();
        }

        private void button_iotip_click(object sender, RoutedEventArgs e)
        {
            Window w;
            if (wdIoTipType != null && typeof(Window).IsAssignableFrom(wdIoTipType))
            {
                w = Activator.CreateInstance(wdIoTipType) as Window;
            }
            else
            {
                w = new WdIOTip();
            }
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.ShowDialog();
        }

        private void button_access_click(object sender, RoutedEventArgs e)
        {
            WdFlyADAccess w = new WdFlyADAccess();
            w.Init(mFlyADService);
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.ShowDialog();
        }

        private void button_silence_click(object sender, RoutedEventArgs e)
        {
            mWarningService.Silence();
        }

        private void button_database_click(object sender, RoutedEventArgs e)
        {
            NavigationService ns = NavigationService;// Application.Current.Properties["NavigationService"] as NavigationService;
            if (ns != null)
            {
                PgErrorAllTable p = new PgErrorAllTable();
                p.Init(mWarningService);
                ns.Navigate(p);
            }
        }
    }
}
