110 lines
4.2 KiB
C#
110 lines
4.2 KiB
C#
using System;
|
||
using System.Windows.Forms;
|
||
|
||
namespace YiDa_WinForm
|
||
{
|
||
public partial class StrengthTestUploadForm : Form
|
||
{
|
||
// 对外暴露的选择结果
|
||
public bool IsMoldProductionSelected { get; private set; }
|
||
public bool IsTimedAlarmSelected { get; private set; }
|
||
public int TimedInterval { get; private set; }
|
||
|
||
// 新增:保存用户上次的勾选状态(用于持久化)
|
||
private bool _lastMoldProductionSelected;
|
||
private bool _lastTimedAlarmSelected;
|
||
|
||
// 无参构造函数(保留,避免报错)
|
||
public StrengthTestUploadForm()
|
||
{
|
||
InitializeComponent();
|
||
// 默认初始化(首次打开的默认状态)
|
||
_lastMoldProductionSelected = true;
|
||
_lastTimedAlarmSelected = true;
|
||
TimedInterval = 120;
|
||
InitFormControl();
|
||
}
|
||
|
||
// 新增:带完整参数的构造函数(接收主窗体传递的「上次勾选状态+间隔值」)
|
||
public StrengthTestUploadForm(bool lastUploadSelected, bool lastTimedAlarmSelected, int lastInterval)
|
||
{
|
||
InitializeComponent();
|
||
// 保存上次状态
|
||
_lastMoldProductionSelected = lastUploadSelected;
|
||
_lastTimedAlarmSelected = lastTimedAlarmSelected;
|
||
TimedInterval = lastInterval > 0 ? lastInterval : 120;
|
||
// 初始化控件状态
|
||
InitFormControl();
|
||
}
|
||
|
||
// 简化:仅接收间隔值的构造函数(兼容原有调用,保持向下兼容)
|
||
public StrengthTestUploadForm(int lastInterval)
|
||
{
|
||
InitializeComponent();
|
||
// 默认勾选状态(首次打开)
|
||
_lastMoldProductionSelected = true;
|
||
_lastTimedAlarmSelected = true;
|
||
TimedInterval = lastInterval > 0 ? lastInterval : 120;
|
||
InitFormControl();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化控件状态(根据保存的上次状态)
|
||
/// </summary>
|
||
private void InitFormControl()
|
||
{
|
||
// 恢复上次的勾选状态(核心:持久化用户选择)
|
||
checkBoxMoldProduction.Checked = _lastMoldProductionSelected;
|
||
checkBoxTimedAlarm.Checked = _lastTimedAlarmSelected;
|
||
// 初始化间隔输入框
|
||
textBoxInterval.Text = TimedInterval.ToString();
|
||
// 控制输入框可用性
|
||
textBoxInterval.Enabled = checkBoxTimedAlarm.Checked;
|
||
labelInterval.Enabled = checkBoxTimedAlarm.Checked;
|
||
}
|
||
|
||
// 确定按钮点击事件
|
||
private void buttonConfirm_Click(object sender, EventArgs e)
|
||
{
|
||
// 1. 获取用户本次选择(保存到对外暴露的属性)
|
||
IsMoldProductionSelected = checkBoxMoldProduction.Checked;
|
||
IsTimedAlarmSelected = checkBoxTimedAlarm.Checked;
|
||
|
||
// 2. 校验时间间隔(仅当勾选报警时校验)
|
||
if (IsTimedAlarmSelected)
|
||
{
|
||
if (int.TryParse(textBoxInterval.Text, out int interval) && interval > 0)
|
||
{
|
||
TimedInterval = interval;
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("请输入有效的正整数时间间隔!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 3. 关闭弹窗(返回OK结果)
|
||
DialogResult = DialogResult.OK;
|
||
Close();
|
||
}
|
||
|
||
// 取消按钮点击事件
|
||
private void buttonCancel_Click(object sender, EventArgs e)
|
||
{
|
||
DialogResult = DialogResult.Cancel;
|
||
Close();
|
||
}
|
||
|
||
// 定时报警复选框状态变更(控制输入框可用性)
|
||
private void checkBoxTimedAlarm_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
textBoxInterval.Enabled = checkBoxTimedAlarm.Checked;
|
||
labelInterval.Enabled = checkBoxTimedAlarm.Checked;
|
||
}
|
||
|
||
// 无用事件(保留,避免设计器报错)
|
||
private void label1_Click(object sender, EventArgs e) { }
|
||
private void textBoxInterval_TextChanged(object sender, EventArgs e) { }
|
||
}
|
||
} |