lixiaojun
2025-02-13 bfd1b73be85fd66ee37031eadcd4d09e7dafb52f
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
namespace Yw.WinFrmUI
{
    public partial class HydroSinglePumpListExtendGridCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public HydroSinglePumpListExtendGridCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalEditView();
            this.colName.OptionsColumn.AllowEdit = false;
            this.colN.OptionsColumn.AllowEdit = false;
        }
 
        /// <summary>
        /// 状态改变事件
        /// </summary>
        public event Action<List<HydroSinglePumpListItemExtendViewModel>> StateChangedEvent;
 
        private BindingList<HydroSinglePumpListItemExtendViewModel> _allBindingList = null;//绑定列表
 
        /// <summary>
        /// 是否改变
        /// </summary>
        public bool HasChanged { get; set; }
 
 
        /// <summary>
        /// 
        /// </summary>
        public void SetBindingData(Yw.Model.HydroPumpInfo pump)
        {
            if (pump == null)
            {
                return;
            }
            var list = new List<HydroSinglePumpListItemExtendViewModel>()
            {
                new HydroSinglePumpListItemExtendViewModel(pump,true),
                new HydroSinglePumpListItemExtendViewModel(pump,false)
            };
            SetBindingData(list);
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void SetBindingData(List<HydroSinglePumpListItemExtendViewModel> allList)
        {
            _allBindingList = new BindingList<HydroSinglePumpListItemExtendViewModel>();
            allList?.ForEach(x => _allBindingList.Add(x));
            this.hydroSinglePumpListItemExtendViewModelBindingSource.DataSource = _allBindingList;
            this.hydroSinglePumpListItemExtendViewModelBindingSource.ResetBindings(false);
        }
 
        /// <summary>
        /// 获取状态列表
        /// </summary>
        public List<HydroSinglePumpListItemExtendViewModel> GetStateList()
        {
            return _allBindingList?.ToList();
        }
 
        //值改变事件
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            this.HasChanged = true;
            this.StateChangedEvent?.Invoke(_allBindingList?.ToList());
        }
 
        private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            var vm = this.gridView1.GetFocusedRow() as HydroSinglePumpListItemExtendViewModel;
            if (vm == null)
            {
                return;
            }
            if (vm.IsRated)
            {
                e.Cancel = true;
            }
        }
    }
}