Shuxia Ning
2024-10-23 47610ca1dd9075a2f0b58cbdb010b66aa95e78d2
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
namespace HStation.WinFrmUI.Xhs
{
    public partial class SinglePumpAnalyInfoCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SinglePumpAnalyInfoCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalEditView();
            this.gridView2.SetNormalView();
            this.gridView3.SetNormalView(); 
 
            this.repColor.ColorAlignment = DevExpress.Utils.HorzAlignment.Center;
            this.repColor.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            this.repColor.ButtonsStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
 
            this.colName.OptionsColumn.AllowEdit = false;
            this.colName.OptionsColumn.ReadOnly = true;
 
            this.colColor.OptionsColumn.AllowEdit = false;
            this.colColor.OptionsColumn.ReadOnly = true;
 
            this.gridView1.ShowingEditor += GridView1_ShowingEditor; ;
        }
 
      
 
 
 
 
        /// <summary>
        /// 设置曲线
        /// </summary> 
        public event Action<string,double,double, Yw.Geometry.CubicSpline2d, Yw.Geometry.CubicSpline2d, Yw.Geometry.CubicSpline2d> SetEvent;
 
        /// <summary>
        /// 设置曲线信息
        /// </summary> 
        public event Action<string,Color> SetInfoEvent;
 
        /// <summary>
        /// 设置设计点
        /// </summary> 
        public event Action<double, double> SetDesignPointEvent;
 
        private List<SinglePumpAnalyViewModel> _all_binding_list = null;
 
        
        public void SetBindingData(List<SinglePumpAnalyViewModel> vm_list)
        {
            _all_binding_list = new List<SinglePumpAnalyViewModel>();
            if (vm_list != null && vm_list.Any())
            {
                _all_binding_list = vm_list.Select(x => new SinglePumpAnalyViewModel(x)).ToList();
            }
 
            this.singlePumpAnalyViewModelBindingSource.DataSource = _all_binding_list;
            this.singlePumpAnalyViewModelBindingSource.ResetBindings(false);
            this.gridView1.BestFitColumns();
        }
 
        public void SetDesignPoint(double flow, double head)
        {
            this.txtDesignQ.EditValue = flow;
            this.txtDesignH.EditValue = head;
        }
 
        /// <summary>
        /// 获取列表
        /// </summary> 
        public List<SinglePumpAnalyViewModel> GetList()
        {
            if (_all_binding_list == null || !_all_binding_list.Any())
            {
                return default;
            }
            return _all_binding_list.Select(x => new SinglePumpAnalyViewModel(x)).ToList();
        }
 
        //验证
        private void GridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            if (this.gridView1.FocusedColumn != this.colCurrentHz)
            {
                var vm = this.gridView1.GetFocusedRow() as SinglePumpAnalyViewModel;
                if (vm.IsDefault)
                {
                    e.Cancel = true;
                }
            }
        }
 
 
        //值变换
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        { 
            if (e.Column == this.colCurrentHz)
            {
                var vm = this.gridView1.GetRow(e.RowHandle) as SinglePumpAnalyViewModel;
                if (vm.CurrentHz < 10 || vm.CurrentHz > 50)
                {
                    return;
                }
                vm.Calc();
                this.SetEvent?.Invoke(vm.Id,vm.CurrentHz,vm.ExtendRatio, vm.QhCalc, vm.QeCalc, vm.QpCalc);
            }
            else if (e.Column == this.colExtendRatio)
            {
                var vm = this.gridView1.GetRow(e.RowHandle) as SinglePumpAnalyViewModel;
                vm.Calc();
                this.SetEvent?.Invoke(vm.Id, vm.CurrentHz, vm.ExtendRatio, vm.QhCalc, vm.QeCalc, vm.QpCalc);
            }
        }
 
        /// <summary>
        /// 设置查询信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="query_pt"></param>
        public void SetQueryInfo(string id, Yw.WinFrmUI.Phart.PumpGroupPt query_pt)
        {
            if (query_pt == null)
                return;
            if (_all_binding_list == null || !_all_binding_list.Any())
                return;
            var vm = _all_binding_list.Find(x => x.Id == id);
            if (vm == null)
                return;
            vm.QueryQ = query_pt.Q > 0 ? $"{query_pt.Q:N1}" : string.Empty;
            vm.QueryH = query_pt.H > 0 ? $"{query_pt.H:N1}" : string.Empty;
            vm.QueryE = query_pt.E > 0 ? $"{query_pt.E:N1}" : string.Empty;
            vm.QueryP = query_pt.P > 0 ? $"{query_pt.P:N1}" : string.Empty;
            this.singlePumpAnalyViewModelBindingSource.ResetBindings(false);
        }
 
        //设置设计点
        private void btnSetDesignPoint_Click(object sender, EventArgs e)
        {
            if (!double.TryParse(this.txtDesignQ.Text, out double design_q))
                return;
            if (!double.TryParse(this.txtDesignH.Text, out double design_h))
                return;
 
            this.SetDesignPointEvent?.Invoke(design_q, design_h);
        }
 
 
    }
}