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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
using CommunityToolkit.Mvvm.Input;
using Misc;
using System;
using System.ComponentModel;
using System.Windows.Controls;
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>
/// 大屏幕提示扫描报警
/// </summary>
public bool EnableScanErrBigTip { get; set; }
/// <summary>
/// USB 继电器 串口地址
/// </summary>
public string LCUS1_PortName { get; set; } = "COM1";
/// <summary>
/// 使能USB 继电器
/// </summary>
public bool LCUS1_Enable { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public RelayCommand PlayCmd { get; }
public RelayCommand OpenCmd { get; }
public RelayCommand BellRingCmd { get; }
public RelayCommand BellOffCmd { get; }
ParamDictionary paramDictionary;
LCUS1 lcus1;
public LCUS1 LCUS1 => lcus1;
public UcSectionErrorVm()
{
PlayCmd = new RelayCommand(Play);
OpenCmd = new RelayCommand(Open);
BellRingCmd = new RelayCommand(() => { lcus1.On(); });
BellOffCmd = new RelayCommand(() => { lcus1.Off(); });
}
public void Init(ParamDictionary paramDictionary, LCUS1 lCUS1)
{
this.paramDictionary = paramDictionary;
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);
}
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;
}
}
}
}
}