fg_yida_2/YiDa_WinForm/Form/ScrapImageUploadForm.cs

114 lines
3.3 KiB
C#
Raw Normal View History

2026-01-29 08:39:56 +08:00
using System;
using System.Windows.Forms;
namespace YiDa_WinForm
{
public partial class ScrapUploadForm : Form
{
2026-01-29 20:29:12 +08:00
// 对外暴露的选择结果
2026-02-03 10:08:13 +08:00
public int ScrapTimedIntervalOne { get; private set; }
public int ScrapTimedIntervalTwo { get; private set; }
2026-01-29 08:39:56 +08:00
2026-02-03 10:08:13 +08:00
public string DeviceCode;
2026-01-29 20:29:12 +08:00
// 无参构造函数(保留,避免报错)
2026-01-29 08:39:56 +08:00
public ScrapUploadForm()
{
InitializeComponent();
2026-02-03 10:08:13 +08:00
ScrapTimedIntervalOne = 120;
ScrapTimedIntervalTwo = 120;
InitFormControl("1");
2026-01-29 20:29:12 +08:00
}
2026-02-03 10:08:13 +08:00
// 带完整参数的构造函数
public ScrapUploadForm(int lastInterval, string deviceCode)
2026-01-29 20:29:12 +08:00
{
InitializeComponent();
2026-02-03 10:08:13 +08:00
if (deviceCode.Contains("1"))
{
DeviceCode = deviceCode;
ScrapTimedIntervalOne = lastInterval > 0 ? lastInterval : 120;
InitFormControl("1");
}
else
{
DeviceCode = deviceCode;
ScrapTimedIntervalTwo = lastInterval > 0 ? lastInterval : 120;
InitFormControl("2");
}
2026-01-29 08:39:56 +08:00
}
2026-01-29 20:29:12 +08:00
/// <summary>
/// 初始化控件状态(根据保存的上次状态)
/// </summary>
2026-02-03 10:08:13 +08:00
private void InitFormControl(string deviceCode)
2026-01-29 20:29:12 +08:00
{
2026-02-03 10:08:13 +08:00
if (deviceCode.Contains("1"))
{
// 初始化间隔输入框
textBoxScrapInterval.Text = ScrapTimedIntervalOne.ToString();
}
else
{
textBoxScrapInterval.Text = ScrapTimedIntervalTwo.ToString();
}
2026-01-29 20:29:12 +08:00
}
// 确定按钮点击事件
2026-01-29 08:39:56 +08:00
private void buttonConfirm_Click(object sender, EventArgs e)
{
2026-02-03 10:08:13 +08:00
// 1. 校验时间间隔(仅当勾选报警时校验)
if (int.TryParse(textBoxScrapInterval.Text, out int interval) && interval > 0)
2026-01-29 08:39:56 +08:00
{
2026-02-03 10:08:13 +08:00
if (DeviceCode.Contains("1"))
2026-01-29 08:39:56 +08:00
{
2026-02-03 10:08:13 +08:00
ScrapTimedIntervalOne = interval;
2026-01-29 08:39:56 +08:00
}
else
{
2026-02-03 10:08:13 +08:00
ScrapTimedIntervalTwo = interval;
2026-01-29 08:39:56 +08:00
}
2026-02-03 10:08:13 +08:00
DeviceCode = null;
}
else
{
MessageBox.Show("请输入有效的正整数时间间隔!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
2026-01-29 08:39:56 +08:00
}
2026-02-03 10:08:13 +08:00
// 2. 关闭弹窗返回OK结果
2026-01-29 08:39:56 +08:00
DialogResult = DialogResult.OK;
Close();
}
2026-01-29 20:29:12 +08:00
// 取消按钮点击事件
2026-01-29 08:39:56 +08:00
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
2026-02-03 10:08:13 +08:00
// 无用事件(保留,避免设计器报错)
private void label1_Click(object sender, EventArgs e)
2026-01-29 08:39:56 +08:00
{
}
2026-01-29 20:29:12 +08:00
2026-02-03 10:08:13 +08:00
private void textBoxScrapInterval_TextChanged(object sender, EventArgs e)
{
}
private void labelScrapInterval_Click(object sender, EventArgs e)
{
}
private void labelTitle_Click(object sender, EventArgs e)
{
}
private void ScrapUploadForm_Load(object sender, EventArgs e)
{
}
2026-01-29 08:39:56 +08:00
}
}