lixiaojun
2024-11-04 3effbd15ec04bbc39514c6904fa71d00631c96eb
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using DevExpress.XtraEditors.Repository;
 
namespace Yw.WinFrmUI
{
    public partial class SetHydroGradingModelCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SetHydroGradingModelCtrl()
        {
            InitializeComponent();
            this.gridView1.SetBindingLimitEditView();
        }
 
        private long _modelId;//模型id
        private string _catalog;//分类
        private string _propName;//属性名称
        private List<SetHydroGradingModelViewModel> _allList = null;
        private BindingList<SetHydroGradingModelViewModel> _allBindingList = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitialData(List<Yw.Vmo.HydroGradingVmo> allList)
        {
            _allList = new List<SetHydroGradingModelViewModel>();
            allList?.ForEach(x =>
            {
                _allList.Add(new SetHydroGradingModelViewModel(x));
            });
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(long modelId, string catalog, string propName)
        {
            _modelId = modelId;
            _catalog = catalog;
            _propName = propName;
            _allBindingList = new BindingList<SetHydroGradingModelViewModel>();
            var list = _allList?.Where(x => x.ModelID == modelId && x.Catalog == catalog && x.PropName == propName).OrderBy(x => x.SortCode).ToList();
            list?.ForEach(x =>
            {
                _allBindingList.Add(x);
            });
            this.setHydroGradingModelViewModelBindingSource.DataSource = _allBindingList;
            this.setHydroGradingModelViewModelBindingSource.ResetBindings(false);
            ResetColumns();
        }
 
        /// <summary>
        /// 重新绑定数据
        /// </summary>
        public void ResetBindingData()
        {
            SetBindingData(_modelId, _catalog, _propName);
        }
 
        //设置列
        private void ResetColumns()
        {
            switch (_propName)
            {
                case Yw.Hydro.ParterProp.LinkStatus:
                    {
                        ResetColumns(false);
                    }
                    break;
                case Yw.Hydro.ParterProp.CalcuPress:
                    {
                        ResetColumns(true);
                    }
                    break;
                case Yw.Hydro.ParterProp.CalcuHead:
                    {
                        ResetColumns(true);
                    }
                    break;
                case Yw.Hydro.ParterProp.CalcuFlow:
                    {
                        ResetColumns(true);
                    }
                    break;
                case Yw.Hydro.ParterProp.CalcuVelocity:
                    {
                        ResetColumns(true);
                    }
                    break;
                case Yw.Hydro.ParterProp.CalcuHeadLoss:
                    {
                        ResetColumns(true);
                    }
                    break;
                default:
                    {
 
                    }
                    break;
            }
        }
 
        //设置列
        private void ResetColumns(bool numeric)
        {
            this.colSetValue.Visible = false;
            this.colMinValue.Visible = false;
            this.colMaxValue.Visible = false;
            this.colColor.Visible = false;
            this.colDelete.Visible = false;
            this.colSetValue.Visible = !numeric;
            this.colMinValue.Visible = numeric;
            this.colMaxValue.Visible = numeric;
            this.colColor.Visible = true;
            this.colDelete.Visible = true;
        }
 
        /// <summary>
        /// 获取评级
        /// </summary>
        public List<Yw.Vmo.HydroGradingVmo> GetGrading()
        {
            var list = new List<Yw.Vmo.HydroGradingVmo>();
            _allList?.ForEach(x =>
            {
                var vmo = new Yw.Vmo.HydroGradingVmo()
                {
                    ID = x.ID,
                    ModelID = x.ModelID,
                    Catalog = x.Catalog,
                    PropName = x.PropName,
                    SetValue = x.SetValue,
                    MinValue = x.MinValue,
                    MaxValue = x.MaxValue,
                    Color = ColorTranslator.ToHtml(x.Color),
                    SortCode = x.SortCode,
                    Description = x.Description
                };
                list.Add(vmo);
            });
            return list;
        }
 
        //自定义下拉框
        private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column == this.colSetValue)
            {
                switch (_propName)
                {
                    case Yw.Hydro.ParterProp.LinkStatus:
                        {
                            var repositoryItem = new RepositoryItemImageComboBox();
                            switch (_catalog)
                            {
                                case Yw.Hydro.ParterCatalog.Pipe:
                                    {
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Open), Yw.Hydro.LinkStatus.Open, -1);
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Closed), Yw.Hydro.LinkStatus.Closed, -1);
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.CV), Yw.Hydro.LinkStatus.CV, -1);
                                    }
                                    break;
                                case Yw.Hydro.ParterCatalog.Pump:
                                    {
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Open), Yw.Hydro.LinkStatus.Open, -1);
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Closed), Yw.Hydro.LinkStatus.Closed, -1);
                                    }
                                    break;
                                case Yw.Hydro.ParterCatalog.Valve:
                                    {
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.None), Yw.Hydro.LinkStatus.None, -1);
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Open), Yw.Hydro.LinkStatus.Open, -1);
                                        repositoryItem.Items.Add(HydroLinkStatusHelper.GetStatusName(Yw.Hydro.LinkStatus.Closed), Yw.Hydro.LinkStatus.Closed, -1);
                                    }
                                    break;
                                default: break;
                            }
                            e.RepositoryItem = repositoryItem;
                        }
                        break;
                    default: break;
                }
            }
        }
 
        //初始化
        private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as SetHydroGradingModelViewModel;
            if (row != null)
            {
                row.ModelID = _modelId;
                row.Catalog = _catalog;
                row.PropName = _propName;
                row.SortCode = _allBindingList == null || _allBindingList.Count < 1 ? 1 : _allBindingList.Max(x => x.SortCode) + 1;
                _allList.Add(row);
            }
        }
 
        //编辑框显示
        private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(_propName))
            {
                e.Cancel = true;
            }
        }
 
        //删除
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Column == this.colDelete)
            {
                var row = this.gridView1.GetRow(e.RowHandle) as SetHydroGradingModelViewModel;
                if (row != null)
                {
                    _allBindingList?.Remove(row);
                    _allList?.Remove(row);
                }
            }
        }
 
 
    }
}