fg_yida_2/YiDa_WinForm/Form/ScrapImageUploadForm.cs
2026-02-03 10:08:13 +08:00

114 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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