114 lines
4.0 KiB
C#
114 lines
4.0 KiB
C#
using Sunny.UI;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace 全自动水压检测仪
|
|
{
|
|
/// <summary>
|
|
/// 状态设置弹窗 - 显示温度模式和阀门状态
|
|
/// </summary>
|
|
public partial class StatusSettingsForm : UIForm
|
|
{
|
|
private System.Windows.Forms.Timer _updateTimer;
|
|
private NormalTemperatureMode _parentForm;
|
|
|
|
public StatusSettingsForm(NormalTemperatureMode parentForm)
|
|
{
|
|
_parentForm = parentForm;
|
|
InitializeComponent();
|
|
|
|
// 设置窗体属性
|
|
this.Text = "状态监控设置";
|
|
this.Width = 850;
|
|
this.Height = 550;
|
|
this.StartPosition = FormStartPosition.CenterParent;
|
|
this.ShowInTaskbar = false;
|
|
|
|
// 初始化更新定时器
|
|
_updateTimer = new System.Windows.Forms.Timer();
|
|
_updateTimer.Interval = 500; // 每500ms更新一次
|
|
_updateTimer.Tick += UpdateTimer_Tick;
|
|
|
|
this.Load += StatusSettingsForm_Load;
|
|
this.FormClosing += StatusSettingsForm_FormClosing;
|
|
}
|
|
|
|
private void UpdateTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
UpdateStatusDisplay();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.WriteLine($"更新状态显示失败: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void UpdateStatusDisplay()
|
|
{
|
|
if (_parentForm == null || _parentForm.IsDisposed)
|
|
return;
|
|
|
|
// 从父窗体获取状态并更新
|
|
_parentForm.UpdateStatusSettingsForm(this);
|
|
}
|
|
|
|
// 公共方法供父窗体调用更新状态
|
|
public void UpdateTempModeStatus(UILightState light1State, UILightState light2State, string modeText)
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new Action(() => UpdateTempModeStatus(light1State, light2State, modeText)));
|
|
return;
|
|
}
|
|
|
|
if (uiLight1_Status != null) uiLight1_Status.State = light1State;
|
|
if (uiLight2_Status != null) uiLight2_Status.State = light2State;
|
|
if (uiLabel11_Status != null) uiLabel11_Status.Text = modeText;
|
|
}
|
|
|
|
public void UpdateValveStatus(
|
|
UILightState light3, UILightState light4, UILightState light5,
|
|
UILightState light6, UILightState light7, UILightState light8,
|
|
UILightState light9, UILightState light10, UILightState light11, UILightState light12)
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new Action(() => UpdateValveStatus(light3, light4, light5, light6, light7, light8, light9, light10, light11, light12)));
|
|
return;
|
|
}
|
|
|
|
if (uiLight3_Status != null) uiLight3_Status.State = light3;
|
|
if (uiLight4_Status != null) uiLight4_Status.State = light4;
|
|
if (uiLight5_Status != null) uiLight5_Status.State = light5;
|
|
if (uiLight6_Status != null) uiLight6_Status.State = light6;
|
|
if (uiLight7_Status != null) uiLight7_Status.State = light7;
|
|
if (uiLight8_Status != null) uiLight8_Status.State = light8;
|
|
if (uiLight9_Status != null) uiLight9_Status.State = light9;
|
|
if (uiLight10_Status != null) uiLight10_Status.State = light10;
|
|
if (uiLight11_Status != null) uiLight11_Status.State = light11;
|
|
if (uiLight12_Status != null) uiLight12_Status.State = light12;
|
|
}
|
|
|
|
private void StatusSettingsForm_Load(object sender, EventArgs e)
|
|
{
|
|
_updateTimer?.Start();
|
|
UpdateStatusDisplay();
|
|
}
|
|
|
|
private void StatusSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
_updateTimer?.Stop();
|
|
_updateTimer?.Dispose();
|
|
}
|
|
|
|
private void uiButton_Close_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|