duheng
2025-03-31 be65218617cab71a90a9a05cf488fbb6e206b5c5
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using DevExpress.Mvvm.Native;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraTreeList;
using System.Windows.Forms;
using Yw;
 
namespace PBS.WinFrmUI
{
    public partial class FacilitiesCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public FacilitiesCtrl()
        {
            InitializeComponent();
        }
 
        //基础验证
        public bool Valid()
        {
            bool isExist = true;
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtName, "必填项");
                isExist = false;
            }
            if (string.IsNullOrEmpty(this.txtFloor.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtFloor, "必填项");
                isExist = false;
            }
            if (string.IsNullOrEmpty(this.txtFloorHeight.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtFloorHeight, "必填项");
                isExist = false;
            }
            if (string.IsNullOrEmpty(this.txtFloorHouseHolds.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtFloorHouseHolds, "必填项");
                isExist = false;
            }
            if (string.IsNullOrEmpty(this.txtConstantP.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtConstantP, "必填项");
                isExist = false;
            }
            if (this.textEditWaterModel.EditValue == null)
            {
                this.dxErrorProvider1.SetError(this.textEditWaterModel, "必填项");
                isExist = false;
            }
            if (this.comboBoxWaterSupply.Text == "请选择")
            {
                this.dxErrorProvider1.SetError(this.comboBoxWaterSupply, "必填项");
                isExist = false;
            }
            if (string.IsNullOrEmpty(this.txtMaxWaterDemand.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtMaxWaterDemand, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtWaterPressure.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtWaterPressure, "必填项");
                return false;
            }
            return isExist;
        }
 
        private Vmo.FacilityVmo _facilityVmo = new Vmo.FacilityVmo();
 
        public async Task SetBindingData()
        {
            this.textEditWaterModel.Properties.AddEnum(typeof(PBS.eSupplyMode));
            /*          textEditWaterModel.Properties.LargeImages = imageCollection1;
                      foreach (PBS.eSupplyMode mode in Enum.GetValues(typeof(PBS.eSupplyMode)))
                      {
                          int imageIndex = (int)mode; // 假设图片索引和枚举值顺序一致
                          textEditWaterModel.Properties.Items.Add(new DevExpress.XtraEditors.Controls.ImageComboBoxItem(mode.ToString(), mode, imageIndex));
                      }*/
            this.comboBoxWaterSupply.Properties.AddEnum(typeof(PBS.eWaterSupply));
            var allPackages = await new HStation.BLL.AssetsPackageMain().GetAll();
            foreach (var item in allPackages)
            {
                var imageItem = new ImageComboBoxItem(item.Name, item.ID);
                this.comboBoxPackages.Properties.Items.Add(imageItem);
            }
            var list = await new PBS.BLL.Place().GetAll();
            var model = list.Select(x => new PlaceSelectViewModel(x)).ToList();
            var regionIdList = model.GroupBy(x => x.ParentID).Select(y => y.Key).ToList();
            if (regionIdList != null && regionIdList.Count > 0)
            {
                var placeList = await new Yw.BLL.Division().GetByIds(regionIdList);
                foreach (var item in placeList)
                {
                    model.Add(new PlaceSelectViewModel
                    {
                        ID = item.ID,
                        Name = item.Name
                    });
                }
            }
            this.treeListLookUpEdit1TreeList.DataSource = model;
            this.imageComboBoxConnectionType.Properties.AddEnum(typeof(PBS.eConnectionType));
            this.imageComboBoxConnectionType.SelectedIndex = 1;
        }
 
        public async void SetData(Vmo.FacilityVmo model)
        {
            _facilityVmo = model;
            this.txtName.EditValue = model.Name;
            this.txtFloor.EditValue = model.Floor;
            this.txtFloorHouseHolds.EditValue = model.Households;
            this.txtFloorHeight.EditValue = model.FloorHeight;
            this.txtMaxWaterDemand.EditValue = model.MaxWaterDemand;
            this.txtWaterPressure.EditValue = model.TerminalPressure;
            this.comboBoxWaterSupply.EditValue = model.WaterSupply;
            this.txtConstantP.EditValue = model.ConstantPressure;
            this.textEditWaterModel.EditValue = model.SupplyMode;
            this.txtEditPlace.EditValue = model.PlaceID;
            this.comboBoxPackages.EditValue = model.PackageID;
            this.imageComboBoxConnectionType.EditValue = model.ConnectionType;
            this.textEditConnectionAddress.EditValue = model.ConnectionAddress;
            this.textEditMaxHeight.EditValue = model.MaxHeight;
            this.txtDescription.EditValue = model.Description;
            var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.FourlinkMain);
            this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), model.Flags);
            this.txtTagName.EditValue = model.TagName;
        }
 
        //获取文本信息
        public Vmo.FacilityVmo GetData()
        {
            if (!Valid())
                return null;
            _facilityVmo.Floor = int.Parse(txtFloor.Text);
            _facilityVmo.Name = txtName.Text;
            if (this.textEditWaterModel.EditValue != null)
            {
                _facilityVmo.SupplyMode = (PBS.eSupplyMode)this.textEditWaterModel.EditValue;
            }
            _facilityVmo.UseStatus = Yw.Vmo.eUseStatus.Enable;
            _facilityVmo.FloorHeight = double.Parse(txtFloorHeight.Text);
            _facilityVmo.Households = int.Parse(txtFloorHouseHolds.Text);
            _facilityVmo.ConstantPressure = double.Parse(txtConstantP.Text);
            _facilityVmo.MaxWaterDemand = Convert.ToDouble(txtMaxWaterDemand.EditValue);
            _facilityVmo.TerminalPressure = Convert.ToDouble(txtWaterPressure.EditValue);
            if (this.comboBoxPackages.EditValue != null)
            {
                _facilityVmo.PackageID = (long)this.comboBoxPackages.EditValue;
            }
            if (this.txtEditPlace.EditValue != null)
            {
                _facilityVmo.PlaceID = Convert.ToInt64(this.txtEditPlace.EditValue);
            }
            if (comboBoxWaterSupply.EditValue != null)
            {
                _facilityVmo.WaterSupply = (PBS.eWaterSupply)comboBoxWaterSupply.EditValue;
            }
            if (this.imageComboBoxConnectionType.EditValue != null)
            {
                _facilityVmo.ConnectionType = (PBS.eConnectionType)this.imageComboBoxConnectionType.EditValue;
            }
            _facilityVmo.ConnectionAddress = this.textEditConnectionAddress.Text;
            if (this.textEditMaxHeight.EditValue != null)
            {
                double.TryParse(this.textEditMaxHeight.Text, out double maxHeight);
                _facilityVmo.MaxHeight = maxHeight;
            }
            _facilityVmo.TagName = txtTagName.Text.Trim();
            _facilityVmo.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
            _facilityVmo.Description = txtDescription.Text;
            return _facilityVmo;
        }
 
        private void treeListLookUpEdit1TreeList_BeforeFocusNode(object sender, BeforeFocusNodeEventArgs e)
        {
            TreeList treeList = sender as TreeList;
            if (treeList != null)
            {
                // 检查当前焦点节点是否为父节点
                if (e.Node.HasChildren)
                {
                    e.CanFocus = false;
                }
            }
        }
    }
}