lixiaojun
2024-12-20 94d10185010a7476021764f5b5cb59dc7d2b68f4
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
namespace HStation.WinFrmUI
{
    public partial class EditXhsProjectDlg : DevExpress.XtraEditors.XtraForm
    {
        public EditXhsProjectDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.layoutControl1.SetupLayoutControl();
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
 
        /// <summary>
        /// 重载数据
        /// </summary>
        public event Action<XhsProjectExtensionsVmo> ReloadDataEvent;
 
        private XhsProjectExtensionsVmo _project = null;//项目
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData(XhsProjectExtensionsVmo project)
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            this.txtName.EditValue = project.Name;
            this.txtNO.EditValue = project.NO;
            this.txtCustomer.EditValue = project.Customer;
            var allFlagsList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Xhs.DataType.XhsProject);
            this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), project.Flags);
            this.txtTagName.EditValue = project.TagName;
            this.txtAddress.EditValue = project.Address;
            this.txtDescription.EditValue = project.Description;
        }
 
        //数据验证
        private async Task<bool> Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(txtName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtName, "必填项");
                return false;
            }
            var tagname = this.txtTagName.Text.Trim();
            if (!string.IsNullOrEmpty(tagname))
            {
                if (await BLLFactory<HStation.BLL.XhsProject>.Instance.IsExistTagNameExceptID(tagname, _project.ID))
                {
                    this.dxErrorProvider1.SetError(this.txtTagName, "重复");
                    return false;
                }
            }
            return true;
        }
 
        //确定
        private async void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (_project == null)
            {
                return;
            }
            if (!await Valid())
            {
                return;
            }
            _project.Name = this.txtName.Text.Trim();
            _project.NO = this.txtNO.Text.Trim();
            _project.Customer = this.txtCustomer.Text.Trim();
            _project.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
            _project.Address = this.txtAddress.Text.Trim();
            _project.TagName = this.txtTagName.Text.Trim();
            _project.Description = this.txtDescription.Text.Trim();
 
            var bol = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.Update(_project);
            if (!bol)
            {
                TipFormHelper.ShowError("更新失败!");
                return;
            }
 
            var project = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.GetByID(_project.ID);
            this.ReloadDataEvent?.Invoke(project);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
    }
}