lixiaojun
2024-11-09 c9585ab171fb973d16792d7a290994bf8279da63
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
namespace Yw.WinFrmUI
{
    public partial class SetHydroTranslationDlg : DevExpress.XtraEditors.XtraForm
    {
        public SetHydroTranslationDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.layoutControl1.SetupLayoutControl();
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
            InitialLinkStatus();
        }
 
        /// <summary>
        /// 重载数据事件
        /// </summary>
        public event Action<List<Yw.Model.HydroTranslationInfo>> ReloadDataEvent;
 
        //所有部件列表
        private List<Yw.Model.HydroTranslationInfo> _allParterList = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Yw.Model.HydroTranslationInfo parter)
        {
            var allParterList = parter == null ? null : new List<Yw.Model.HydroTranslationInfo>() { parter };
            this.SetBindingData(allParterList);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(List<Yw.Model.HydroTranslationInfo> allParterList)
        {
            _allParterList = allParterList;
            if (_allParterList != null && _allParterList.Count == 1)
            {
                var parter = _allParterList.First();
                this.imgCmbLinkStatus.EditValue = parter.LinkStatus;
                this.txtMaterial.EditValue = parter.Material;
                this.txtDiameter.EditValue = parter.Diameter;
                this.txtLength.EditValue = parter.Length;
                this.txtRoughness.EditValue = parter.Roughness;
                this.txtMinorLoss.EditValue = parter.MinorLoss;
            }
        }
 
        //初始化管段状态
        private void InitialLinkStatus()
        {
            this.imgCmbLinkStatus.Properties.BeginUpdate();
            this.imgCmbLinkStatus.Properties.Items.Clear();
            this.imgCmbLinkStatus.Properties.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Open), Yw.Hydro.LinkStatus.Open, -1);
            this.imgCmbLinkStatus.Properties.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Closed), Yw.Hydro.LinkStatus.Closed, -1);
            this.imgCmbLinkStatus.Properties.EndUpdate();
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (this.imgCmbLinkStatus.EditValue == null)
            {
                this.dxErrorProvider1.SetError(this.imgCmbLinkStatus, "必选项");
                return false;
            }
            if (this.txtDiameter.EditValue == null)
            {
                this.dxErrorProvider1.SetError(this.txtDiameter, "必填项");
                return false;
            }
            if (this.txtLength.EditValue == null)
            {
                this.dxErrorProvider1.SetError(this.txtLength, "必填项");
                return false;
            }
            if (this.txtRoughness.EditValue == null)
            {
                this.dxErrorProvider1.SetError(this.txtRoughness, "必填项");
                return false;
            }
            if (this.txtMinorLoss.EditValue == null)
            {
                this.dxErrorProvider1.SetError(this.txtMinorLoss, "必填项");
                return false;
            }
            return true;
        }
 
        //确定
        private void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (_allParterList == null || _allParterList.Count < 1)
            {
                return;
            }
            if (!Valid())
            {
                return;
            }
            var linkStatus = this.imgCmbLinkStatus.EditValue.ToString();
            var material = this.txtMaterial.Text.Trim();
            var diameter = double.Parse(this.txtDiameter.EditValue.ToString());
            var length = double.Parse(this.txtLength.EditValue.ToString());
            var roughness = double.Parse(this.txtRoughness.EditValue.ToString());
            var minoroLoss = double.Parse(this.txtMinorLoss.EditValue.ToString());
            _allParterList.ForEach(x =>
            {
                x.LinkStatus = linkStatus;
                x.Material = material;
                x.Diameter = diameter;
                x.Length = length;
                x.Roughness = roughness;
                x.MinorLoss = minoroLoss;
            });
            this.ReloadDataEvent?.Invoke(_allParterList);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
    }
}