duheng
2025-03-28 b266e82b9a377fa35a766f7a3a2f5aa95f3c9125
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
using DevExpress.XtraEditors.Repository;
 
namespace Yw.WinFrmUI
{
    public partial class SetHydroEvaluationModelCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SetHydroEvaluationModelCtrl()
        {
            InitializeComponent();
            this.gridView1.SetBindingLimitEditView();
        }
 
        private long _modelId;//模型id
        private string _catalog;//分类
        private List<SetHydroEvaluationModelViewModel> _allList = null;
        private BindingList<SetHydroEvaluationModelViewModel> _allBindingList = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitialData(List<Yw.Vmo.HydroEvaluationVmo> allList)
        {
            _allList = new List<SetHydroEvaluationModelViewModel>();
            allList?.ForEach(x =>
            {
                _allList.Add(new SetHydroEvaluationModelViewModel(x));
            });
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(long modelId, string catalog)
        {
            _modelId = modelId;
            _catalog = catalog;
            _allBindingList = new BindingList<SetHydroEvaluationModelViewModel>();
            var list = _allList?.Where(x => x.ModelID == modelId && x.Catalog == catalog).OrderBy(x => x.SortCode).ToList();
            list?.ForEach(x =>
            {
                _allBindingList.Add(x);
            });
            this.setHydroEvaluationModelViewModelBindingSource.DataSource = _allBindingList;
            this.setHydroEvaluationModelViewModelBindingSource.ResetBindings(false);
        }
 
        /// <summary>
        /// 获取评价
        /// </summary>
        public List<Yw.Vmo.HydroEvaluationVmo> GetEvaluation()
        {
            var list = new List<Yw.Vmo.HydroEvaluationVmo>();
            _allList?.ForEach(x =>
            {
                var vmo = new Yw.Vmo.HydroEvaluationVmo()
                {
                    ID = x.ID,
                    ModelID = x.ModelID,
                    Catalog = x.Catalog,
                    EvaluateType = x.EvaluateType,
                    EvaluateLower = x.EvaluateLower,
                    EvaluateUpper = x.EvaluateUpper,
                    EvaluateContent = x.EvaluateContent,
                    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.colEvaluateType)
            {
                var dict = HydroEvaluationTypeHelper.GetDict(_catalog);
                if (dict != null && dict.Count > 0)
                {
                    var repositoryItem = new RepositoryItemImageComboBox();
                    foreach (var item in dict)
                    {
                        repositoryItem.Items.Add(item.Value, item.Key, -1);
                    }
                    e.RepositoryItem = repositoryItem;
                }
            }
        }
 
        //初始化
        private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as SetHydroEvaluationModelViewModel;
            if (row != null)
            {
                row.ModelID = _modelId;
                row.Catalog = _catalog;
                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 (_allBindingList == null)
            {
                e.Cancel = true;
                return;
            }
            var row = this.gridView1.GetFocusedRow() as SetHydroEvaluationModelViewModel;
            if (row == null)
            {
                var col = this.gridView1.FocusedColumn;
                if (col != this.colEvaluateType)
                {
                    e.Cancel = true;
                    return;
                }
            }
        }
 
        //删除
        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 SetHydroEvaluationModelViewModel;
                if (row != null)
                {
                    _allBindingList?.Remove(row);
                    _allList?.Remove(row);
                }
            }
        }
 
 
    }
}