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;


namespace ThickTcpUiInWindow
{
    /// <summary>
    /// Window_AHelper.xaml 的交互逻辑
    /// </summary>
    public partial class Window_ABHelper : FLY.ControlLibrary.WindowBigClose
    {
        private ABHelper mABHelper;
        public double A;
        public double B;

        private double a;
        private double b;

        public Window_ABHelper()
        {
            InitializeComponent();
            mABHelper = new ABHelper();
            this.DataContext = mABHelper;
        }

        public void Init(double Comp,double Shift)
        {
            a = Comp;
            b = Shift;
            mABHelper.A = a;
            mABHelper.B = b;

            A = mABHelper.A;
            B = mABHelper.B;
        }

        private void button_cal_Click(object sender, RoutedEventArgs e)
        {
            if ((mABHelper.X2 == mABHelper.X1) && (mABHelper.Y2 != mABHelper.Y1))
            {
                FLY.ControlLibrary.Window_WarningTip.Show("异常!!!!",
                    "X2 == X1 但 Y2 != Y1",
                    TimeSpan.FromSeconds(2));
                return;
            }
            if ((mABHelper.X2 != mABHelper.X1) && (mABHelper.Y2 == mABHelper.Y1))
            {
                FLY.ControlLibrary.Window_WarningTip.Show("异常!!!!",
                    "X2 != X1 但 Y2 == Y1",
                    TimeSpan.FromSeconds(2));
                return;
            }
            else if (a == 0)
            {
                FLY.ControlLibrary.Window_WarningTip.Show("异常!!!!",
                    "A==0",
                    TimeSpan.FromSeconds(2));
                return;
            }

            if ((mABHelper.X2 == mABHelper.X1) && (mABHelper.Y2 == mABHelper.Y1))
            {
                mABHelper.A = a;
                mABHelper.B = mABHelper.Y2 - mABHelper.X2 + b;
            }
            else
            {
                double x2 = (mABHelper.X2 - b) / a;
                double x1 = (mABHelper.X1 - b) / a;

                mABHelper.A = (mABHelper.Y2 - mABHelper.Y1) / (x2 - x1);
                mABHelper.B = mABHelper.Y2 - mABHelper.A * x2;
            }

            FLY.ControlLibrary.Window_Tip.Show("成功",
                "计算成功",
                TimeSpan.FromSeconds(2));
        }
        private void button_apply_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

    }
}
