lixiaojun
2025-01-20 6e1306ab578ed1ad79fc33b0bb7e496b897bf4a4
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
using HStation.Vmo;
using Yw;
 
namespace HStation.WinFrmUI
{
    public partial class AddAssetsHydrantFactorDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddAssetsHydrantFactorDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.layoutControl1.SetupLayoutControl();
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
 
        private static AssetsHydrantFactorVmo _last = null;
 
        /// <summary>
        /// 返回数据事件
        /// </summary>
        public event Action<HStation.Vmo.AssetsHydrantFactorVmo> ReloadDataEvent;
 
        private HStation.Vmo.AssetsHydrantFactorVmo _vmo = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            _vmo = new Vmo.AssetsHydrantFactorVmo();
            if (_last != null)
            {
                this.txtName.EditValue = _last.Name;
                this.txtMinorLoss.EditValue = _last.MinorLoss;
                this.txtDiameter.EditValue = _last.Caliber;
                this.txtMaterial.EditValue = _last.Material;
                this.txtDescription.EditValue = _last.Description;
            }
        }
 
        //验证
        private 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()
        {
            if (_vmo == null)
            {
                return;
            }
            if (!Valid())
            {
                return;
            }
            _vmo.Name = this.txtName.Text.Trim();
            _vmo.MinorLoss = double.Parse(this.txtMinorLoss.EditValue?.ToString());
            _vmo.Caliber = this.txtDiameter.EditValue == null ? null : double.Parse(this.txtDiameter.EditValue?.ToString());
            _vmo.Material = this.txtMaterial.Text.Trim();
            _vmo.Description = this.txtDescription.Text.Trim();
            var id = await BLLFactory<HStation.BLL.AssetsHydrantFactor>.Instance.Insert(_vmo);
            if (id < 1)
            {
                TipFormHelper.ShowError("添加失败!");
                return;
            }
            var vmo = await BLLFactory<HStation.BLL.AssetsHydrantFactor>.Instance.GetByID(id);
            _last = vmo;
            this.ReloadDataEvent?.Invoke(vmo);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}