using System;
using System.Collections.Generic;
using System.ComponentModel;
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_AHelper : FLY.ControlLibrary.WindowBigClose
    {
        private ABHelper mABHelper;
        public double A;
        private double a;
        public Window_AHelper()
        {
            InitializeComponent();
            mABHelper = new ABHelper();
            this.DataContext = mABHelper;
        }

        public void Init(double Comp)
        {
            a = Comp;
            mABHelper.A = a;
            A = mABHelper.A;
        }

        private void button_cal_Click(object sender, RoutedEventArgs e)
        {
            if (mABHelper.X1 == 0 || mABHelper.Y1 == 0)
            {
                FLY.ControlLibrary.Window_WarningTip.Show("异常!!!!",
                    "X1=0 或 Y1=0",
                    TimeSpan.FromSeconds(2));
                return;
            }
            else if (a == 0)
            {
                FLY.ControlLibrary.Window_WarningTip.Show("异常!!!!",
                    "A==0",
                    TimeSpan.FromSeconds(2));
                return;
            }
            double x1 = (mABHelper.X1) / a;

            mABHelper.A = mABHelper.Y1 / x1;
            A = mABHelper.A;
        }
        private void button_apply_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

    }

    public class ABHelper : INotifyPropertyChanged
    {
        private double x1;
        public double X1
        {
            get { return x1; }
            set
            {
                if (x1 != value)
                {
                    x1 = value;
                    NotifyPropertyChanged("X1");
                }
            }
        }
        private double y1;
        public double Y1
        {
            get { return y1; }
            set
            {
                if (y1 != value)
                {
                    y1 = value;
                    NotifyPropertyChanged("Y1");
                }
            }
        }

        private double x2;
        public double X2
        {
            get { return x2; }
            set
            {
                if (x2 != value)
                {
                    x2 = value;
                    NotifyPropertyChanged("X2");
                }
            }
        }
        private double y2;
        public double Y2
        {
            get { return y2; }
            set
            {
                if (y2 != value)
                {
                    y2 = value;
                    NotifyPropertyChanged("Y2");
                }
            }
        }
        private double a;
        public double A
        {
            get { return a; }
            set
            {
                if (a != value)
                {
                    a = value;
                    NotifyPropertyChanged("A");
                }
            }
        }
        private double b;
        public double B
        {
            get { return b; }
            set
            {
                if (b != value)
                {
                    b = value;
                    NotifyPropertyChanged("B");
                }
            }
        }

        void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
