Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
 
namespace IStation.WinFrmUI.Monitor
{
    /// <summary>
    ///   
    /// </summary>
    public partial class BoxSelectPointsDlg : XtraForm
    {
        public BoxSelectPointsDlg()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
        }
 
        public event Func<DateTime, bool> RemovePointEvent;
        public event Func<List<Model.CurveAnalyzePoint>, bool> ReloadDataEvent;
        private BindingList<Model.CurveAnalyzePoint> _bindingList = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary> 
        public void Set(List<Model.CurveAnalyzePoint> checkPoints)
        {
            if (checkPoints != null && checkPoints.Any())
            {
                checkPoints.ForEach(x => x.Round());
                _bindingList = new BindingList<Model.CurveAnalyzePoint>(checkPoints);
            }
            else
            {
                _bindingList = new BindingList<Model.CurveAnalyzePoint>();
            }
 
 
            this.curveAnalyzePointBindingSource.DataSource = _bindingList;
            this.curveAnalyzePointBindingSource.ResetBindings(false);
            this.gridView1.BestFitColumns();
        }
 
        //验证
        public bool Valid()
        {
            this.gridView1.CloseEditor();
            this.gridView1.UpdateCurrentRow();
            if (_bindingList.Count > 0)
            {
                for (int i = 0; i < _bindingList.Count; i++)
                {
                    var vm = _bindingList[i];
                    if (string.IsNullOrEmpty(vm.HZ.ToString()))
                    {
                        this.gridView1.FocusedRowHandle = i;
                        this.gridView1.SetColumnError(this.colHz, "必填项");
                        return false;
                    }
 
                    if (string.IsNullOrEmpty(vm.Q.ToString()))
                    {
                        this.gridView1.FocusedRowHandle = i;
                        this.gridView1.SetColumnError(this.colHz, "必填项");
                        return false;
                    }
 
                }
            }
            return true;
        }
 
        #region GridView 
 
        //删除
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (_bindingList == null || _bindingList.Count < 1)
                return;
            if (e.Column == this.colDelete)
            {
                var row = this.gridView1.GetFocusedRow() as Model.CurveAnalyzePoint;
                if (row == null)
                    return;
                if (this.RemovePointEvent != null)
                {
                    var bol = this.RemovePointEvent(row.Time);
                    if (bol)
                    {
                        _bindingList.Remove(row);
                    }
                }
            }
        }
 
 
        #endregion
 
 
    }
}