Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using DevExpress.XtraEditors;
using IStation.Unit;
using System;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Basic
{
    public partial class AddIntegrationSignalTypeDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddIntegrationSignalTypeDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = WinFrmUI.Properties.Resources.App;
            this.dataLayoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 验证识别标识的唯一性
        /// </summary>
        public event Func<string, bool> ValidIdentifierUniqueEvent;
        /// <summary>
        /// 返回数据事件
        /// </summary>
        public event Action<Model.SignalType> ReloadDataEvent;
 
        private Model.SignalType _model = null;//当前操作对象
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(long GroupID, int SortCode)
        {
            this.Text = "添加集成信号类型";
            _model = new Model.SignalType();
            _model.GroupID = GroupID;
            _model.UnitType = eUnitType.未知;
            _model.UnitValue = string.Empty;
            _model.ValueType = Model.Monitor.eValueType.Integration;
            _model.SortCode = SortCode;
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.NameTextEdit.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.NameTextEdit, "必填项");
                return false;
            }
            var identifier = this.IdentifierTextEdit.Text.Trim();
            if (string.IsNullOrEmpty(identifier))
            {
                this.dxErrorProvider1.SetError(this.IdentifierTextEdit, "必填项");
                return false;
            }
            if (this.ValidIdentifierUniqueEvent != null)
            {
                if (!this.ValidIdentifierUniqueEvent(identifier))
                {
                    this.dxErrorProvider1.SetError(this.IdentifierTextEdit, "标识重复");
                    return false;
                }
            }
            return true;
        }
 
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
 
            _model.Name = this.NameTextEdit.Text.Trim();
            _model.Identifier = this.IdentifierTextEdit.Text.Trim();
            _model.Description = this.DescriptionMemoEdit.Text.Trim();
 
            var bll = new BLL.Scatl.SignalType();
            var id = bll.Insert(_model);
            if (id < 1)
            {
                XtraMessageBox.Show("添加失败!");
                return;
            }
 
            if (this.ReloadDataEvent != null)
            {
                var model = bll.GetById(id);
                this.ReloadDataEvent.Invoke(model);
            }
 
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
    }
}