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 FLY.Thick.Base.IService;
using FLY.Thick.Base.Client;

namespace ThickTcpUiInWindow
{
    /// <summary>
    /// Window_BoltCreate.xaml 的交互逻辑
    /// </summary>
    public partial class Window_BoltCreate : Window
    {
        BoltCreateInfo mBoltCreateInfo;
        //这两个需要赋值
        public IInitParamService mInitParam;
        public IBoltMapService mBoltMap;
        
        public Window_BoltCreate()
        {
            InitializeComponent();
            mBoltCreateInfo = new BoltCreateInfo();
        }
        public void Init(IBoltMapService boltmap, IInitParamService initparam) 
        {
            mBoltMap = boltmap;
            mInitParam = initparam;

            mBoltCreateInfo.PosLength = mInitParam.PosLength;
            mBoltCreateInfo.BoltNo1st = 0;
            mBoltCreateInfo.BoltWidth = (int)(10 / mInitParam.Encoder1_mmpp);// 10mm
            mBoltCreateInfo.BoltInterval = mBoltCreateInfo.BoltWidth;
        }

        private void Window_Unloaded(object sender, RoutedEventArgs e)
        {

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = mBoltCreateInfo;
            this.grid_null.DataContext = mInitParam;
        }

        private void button_apply01_Click(object sender, RoutedEventArgs e)
        {
            BoltCreateInfo.CreateAutoMapReturn r = mBoltCreateInfo.CreateAutoMap(
                mBoltMap,
                mBoltCreateInfo.PosLength,
                mBoltCreateInfo.BoltWidth,
                mBoltCreateInfo.BoltNo1st);
            if (r != BoltCreateInfo.CreateAutoMapReturn.OK)
                MessageBox.Show("参数异常", "警告", MessageBoxButton.OK, MessageBoxImage.Error);
            else
            {
                mBoltMap.Apply();
                this.Close();
            }
        }
        private void button_apply02_Click(object sender, RoutedEventArgs e)
        {
            BoltCreateInfo.CreateAutoMapReturn r = mBoltCreateInfo.CreateAutoMap(
                mBoltMap,
                mBoltCreateInfo.PosLength,
                mBoltCreateInfo.BoltWidth,
                mBoltCreateInfo.BoltNo1st,
                mBoltCreateInfo.BoltInterval);
            if (r != BoltCreateInfo.CreateAutoMapReturn.OK)
                MessageBox.Show("参数异常", "警告", MessageBoxButton.OK, MessageBoxImage.Error);
            else
            {
                mBoltMap.Apply();
                this.Close();
            }
        }
        private void button_apply03_Click(object sender, RoutedEventArgs e)
        {
            BoltCreateInfo.CreateAutoMapReturn r = mBoltCreateInfo.CreateAutoMap(
                mBoltMap,
                mBoltCreateInfo.PosLength,
                mBoltCreateInfo.BoltWidth,
                mBoltCreateInfo.Custom);
            if (r != BoltCreateInfo.CreateAutoMapReturn.OK)
                MessageBox.Show("参数异常", "警告", MessageBoxButton.OK, MessageBoxImage.Error);
            else
            {
                mBoltMap.Apply();
                this.Close();
            }
        }
    }
}
