修改
This commit is contained in:
@@ -48,6 +48,10 @@ namespace 全自动水压检测仪
|
|||||||
private System.Windows.Forms.Timer _readTimerTwo; // 第二个定时器引用
|
private System.Windows.Forms.Timer _readTimerTwo; // 第二个定时器引用
|
||||||
private bool _isManualInput = false; // 手动输入标记
|
private bool _isManualInput = false; // 手动输入标记
|
||||||
private bool _isSwitchingWindow = false; // 窗口切换标记,避免并发
|
private bool _isSwitchingWindow = false; // 窗口切换标记,避免并发
|
||||||
|
|
||||||
|
// 温度模式状态跟踪(用于防抖优化)
|
||||||
|
private bool _lastHighTempMode = false;
|
||||||
|
private bool _lastLowTempMode = false;
|
||||||
|
|
||||||
private ConductivityRepository _repository;
|
private ConductivityRepository _repository;
|
||||||
|
|
||||||
@@ -780,32 +784,30 @@ namespace 全自动水压检测仪
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//低温指示
|
//低温指示(优化版本 - 减少不必要的UI更新)
|
||||||
if (modbusResults.LowStatus != null && modbusResults.LowStatus.Length > 0 && uiLight1 != null && !uiLight1.IsDisposed)
|
if (modbusResults.LowStatus != null && modbusResults.LowStatus.Length > 0 && uiLight1 != null && !uiLight1.IsDisposed)
|
||||||
{
|
{
|
||||||
bool previousLowTempState = uiLight1.State == UILightState.On;
|
|
||||||
bool currentLowTempState = modbusResults.LowStatus[0];
|
bool currentLowTempState = modbusResults.LowStatus[0];
|
||||||
|
|
||||||
uiLight1.State = currentLowTempState ? UILightState.On : UILightState.Off;
|
uiLight1.State = currentLowTempState ? UILightState.On : UILightState.Off;
|
||||||
|
|
||||||
// 如果温度模式状态发生变化,更新控件可见性
|
// 只有状态真正改变时才更新控件可见性
|
||||||
if (previousLowTempState != currentLowTempState)
|
if (_lastLowTempMode != currentLowTempState)
|
||||||
{
|
{
|
||||||
|
_lastLowTempMode = currentLowTempState;
|
||||||
UpdateControlsVisibilityByMode();
|
UpdateControlsVisibilityByMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//高温指示
|
//高温指示(优化版本 - 减少不必要的UI更新)
|
||||||
if (modbusResults.HighStatus != null && modbusResults.HighStatus.Length > 0 && uiLight2 != null && !uiLight2.IsDisposed)
|
if (modbusResults.HighStatus != null && modbusResults.HighStatus.Length > 0 && uiLight2 != null && !uiLight2.IsDisposed)
|
||||||
{
|
{
|
||||||
bool previousHighTempState = uiLight2.State == UILightState.On;
|
|
||||||
bool currentHighTempState = modbusResults.HighStatus[0];
|
bool currentHighTempState = modbusResults.HighStatus[0];
|
||||||
|
|
||||||
uiLight2.State = currentHighTempState ? UILightState.On : UILightState.Off;
|
uiLight2.State = currentHighTempState ? UILightState.On : UILightState.Off;
|
||||||
|
|
||||||
// 如果温度模式状态发生变化,更新控件可见性
|
// 只有状态真正改变时才更新控件可见性
|
||||||
if (previousHighTempState != currentHighTempState)
|
if (_lastHighTempMode != currentHighTempState)
|
||||||
{
|
{
|
||||||
|
_lastHighTempMode = currentHighTempState;
|
||||||
UpdateControlsVisibilityByMode();
|
UpdateControlsVisibilityByMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1277,7 +1279,7 @@ namespace 全自动水压检测仪
|
|||||||
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 10082);
|
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 10082);
|
||||||
}
|
}
|
||||||
|
|
||||||
//切换实验模式
|
//切换实验模式(优化版本 - 减少延迟和卡顿)
|
||||||
private async void uiSwitch1_Click(object sender, EventArgs e)
|
private async void uiSwitch1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -1304,10 +1306,10 @@ namespace 全自动水压检测仪
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 延迟等待PLC状态更新
|
// 缩短延迟时间,从800ms减少到300ms
|
||||||
await Task.Delay(800);
|
await Task.Delay(300);
|
||||||
|
|
||||||
// 更新控件可见性
|
// 更新控件可见性(已优化为批量更新)
|
||||||
SafeInvoke(() =>
|
SafeInvoke(() =>
|
||||||
{
|
{
|
||||||
UpdateControlsVisibilityByMode();
|
UpdateControlsVisibilityByMode();
|
||||||
@@ -1632,7 +1634,7 @@ namespace 全自动水压检测仪
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据温度模式更新控件可见性
|
/// 根据温度模式更新控件可见性(优化版本 - 批量更新减少卡顿)
|
||||||
/// 常温模式:显示常温相关参数(常温实时液位、常温加水)
|
/// 常温模式:显示常温相关参数(常温实时液位、常温加水)
|
||||||
/// 高温模式:显示高温相关参数(高温实时液位、箱体温度、出口温度、高温加水、水箱加热)
|
/// 高温模式:显示高温相关参数(高温实时液位、箱体温度、出口温度、高温加水、水箱加热)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1642,119 +1644,82 @@ namespace 全自动水压检测仪
|
|||||||
{
|
{
|
||||||
// 判断当前是否为高温模式(uiLight2亮起表示高温模式)
|
// 判断当前是否为高温模式(uiLight2亮起表示高温模式)
|
||||||
bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
|
bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
|
||||||
bool isLowTempMode = uiLight1 != null && uiLight1.State == UILightState.On;
|
|
||||||
|
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 开始更新 - 高温模式: {isHighTempMode}, 常温模式: {isLowTempMode}");
|
// 暂停布局更新,批量修改控件属性,减少重绘次数
|
||||||
|
this.SuspendLayout();
|
||||||
|
|
||||||
// ========== 高温模式专属控件(高温模式显示,常温模式隐藏) ==========
|
// ========== 高温模式专属控件(高温模式显示,常温模式隐藏) ==========
|
||||||
|
|
||||||
// 高温实时液位(mm) - uiPanel31包含uiLabel7, uiLabel8, uiLabel34, uiProcessBar2
|
// 高温实时液位(mm)
|
||||||
if (uiPanel31 != null && !uiPanel31.IsDisposed)
|
if (uiPanel31 != null && !uiPanel31.IsDisposed)
|
||||||
{
|
|
||||||
uiPanel31.Visible = isHighTempMode;
|
uiPanel31.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel31(高温液位) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 箱体温度(°C) - uiPanel35包含uiLabel42, uiLabel43(实时数据监控区域)
|
// 箱体温度(°C)
|
||||||
if (uiPanel35 != null && !uiPanel35.IsDisposed)
|
if (uiPanel35 != null && !uiPanel35.IsDisposed)
|
||||||
{
|
|
||||||
uiPanel35.Visible = isHighTempMode;
|
uiPanel35.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel35(箱体温度) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 出口温度(°C) - uiPanel33包含uiLabel38, uiLabel39(实时数据监控区域)
|
// 出口温度(°C)
|
||||||
if (uiPanel33 != null && !uiPanel33.IsDisposed)
|
if (uiPanel33 != null && !uiPanel33.IsDisposed)
|
||||||
{
|
|
||||||
uiPanel33.Visible = isHighTempMode;
|
uiPanel33.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel33(出口温度) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 高温加水按钮 - uiButton5
|
// 高温加水按钮
|
||||||
if (uiButton5 != null && !uiButton5.IsDisposed)
|
if (uiButton5 != null && !uiButton5.IsDisposed)
|
||||||
{
|
|
||||||
uiButton5.Visible = isHighTempMode;
|
uiButton5.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton5(高温加水) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 高温加水指示灯 - uiLight11
|
// 高温加水指示灯
|
||||||
if (uiPanel43 != null && !uiPanel43.IsDisposed)
|
if (uiPanel43 != null && !uiPanel43.IsDisposed)
|
||||||
{
|
|
||||||
uiPanel43.Visible = isHighTempMode;
|
uiPanel43.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel43(高温加水指示灯) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 水箱加热按钮 - uiButton4(用户操作设定区域)
|
// 水箱加热按钮
|
||||||
if (uiButton4 != null && !uiButton4.IsDisposed)
|
if (uiButton4 != null && !uiButton4.IsDisposed)
|
||||||
{
|
|
||||||
uiButton4.Visible = isHighTempMode;
|
uiButton4.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton4(水箱加热) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 出口温度判定设置 - uiLabel48和uiTextBox9(用户操作设定区域)
|
// 出口温度判定设置
|
||||||
if (uiLabel48 != null && !uiLabel48.IsDisposed)
|
if (uiLabel48 != null && !uiLabel48.IsDisposed)
|
||||||
{
|
|
||||||
uiLabel48.Visible = isHighTempMode;
|
uiLabel48.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel48(出口温度标签) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
|
if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
|
||||||
{
|
|
||||||
uiTextBox9.Visible = isHighTempMode;
|
uiTextBox9.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox9(出口温度输入) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 写入按钮 - uiButton8(用于写入联络单号和件号数据到PLC,常温和高温模式都需要)
|
// 箱体温度设置
|
||||||
// 注意:写入按钮应该始终显示,因为联络单号和件号在两种模式下都需要
|
|
||||||
if (uiButton8 != null && !uiButton8.IsDisposed)
|
|
||||||
{
|
|
||||||
uiButton8.Visible = true; // 始终显示写入按钮
|
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton8(写入按钮) Visible = true (始终显示)");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 箱体温度设置 - uiLabel37和uiTextBox4(用户操作设定区域)
|
|
||||||
if (uiLabel37 != null && !uiLabel37.IsDisposed)
|
if (uiLabel37 != null && !uiLabel37.IsDisposed)
|
||||||
{
|
|
||||||
uiLabel37.Visible = isHighTempMode;
|
uiLabel37.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel37(箱体温度标签) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
|
if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
|
||||||
{
|
|
||||||
uiTextBox4.Visible = isHighTempMode;
|
uiTextBox4.Visible = isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox4(箱体温度输入) Visible = {isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 常温模式专属控件(常温模式显示,高温模式隐藏) ==========
|
// ========== 常温模式专属控件(常温模式显示,高温模式隐藏) ==========
|
||||||
|
|
||||||
// 常温实时液位(mm) - uiPanel23包含uiLabel12, uiLabel16, uiLabel17, uiProcessBar1
|
// 常温实时液位(mm)
|
||||||
if (uiPanel23 != null && !uiPanel23.IsDisposed)
|
if (uiPanel23 != null && !uiPanel23.IsDisposed)
|
||||||
{
|
|
||||||
uiPanel23.Visible = !isHighTempMode;
|
uiPanel23.Visible = !isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel23(常温液位) Visible = {!isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 常温加水按钮 - uiButton13
|
// 常温加水按钮
|
||||||
if (uiButton13 != null && !uiButton13.IsDisposed)
|
if (uiButton13 != null && !uiButton13.IsDisposed)
|
||||||
{
|
|
||||||
uiButton13.Visible = !isHighTempMode;
|
uiButton13.Visible = !isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton13(常温加水) Visible = {!isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 常温加水指示灯 - uiLight6
|
// 常温加水指示灯
|
||||||
if (uiPanel38 != null && !uiPanel38.IsDisposed)
|
if (uiPanel38 != null && !uiPanel38.IsDisposed)
|
||||||
{
|
|
||||||
uiPanel38.Visible = !isHighTempMode;
|
uiPanel38.Visible = !isHighTempMode;
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel38(常温加水指示灯) Visible = {!isHighTempMode}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 写入按钮始终显示
|
||||||
|
if (uiButton8 != null && !uiButton8.IsDisposed)
|
||||||
|
uiButton8.Visible = true;
|
||||||
|
|
||||||
|
// 恢复布局更新,一次性重绘所有变更
|
||||||
|
this.ResumeLayout(true);
|
||||||
|
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 模式切换完成 - 高温模式: {isHighTempMode}");
|
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 模式切换完成 - 高温模式: {isHighTempMode}");
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException ex)
|
catch (ObjectDisposedException ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 控件已释放: {ex.Message}");
|
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 控件已释放: {ex.Message}");
|
||||||
|
// 确保恢复布局
|
||||||
|
try { this.ResumeLayout(true); } catch { }
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 更新控件可见性失败: {ex.Message}");
|
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 更新控件可见性失败: {ex.Message}");
|
||||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 堆栈跟踪: {ex.StackTrace}");
|
// 确保恢复布局
|
||||||
|
try { this.ResumeLayout(true); } catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user