duheng
2024-07-23 3fec42c6383aa3b8d65f744a93b8a918d7cc6e02
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
using Mapster;
using Yw.Dto;
 
namespace HStation.WinFrmUI.Basic
{
    public partial class EditSysMoudleDlg : DevExpress.XtraEditors.XtraForm
    {
        public EditSysMoudleDlg()
        {
            InitializeComponent();
        }
 
        public event Func<Yw.Dto.UpdateSysModuleInput, Task<bool>> ReloadDataEvent = null;
 
        private UpdateSysModuleInput _UpdateModuleDto { get; set; }
 
        public async void SetBindingData(long ID)
        {
            var bll = new Yw.BLL.SysModule();
            var model = await bll.GetByID(ID);
            _UpdateModuleDto = model.Adapt<Yw.Dto.SysModuleDto, Yw.Dto.UpdateSysModuleInput>();
            this.TextEditName.Text = _UpdateModuleDto.Name;
            this.TextEditCode.Text = _UpdateModuleDto.Code;
            this.TextEditDescription.Text = _UpdateModuleDto.Description;
        }
 
        //数据验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(TextEditName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditName, "必填项");
                return false;
            }
            return true;
        }
 
        //完成
        private async void BtnOk_ClickAsync(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            _UpdateModuleDto.Name = TextEditName.Text.Trim();
            _UpdateModuleDto.Code = TextEditCode.Text.Trim();
            _UpdateModuleDto.Description = TextEditDescription.Text.Trim();
            if (await this.ReloadDataEvent.Invoke(_UpdateModuleDto))
            {
                MessageBoxHelper.ShowSuccess("修改成功!");
            }
            else
            {
                MessageBoxHelper.ShowError("修改失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}