duheng
2024-08-12 1a12ef2743134f7fdea6d0abbfec34543b85bdb5
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
using Mapster;
using Yw.Basic;
using Yw.Dto;
 
namespace HStation.WinFrmUI.Basic
{
    public partial class EditSysTypeDlg : DevExpress.XtraEditors.XtraForm
    {
        public EditSysTypeDlg()
        {
            InitializeComponent();
        }
 
        public event Func<Yw.Vmo.SysType, Task<bool>> ReloadDataEvent = null;
 
        private Yw.Vmo.SysType _UpdateSysTypeDto { get; set; }
 
        public async void SetBindingData(long ID)
        {
            var dto = await new Yw.BLL.SysType().GetByID(ID);
            _UpdateSysTypeDto = dto;
            if (_UpdateSysTypeDto.ExtendType == (Yw.Vmo.eExtendType)eExtendType.None)
            {
                this.TextEditExType.SelectedIndex = 0;
            }
            else if (_UpdateSysTypeDto.ExtendType == (Yw.Vmo.eExtendType)eExtendType.Config)
            {
                this.TextEditExType.SelectedIndex = 1;
            }
            else
            {
                this.TextEditExType.SelectedIndex = 2;
            }
            this.TextEditName.Text = _UpdateSysTypeDto.Name;
            this.TextEditDescription.Text = _UpdateSysTypeDto.Description;
            this.TextEditCode.Text = _UpdateSysTypeDto.Code;
        }
 
        //数据验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(TextEditName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditName, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(TextEditCode.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditCode, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(TextEditExType.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditExType, "必填项");
                return false;
            }
            return true;
        }
 
        //完成
        private async void BtnOk_ClickAsync(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            _UpdateSysTypeDto.Name = TextEditName.Text.Trim();
            _UpdateSysTypeDto.Description = TextEditDescription.Text.Trim();
            if (this.TextEditExType.SelectedIndex == 0)
            {
                _UpdateSysTypeDto.ExtendType = (Yw.Vmo.eExtendType)eExtendType.None;
            }
            else if (this.TextEditExType.SelectedIndex == 1)
            {
                _UpdateSysTypeDto.ExtendType = (Yw.Vmo.eExtendType)eExtendType.Config;
            }
            else
            {
                _UpdateSysTypeDto.ExtendType = (Yw.Vmo.eExtendType)eExtendType.Catalog;
            }
            _UpdateSysTypeDto.Code = TextEditCode.Text.Trim();
            if (await this.ReloadDataEvent.Invoke(_UpdateSysTypeDto))
            {
                MessageBoxHelper.ShowSuccess("修改成功!");
            }
            else
            {
                MessageBoxHelper.ShowError("修改失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}