duheng
2025-01-08 21067008153a810c72e8b86faaeca577290ff265
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
using Yw;
using Yw.WinFrmUI;
 
namespace HStation.WinFrmUI
{
    public partial class AddRoleDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddRoleDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
 
        /// <summary>
        /// 返回数据事件
        /// </summary>
        public event Action<Yw.Vmo.Role> ReloadDataEvent;
 
        //验证
        private async Task<bool> Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtName, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtMinorLoss.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtMinorLoss, "必填项");
                return false;
            }
            return true;
        }
 
        //确定
        private async void GeneralOkAndCancelCtrl1_OkEvent()
        {
            var vmo = new Yw.Vmo.RoleEx();
            if (!await Valid())
            {
                return;
            }
            vmo.Name = this.txtName.Text.Trim();
            vmo.Description = this.txtDescription.Text.Trim();
            vmo.ProjectID = 1;
            var id = await BLLFactory<Yw.BLL.Role>.Instance.InsertEx(vmo);
            if (id < 1)
            {
                TipFormHelper.ShowError("添加失败!");
                return;
            }
            var model = await BLLFactory<Yw.BLL.Role>.Instance.GetByID(id);
            this.ReloadDataEvent?.Invoke(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}