duheng
2024-04-22 a549072a040749f7c732c83d2d0f138614ac08e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using DevExpress.XtraEditors;
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI
{
    /// <summary>
    /// 设置标签
    /// </summary>
    public partial class SetTagNameDlg : XtraForm
    {
        public SetTagNameDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Properties.Resources.App;
            this.layoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 验证唯一性事件
        /// </summary>
        public event Func<string, Task<bool>> ValidUniqueEvent;
        /// <summary>
        /// 回调事件
        /// </summary>
        public event Func<string, Task<bool>> ReloadDataEvent;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(string TagName)
        {
            this.txtTagName.EditValue = TagName;
        }
 
        //验证
        private async Task<bool> Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtTagName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtTagName, "必填项");
                return false;
            }
            if (this.ValidUniqueEvent != null)
            {
                if (!await this.ValidUniqueEvent(this.txtTagName.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtTagName, "重复");
                    return false;
                }
            }
            return true;
        }
 
        //确定
        private async void btnOk_Click(object sender, EventArgs e)
        {
            if (!await Valid())
                return;
            if (this.ReloadDataEvent != null)
            {
                var result = this.ReloadDataEvent.Invoke(this.txtTagName.Text.Trim());
                if (await result)
                {
                    XtraMessageBox.Show("更新成功!");
                }
                else
                {
                    XtraMessageBox.Show("更新失败!");
                    return;
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}