lixiaojun
2024-11-08 571fb22bfd7ca4b0ca49328be3a3e91c0e3fed0d
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
namespace Yw.WinFrmUI
{
    public partial class HydroParterSearchListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public HydroParterSearchListCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.searchControl1.SetSearchSettings(Search, Recover);
        }
 
        /// <summary>
        /// 水力点击事件
        /// </summary>
        public event Action<Yw.Model.HydroParterInfo> HydroClickEvent;
 
        /// <summary>
        /// 水力查询事件
        /// </summary>
        public event Action<List<Yw.Model.HydroParterInfo>> HydroSearchEvent;
 
        //获取水力信息方法
        private Func<Yw.Model.HydroModelInfo> _hydroInfoFunc = null;
        //所有绑定列表
        private List<HydroParterViewModel> _allBindingList = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitialData(Func<Yw.Model.HydroModelInfo> hydroInfoFunc)
        {
            _hydroInfoFunc = hydroInfoFunc;
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(string content)
        {
            this.searchControl1.EditValue = content;
            Search(null, null);
        }
 
        //查询
        private void Search(object sender, EventArgs e)
        {
            var condition = this.searchControl1.Text.Trim();
            if (string.IsNullOrEmpty(condition))
            {
                return;
            }
            var hydroInfo = _hydroInfoFunc?.Invoke();
            if (hydroInfo == null)
            {
                return;
            }
            var allParterList = hydroInfo.GetAllParters();
            var parters = allParterList?.Where(x => (!string.IsNullOrEmpty(x.Code) && x.Code.Contains(condition))
                || (!string.IsNullOrEmpty(x.Name) && x.Name.Contains(condition))
                || (!string.IsNullOrEmpty(x.Catalog) && x.Catalog.Contains(condition))
                || (!string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(condition))
                ).ToList();
            _allBindingList = new List<HydroParterViewModel>();
            if (parters != null && parters.Count > 0)
            {
                foreach (var parter in parters)
                {
                    var vm = new HydroParterViewModel(parter, hydroInfo);
                    _allBindingList.Add(vm);
 
                }
            }
            this.hydroParterViewModelBindingSource.DataSource = _allBindingList;
            this.hydroParterViewModelBindingSource.ResetBindings(false);
            this.HydroSearchEvent?.Invoke(_allBindingList?.Select(x => x.Vmo).ToList());
        }
 
        //覆盖
        private void Recover(object sender, EventArgs e)
        {
            var hydroInfo = _hydroInfoFunc?.Invoke();
            if (hydroInfo == null)
            {
                return;
            }
            this.HydroSearchEvent?.Invoke(null);
        }
 
        //行点击事件
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as HydroParterViewModel;
            if (row == null)
            {
                return;
            }
            this.HydroClickEvent?.Invoke(row.Vmo);
        }
 
 
    }
}