PgScanWarning.xaml.cs 2.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
using FLY.Thick.Base.UI;
using FLY.Thick.FilmCasting.IService;
using GalaSoft.MvvmLight.Command;
using System;
using System.ComponentModel;
using System.Windows.Controls;
using Unity;

namespace FLY.Thick.FilmCasting.UI
{
    /// <summary>
    /// PgScanWarning.xaml 的交互逻辑
    /// </summary>
14 15
    public partial class PgScanWarning : Page
    {
16 17
        PgScanWarningVm viewModel;
        public PgScanWarning()
18 19 20 21 22 23 24 25 26 27
        {
            InitializeComponent();
        }
        [InjectionMethod]
        public void Init(IScanWarningService scanWarningService)
        {
            viewModel = new PgScanWarningVm();
            viewModel.Init(scanWarningService);
            this.DataContext = viewModel;
        }
28
    }
29
    public class PgScanWarningVm : INotifyPropertyChanged
30
    {
31
        public event PropertyChangedEventHandler PropertyChanged;
32

33 34 35 36 37
        #region 参数
        /// <summary>
        /// 使能
        /// </summary>
        public bool Enable { get; set; }
38 39 40 41 42 43 44

        /// <summary>
        /// 连续N个点,大于规格线(公差)才算报警
        /// </summary>
        public int AlarmCnt { get; set; }

        /// <summary>
45
        /// 是公差的多少倍 报警 
46 47 48 49 50 51 52 53 54
        /// </summary>
        public double AlarmPercent { get; set; }
        /// <summary>
        /// 混合数
        /// </summary>
        public int Mix { get; set; }
        #endregion
        #region Command
        public RelayCommand ApplyCmd { get; }
55
        #endregion
56

57
        IScanWarningService scanWarningService;
58

59 60 61 62
        public PgScanWarningVm()
        {
            ApplyCmd = new RelayCommand(Apply);
        }
63

64 65 66
        public void Init(IScanWarningService scanWarningService)
        {
            this.scanWarningService = scanWarningService;
67

68 69 70 71
            Misc.BindingOperations.SetBinding(scanWarningService, nameof(scanWarningService.Enable), this, nameof(Enable));
            Misc.BindingOperations.SetBinding(scanWarningService, nameof(scanWarningService.AlarmCnt), this, nameof(AlarmCnt));
            Misc.BindingOperations.SetBinding(scanWarningService, nameof(scanWarningService.AlarmPercent), this, nameof(AlarmPercent));
            Misc.BindingOperations.SetBinding(scanWarningService, nameof(scanWarningService.Mix), this, nameof(Mix));
72 73
        }
        private void Apply()
74 75 76 77 78
        {
            if (!WdPassword.Authorize("ScanWarning"))
                return;

            scanWarningService.Enable = this.Enable;
79 80 81 82 83
            scanWarningService.AlarmCnt = this.AlarmCnt;
            scanWarningService.AlarmPercent = this.AlarmPercent;
            scanWarningService.Mix = this.Mix;
            scanWarningService.Apply();

84 85 86 87
            FLY.ControlLibrary.Window_Tip.Show("应用成功",
                null,
                TimeSpan.FromSeconds(2));
        }
88 89
    }
}