2026-03-11 16:42:31 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
2026-03-24 19:34:22 +08:00
|
|
|
|
using System.Windows.Media;
|
2026-03-11 16:42:31 +08:00
|
|
|
|
|
|
|
|
|
|
namespace PLCDataMonitor
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class HomePage : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
// 定义事件用于与主窗口通信
|
|
|
|
|
|
public event EventHandler<string> ConnectButtonClicked;
|
|
|
|
|
|
|
|
|
|
|
|
public HomePage()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 19:11:06 +08:00
|
|
|
|
|
|
|
|
|
|
// 定义暂停/继续事件
|
|
|
|
|
|
public event EventHandler PauseRequested;
|
|
|
|
|
|
public event EventHandler ResumeRequested;
|
|
|
|
|
|
|
2026-03-24 19:34:22 +08:00
|
|
|
|
// 【修改点 2】合并点击逻辑
|
2026-03-11 19:11:06 +08:00
|
|
|
|
private void PauseButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2026-03-24 19:34:22 +08:00
|
|
|
|
string currentContent = PauseButton.Content.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
if (currentContent == "暂停")
|
|
|
|
|
|
{
|
|
|
|
|
|
// 当前是运行状态,点击后变为暂停
|
|
|
|
|
|
PauseRequested?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
|
|
|
|
|
|
|
// 立即更新按钮样式为“继续”
|
|
|
|
|
|
PauseButton.Content = "继续";
|
|
|
|
|
|
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#27AE60")); // 绿色
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 当前是暂停状态,点击后变为继续
|
|
|
|
|
|
ResumeRequested?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
|
|
|
|
|
|
|
// 立即更新按钮样式为“暂停”
|
|
|
|
|
|
PauseButton.Content = "暂停";
|
|
|
|
|
|
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E67E22")); // 橙色
|
|
|
|
|
|
}
|
2026-03-11 19:11:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-24 19:34:22 +08:00
|
|
|
|
//private void ResumeButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// ResumeRequested?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 【新增】供 MainWindow 调用的方法,以防 PLC 状态自行变化导致按钮状态不同步
|
|
|
|
|
|
public void SetButtonState(bool isPaused)
|
2026-03-11 19:11:06 +08:00
|
|
|
|
{
|
2026-03-24 19:34:22 +08:00
|
|
|
|
if (isPaused)
|
|
|
|
|
|
{
|
|
|
|
|
|
PauseButton.Content = "继续";
|
|
|
|
|
|
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#27AE60"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PauseButton.Content = "暂停";
|
|
|
|
|
|
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E67E22"));
|
|
|
|
|
|
}
|
2026-03-11 19:11:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-24 19:34:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-03-21 11:15:47 +08:00
|
|
|
|
public void UpdateAlarms(string alarmMessage)
|
|
|
|
|
|
{
|
2026-03-24 19:34:22 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Dispatcher.Invoke(() => // 更新滚动报警控件的文本
|
|
|
|
|
|
AlarmScrollingCtrl.Text = alarmMessage);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2026-03-23 17:31:25 +08:00
|
|
|
|
|
2026-03-24 19:34:22 +08:00
|
|
|
|
}
|
2026-03-21 11:15:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 16:42:31 +08:00
|
|
|
|
// 更新数据显示
|
|
|
|
|
|
public void UpdateData(string pressure1, string pressure2, string friction1, string friction2, int count1, int count2, string t1, string t2, string Distince)
|
|
|
|
|
|
{
|
|
|
|
|
|
TbStation1Pressure.Text = pressure1;
|
|
|
|
|
|
TbStation2Pressure.Text = pressure2;
|
|
|
|
|
|
TbFriction1.Text = friction1;
|
|
|
|
|
|
TbFriction2.Text = friction2;
|
|
|
|
|
|
txtcount1.Text = count1.ToString();
|
|
|
|
|
|
txtcount2.Text = count2.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
txtT1.Text = t1;
|
|
|
|
|
|
txtT2.Text = t2;
|
|
|
|
|
|
txtDistince.Text = Distince;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|