WdAbHelper.xaml.cs 3.08 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2
using System;
using System.Collections.Generic;
潘栩锋's avatar
潘栩锋 committed
3
using System.ComponentModel;
潘栩锋's avatar
潘栩锋 committed
4 5 6 7 8 9 10 11 12 13 14 15
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;


潘栩锋's avatar
潘栩锋 committed
16
namespace FLY.Thick.Base.UI
潘栩锋's avatar
潘栩锋 committed
17 18 19 20
{
    /// <summary>
    /// Window_AHelper.xaml 的交互逻辑
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
21
    public partial class WdAbHelper : FLY.ControlLibrary.WindowBigClose
潘栩锋's avatar
潘栩锋 committed
22
    {
潘栩锋's avatar
潘栩锋 committed
23
        WdAbHelperVm viewModel;
潘栩锋's avatar
潘栩锋 committed
24 25
        public double A { get { return viewModel.A; } }
        public double B { get { return viewModel.B; } }
潘栩锋's avatar
潘栩锋 committed
26

潘栩锋's avatar
潘栩锋 committed
27
        //外部值
潘栩锋's avatar
潘栩锋 committed
28 29 30
        private double a;
        private double b;

潘栩锋's avatar
潘栩锋 committed
31
        public WdAbHelper()
潘栩锋's avatar
潘栩锋 committed
32 33
        {
            InitializeComponent();
潘栩锋's avatar
潘栩锋 committed
34
            viewModel = new WdAbHelperVm();
潘栩锋's avatar
潘栩锋 committed
35
            this.DataContext = viewModel;
潘栩锋's avatar
潘栩锋 committed
36 37
        }

潘栩锋's avatar
潘栩锋 committed
38
        public void Init(double a,double b)
潘栩锋's avatar
潘栩锋 committed
39
        {
潘栩锋's avatar
潘栩锋 committed
40 41
            this.a = a;
            this.b = b;
潘栩锋's avatar
潘栩锋 committed
42

潘栩锋's avatar
潘栩锋 committed
43 44
            viewModel.A = a;
            viewModel.B = b;
潘栩锋's avatar
潘栩锋 committed
45 46 47 48
        }

        private void button_cal_Click(object sender, RoutedEventArgs e)
        {
潘栩锋's avatar
潘栩锋 committed
49
            if ((viewModel.X2 == viewModel.X1) && (viewModel.Y2 != viewModel.Y1))
潘栩锋's avatar
潘栩锋 committed
50 51 52 53 54 55
            {
                FLY.ControlLibrary.Window_WarningTip.Show("异常!!!!",
                    "X2 == X1 但 Y2 != Y1",
                    TimeSpan.FromSeconds(2));
                return;
            }
潘栩锋's avatar
潘栩锋 committed
56
            if ((viewModel.X2 != viewModel.X1) && (viewModel.Y2 == viewModel.Y1))
潘栩锋's avatar
潘栩锋 committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70
            {
                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;
            }

潘栩锋's avatar
潘栩锋 committed
71
            if ((viewModel.X2 == viewModel.X1) && (viewModel.Y2 == viewModel.Y1))
潘栩锋's avatar
潘栩锋 committed
72
            {
潘栩锋's avatar
潘栩锋 committed
73 74
                viewModel.A = a;
                viewModel.B = viewModel.Y2 - viewModel.X2 + b;
潘栩锋's avatar
潘栩锋 committed
75 76 77
            }
            else
            {
潘栩锋's avatar
潘栩锋 committed
78 79
                double x2 = (viewModel.X2 - b) / a;
                double x1 = (viewModel.X1 - b) / a;
潘栩锋's avatar
潘栩锋 committed
80

潘栩锋's avatar
潘栩锋 committed
81 82
                viewModel.A = (viewModel.Y2 - viewModel.Y1) / (x2 - x1);
                viewModel.B = viewModel.Y2 - viewModel.A * x2;
潘栩锋's avatar
潘栩锋 committed
83 84 85 86 87 88 89 90 91 92 93 94
            }

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

    }
潘栩锋's avatar
潘栩锋 committed
95
    public class WdAbHelperVm : INotifyPropertyChanged
潘栩锋's avatar
潘栩锋 committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    {

        public double X1 { get; set; }
        public double Y1 { get; set; }

        public double X2 { get; set; }

        public double Y2 { get; set; }

        public double A { get; set; }

        public double B { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }
潘栩锋's avatar
潘栩锋 committed
111
}