UcSectionError.xaml.cs 4.58 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
using GalaSoft.MvvmLight.Command;
using Misc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
using FLY.Thick.Base.UI;

namespace FLY.Thick.Base.UI.CustomSection
{
    /// <summary>
    /// UcSectionWarning.xaml 的交互逻辑
    /// </summary>
    public partial class UcSectionError : UserControl
    {
        UcSectionErrorVm viewModel;

        public UcSectionError()
        {
            InitializeComponent();
        }

        [Unity.InjectionMethod]
        public void Init(ParamDictionary paramDictionary, LCUS1 lCUS1)
        {
            viewModel = new UcSectionErrorVm();
            viewModel.Init(paramDictionary, lCUS1);
            this.DataContext = viewModel;
        }
    }
    public class UcSectionErrorVm : INotifyPropertyChanged
    {
        /// <summary>
        /// 报警音乐路径 
        /// </summary>
        public string WarningTipPath { get; set; }

        /// <summary>
        /// 报警持续时间 单位:秒
        /// </summary>
        public int WarningDurationSec { get; set; }

        /// <summary>
55
        /// 大屏幕提示扫描报警 
潘栩锋's avatar
潘栩锋 committed
56
        /// </summary>
57
        public bool EnableScanErrBigTip { get; set; }
潘栩锋's avatar
潘栩锋 committed
58 59 60 61 62 63 64 65 66

        /// <summary>
        /// USB 继电器 串口地址
        /// </summary>
        public string LCUS1_PortName { get; set; } = "COM1";

        /// <summary>
        /// 使能USB 继电器
        /// </summary>
67
        public bool LCUS1_Enable { get; set; }
潘栩锋's avatar
潘栩锋 committed
68 69 70 71 72 73 74 75 76 77 78 79 80



        public event PropertyChangedEventHandler PropertyChanged;


        public RelayCommand PlayCmd { get; }
        public RelayCommand OpenCmd { get; }
        public RelayCommand BellRingCmd { get; }
        public RelayCommand BellOffCmd { get; }


        ParamDictionary paramDictionary;
81 82
        LCUS1 lcus1;
        public LCUS1 LCUS1 => lcus1;
潘栩锋's avatar
潘栩锋 committed
83 84 85 86
        public UcSectionErrorVm() 
        {
            PlayCmd = new RelayCommand(Play);
            OpenCmd = new RelayCommand(Open);
87 88
            BellRingCmd = new RelayCommand(() => { lcus1.On(); });
            BellOffCmd = new RelayCommand(() => { lcus1.Off(); });
潘栩锋's avatar
潘栩锋 committed
89 90 91 92 93
        }

        public void Init(ParamDictionary paramDictionary, LCUS1 lCUS1)
        {
            this.paramDictionary = paramDictionary;
94 95 96 97 98 99
            this.lcus1 = lCUS1;
            paramDictionary.SetBinding(this, nameof(WarningTipPath), ParamDistItemKeys.WarningTipPath, "");
            paramDictionary.SetBinding(this, nameof(WarningDurationSec), ParamDistItemKeys.WarningDurationSec, 5);
            paramDictionary.SetBinding(this, nameof(EnableScanErrBigTip), ParamDistItemKeys.EnableScanErrBigTip, false);
            paramDictionary.SetBinding(this, nameof(LCUS1_PortName), ParamDistItemKeys.LCUS1_PortName, "COM1");
            paramDictionary.SetBinding(this, nameof(LCUS1_Enable), ParamDistItemKeys.LCUS1_Enable, false);
潘栩锋's avatar
潘栩锋 committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        }

        private void Play() 
        { 
            //报警!!!!!!!!
            FLY.ControlLibrary.Window_WarningTip.Show(
                "测试",
                WarningTipPath + $" 持续{WarningDurationSec}s",
                TimeSpan.FromSeconds(WarningDurationSec),
                WarningTipPath);
        }

        private void Open()
        {
            System.Windows.Forms.FileDialog open = new System.Windows.Forms.OpenFileDialog();
            open.Filter = "mp3文件|*.mp3|wav文件|*.wav|所有文件|*.*";
            open.Title = "打开音乐文件";
            
            if (System.IO.Path.IsPathRooted(WarningTipPath))
                open.InitialDirectory = System.IO.Path.GetDirectoryName(WarningTipPath);
            else
                open.InitialDirectory = System.Environment.CurrentDirectory;

            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string currentDirectory = System.Environment.CurrentDirectory.ToLower();
                string filename = open.FileName.ToLower();

                if (filename.StartsWith(currentDirectory))
                {
                    //CurrentDirectory没有最后的\ 需要+1
                    WarningTipPath = open.FileName.Substring(System.Environment.CurrentDirectory.Length + 1);
                }
                else
                {
                    WarningTipPath = open.FileName;
                }
            }
        }

    }
}