DHDHSoftware/DHSoftware/Views/SizeLabelEdit.cs
2025-03-21 08:51:20 +08:00

96 lines
2.9 KiB
C#

using DH.Commons.Base;
using DH.Commons.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static DH.Commons.Enums.EnumHelper;
namespace DHSoftware.Views
{
public partial class SizeLabelEdit : UserControl
{
private AntdUI.Window window;
private SizeTreatParam sizeLabel;
public bool submit;
public SizeLabelEdit(AntdUI.Window _window, SizeTreatParam SizeLabel)
{
InitializeComponent();
sizeLabel = SizeLabel;
//设置默认值
InitData();
// 绑定事件
BindEventHandler();
}
private void BindEventHandler()
{
button_ok.Click += Button_ok_Click;
button_cancel.Click += Button_cancel_Click;
}
private void Button_cancel_Click(object sender, EventArgs e)
{
submit = false;
this.Dispose();
}
private void Button_ok_Click(object sender, EventArgs e)
{
iptName.Status = AntdUI.TType.None;
//检查输入内容
if (String.IsNullOrEmpty(iptName.Text))
{
iptName.Status = AntdUI.TType.Error;
AntdUI.Message.warn(window, "参数名称不能为空!", autoClose: 3);
return;
}
sizeLabel.PreName = iptName.Text;
sizeLabel.PrePix = Convert.ToInt32(ipthreshold.Text);
sizeLabel.ResultShow = iptIntParam.Text;
sizeLabel.OutResultShow =iptOutParam.Text;
SizeEnum state = EnumHelper.GetEnumFromDescription<SizeEnum>(sltSizeEnum.Text);
sizeLabel.PreType = state;
submit = true;
this.Dispose();
}
private void InitData()
{
// 清空原有项
sltSizeEnum.Items.Clear();
foreach (SizeEnum state in Enum.GetValues(typeof(SizeEnum)))
{
string description = EnumHelper.GetEnumDescription(state);
sltSizeEnum.Items.Add(description);
}
if (string.IsNullOrEmpty(sizeLabel.PreName))
{
iptName.Text = string.Empty;
ipthreshold.Text = "1";
iptIntParam.Text = string.Empty;
iptOutParam.Text = string.Empty;
sltSizeEnum.SelectedIndex = 0;
}
else
{
iptName.Text = sizeLabel.PreName;
ipthreshold.Text = sizeLabel.PrePix.ToString();
iptIntParam.Text = sizeLabel.ResultShow;
iptOutParam.Text = sizeLabel.OutResultShow;
sltSizeEnum.Text = EnumHelper.GetEnumDescription(sizeLabel.PreType);
}
}
}
}