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 ThickTcpUiInWindow.Converter;
using System.Net;

using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
namespace ThickTcpUiInWindow
{
    /// <summary>
    /// Page_FlyAD.xaml 的交互逻辑
    /// </summary>
    public partial class Page_FlyAD : Page
    {
        FlyADService mFlyADService;

        IPEndPoint ServerIPEP;
        TDGageService mTDGageService;


        public Page_FlyAD()
        {
            InitializeComponent();
        }
        public void Init(IPEndPoint ServerIPEP, DynArea dynarea, TDGageService tdGageService) 
        {
            mFlyADService = new FlyADService();



            FObjBase.FObjSys.Current.Connect_to_Another_OBJSys(
                ServerIPEP, mFlyADService.ID);

            this.DataContext = mFlyADService;
            textbox_targetpos.DataContext = this;
            textblock_position.DataContext = dynarea;

            mTDGageService = tdGageService;
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {

        }
        
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            mFlyADService.Dispose();
        }

        private void button_apply_Click(object sender, RoutedEventArgs e)
        {
            if (Window_Password.Authorize(2))
            {
                mFlyADService.Apply();
                FLY.ControlLibrary.Window_Tip.Show("应用成功",
                    null,
                    TimeSpan.FromSeconds(2));
            }
        }

        private void button_backw_Click(object sender, RoutedEventArgs e)
        {
            mTDGageService.StartP2(STARTP2_MODE.BACKW_UNTIL_STOP);
        }
        public int TargetPos
        {
            get;
            set;
        }
        private void button_runto_Click(object sender, RoutedEventArgs e)
        {
            mTDGageService.StartP2(STARTP2_MODE.RUNTO, TargetPos);
        }

        private void button_stop_Click(object sender, RoutedEventArgs e)
        {
            mTDGageService.StartP2(STARTP2_MODE.STOP);
        }

        private void button_org_Click(object sender, RoutedEventArgs e)
        {
            mTDGageService.StartP2(STARTP2_MODE.ORG);
        }

        private void button_forw_Click(object sender, RoutedEventArgs e)
        {
            mTDGageService.StartP2(STARTP2_MODE.FORW_UNTIL_STOP);
        }
    }

}
