duheng
2025-02-07 c5136b7517998a076f1bd2e4abdda01decae8b6f
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using DevExpress.Charts.Native;
using DevExpress.XtraEditors;
using Eventech.Common;
using IStation.WinFrmUI.Basic.basic.pumpmgr;
using System;
using System.ComponentModel;
using System.Linq;
 
namespace IStation.WinFrmUI.Basic
{
    /// <summary>
    /// 
    /// </summary>
    public partial class PumpMgrGridCtrl : XtraUserControl
    {
        public PumpMgrGridCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            this.layoutControl1.SetupLayoutControl();
        }
 
        public class CurrentViewModel : Model.Product<Model.Pump>
        {
            public CurrentViewModel() { }
            public CurrentViewModel(Model.Product<Model.Pump> rhs) : base(rhs)
            {
                if (rhs.RatedParas != null)
                {
                    this.Qr = rhs.RatedParas.Qr;
                    this.Hr = rhs.RatedParas.Hr;
                    this.Nr = rhs.RatedParas.Nr;
                    this.Pr = rhs.RatedParas.Pr;
                    this.Er = rhs.RatedParas.Er;
                    this.NPSHr = rhs.RatedParas.NPSHr;
                    this.StNumr = rhs.RatedParas.StNumr;
                    this.Ic = rhs.RatedParas.Ic;
                    this.Oc = rhs.RatedParas.Oc;
                    this.IOd = rhs.RatedParas.IOd;
                    this.IsBp = rhs.RatedParas.IsBp ? "是" : "否";
                    this.IsSxp = rhs.RatedParas.IsSxp ? "是" : "否";
                }
            }
            public double Qr { get; set; }
            public double Hr { get; set; }
            public double Nr { get; set; }
            public double Pr { get; set; }
            public double Er { get; set; }
            public double NPSHr { get; set; }
            public int StNumr { get; set; }
            public double? Ic { get; set; }
            public double? Oc { get; set; }
            public double? IOd { get; set; }
            public string IsBp { get; set; }
            public string IsSxp { get; set; }
 
            public void Reset(CurrentViewModel vm)
            {
                base.Reset(vm);
                if (vm.RatedParas != null)
                {
                    this.Qr = vm.Qr;
                    this.Hr = vm.Hr;
                    this.Nr = vm.Nr;
                    this.Pr = vm.Pr;
                    this.Er = vm.Er;
                    this.NPSHr = vm.NPSHr;
                    this.StNumr = vm.StNumr;
                    this.Ic = vm.Ic;
                    this.Oc = vm.Oc;
                    this.IOd = vm.IOd;
                    this.IsBp = vm.IsBp;
                    this.IsSxp = vm.IsSxp;
                }
            }
 
            public void Reset(Model.Product<Model.Pump> rhs)
            {
                base.Reset(rhs);
                if (rhs.RatedParas != null)
                {
                    this.Qr = rhs.RatedParas.Qr;
                    this.Hr = rhs.RatedParas.Hr;
                    this.Nr = rhs.RatedParas.Nr;
                    this.Pr = rhs.RatedParas.Pr;
                    this.Er = rhs.RatedParas.Er;
                    this.NPSHr = rhs.RatedParas.NPSHr;
                    this.StNumr = rhs.RatedParas.StNumr;
                    this.Ic = rhs.RatedParas.Ic;
                    this.Oc = rhs.RatedParas.Oc;
                    this.IOd = rhs.RatedParas.IOd;
                    this.IsBp = rhs.RatedParas.IsBp ? "是" : "否";
                    this.IsSxp = rhs.RatedParas.IsSxp ? "是" : "否";
                }
            }
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary> 
        public event Action<Model.Product<Model.Pump>> FocusedChangedEvent;
 
        private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
        
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Clear()
        {
            _allBindingList = new BindingList<CurrentViewModel>();
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.FocusedChangedEvent?.Invoke(null);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            WaitFrmHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new BindingList<CurrentViewModel>();
 
            var pumps = new BLL.Product().GetAllPump();
            if (pumps != null && pumps.Any())
            {
                foreach (var pump in pumps)
                {
                    var vm = new CurrentViewModel(pump);
                    _allBindingList.Add(vm);
                }
            }
 
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.gridView1.BestFitColumns();
            WaitFrmHelper.HideWaitForm();
        }
        //修改泵基础信息
        public void EditPumpMgr()
        {
            var row = gridView1.GetCurrentViewModel(_allBindingList);
            if (row == null)
                return;
            var dlg = new EditPumpDlg();
            dlg.SetBindingData(row);
            dlg.ReLoadDataevent += (pump_info) =>
            {
                var bll = new BLL.Product();
                var model = new Model.Product(pump_info);
                model.RatedParas = pump_info.RatedParas.ToJson();
                var isok = bll.Update(model);
                if (isok)
                {
                    row.Reset(pump_info);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        //添加泵基础信息
        public void AddPump()
        {
            var dlg = new AddPumpDlg();
            dlg.SetbindingData();
            dlg.ReloadBingData += (pump) =>
            {
                var bll=new BLL.Product();
                var model=new Model.Product(pump);
                model.RatedParas=pump.RatedParas.ToJson();
                var isok=bll.Insert(model);
                if (isok>0)
                {
                    this.SetBindingData();
                    return true;
                }
                
                return false;
            };
          
            dlg.ShowDialog();
          
        }
 
       
    }
}