duheng
7 天以前 4de480ec624d3b79ca690dc906e10cd2fbdc9be7
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
 
 
namespace IStation.WinFrmUI.Basic
{
    public partial class CompareCurveParasListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        // 单位
 
        protected Eventech.Model.UnitQ _unitQ = Eventech.Model.UnitQ.M3H;
        protected Eventech.Model.UnitH _unitH = Eventech.Model.UnitH.M;
        protected Eventech.Model.UnitP _unitP = Eventech.Model.UnitP.KW;
        protected Eventech.Model.UnitH _unitNPSH = Eventech.Model.UnitH.M;
 
        #region 构造函数和加载函数
 
        public CompareCurveParasListCtrl()
        {
            InitializeComponent();
            _unitP = Eventech.Model.UnitP.KW;
            _unitQ = Eventech.Model.UnitQ.M3H;
            _unitH = Eventech.Model.UnitH.M;
 
            this.Load += new System.EventHandler(this.OnFrmLoad);
            this.gridView1.SetNormalEditView();
        }
 
        private void OnFrmLoad(object sender, EventArgs e)
        {
            this.gridView1.OptionsView.ShowGroupPanel = false;//隐藏最上面的GroupPanel
            this.gridView1.OptionsSelection.MultiSelect = false;//单选
            this.gridView1.OptionsBehavior.Editable = true;//
            this.gridView1.BestFitColumns();
            //this.gridView1.IndicatorWidth = 45;
 
            this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
            this.gridView1.OptionsView.EnableAppearanceOddRow = true;
 
 
 
            this.gridView1.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridView_RowClick);
            this.gridView1.CustomDrawCell += GridView_CustomDrawCell;
            this.gridView1.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanged);
            this.gridView1.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanging);
            this.gridView1.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridView_RowCellClick);
 
            this.gridControl1.DataSource = _bindList;
            //this.gridView1.BestFitColumns();
 
        }
 
 
 
        #endregion 构造函数和加载函数
 
        //
        internal class CurrentViewModel
        {
            public long ItemID { get; set; }
 
            public Color DispColor
            {
                set { _dispColor = value; }
                get { return _dispColor; }
            }
            private Color _dispColor = Color.Black;
 
            public string PumpName { get; set; }
            public string ProjectCode { get; set; }
            public string ProjectName { get; set; }
            public string PartCode { get; set; }
            public string TestTime { get; set; }
            public string PartName { get; set; }
            public string QueryPtQ { get; set; }
            public string QueryPtH { get; set; }
            public string QueryPtE { get; set; }
            public string QueryPtP { get; set; }
 
 
        }
 
        private BindingList<CurrentViewModel> _bindList = new BindingList<CurrentViewModel>();
 
        public Action<
            IStation.Model.PumpCurve,
            Color>
            OnAddTestItem = null;
        public Action<long> OnDeleteTestItem = null;
        public Action<long, Color> OnChangeColor = null;
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pumpCurve"></param>
        public void AddTestItem(
            string stationName,
             Model.Product<Model.Pump> pump,
            IStation.Model.PumpCurve pumpCurve)
        {
            foreach (var it in _bindList)
            {
                if (it.ItemID == pumpCurve.ID)
                {
                    return;
                }
            }
 
            if (pumpCurve.CurveInfo == null || pumpCurve.CurveInfo.CurveQH == null)
                return;
            var curveInfo = pumpCurve.CurveInfo;
            if (curveInfo.CurveQH == null)
                return;
 
            var color = GetCurveColor();
            if (OnAddTestItem != null)
            {
                OnAddTestItem(pumpCurve, color);
            }
 
 
            CurrentViewModel v = new CurrentViewModel();
            v.PumpName = pump.Name;
            v.ItemID = pumpCurve.ID;
            v.DispColor = color;
            v.ProjectCode = pumpCurve.CurveCode;
            v.ProjectName = stationName;
            v.TestTime = pumpCurve.CreateTime.ToString("yyyy-MM-dd HH:mm");
 
 
            v.PartCode = pump.ModelType;
            v.PartName = pump.Name;
 
 
            _bindList.Add(v);
        }
 
 
 
        private Color GetCurveColor()
        {
            for (int index = 0; index < 20; index++)
            {
                Color color =
                    index < ColorArray.Count ? ColorArray[index] : GetRandomColor();
                CurrentViewModel fff = null;
                foreach (var it in _bindList)
                    if (it.DispColor == color)
                    {
                        fff = it;
                        break;
                    }
                if (fff == null)
                    return color;
            }
            return Color.Black;
        }
        public int GetListCout()
        {
            return _bindList.Count;
        }
 
        public void ClearList()
        {
            _bindList.Clear();
        }
 
        #region 获取曲线的随机颜色
 
        private List<Color> ColorArray = new List<Color>() { Color.Red,
                        Color.Blue, Color.Green, Color.DodgerBlue,Color.Fuchsia,Color.MidnightBlue,Color.Maroon, Color.Aquamarine, Color.Bisque ,Color.BurlyWood };
 
 
 
        public Color GetRandomColor()
        {
            Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
            int int_Red = RandomNum_First.Next(256);
            Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
            int int_Green = RandomNum_Sencond.Next(256);
            int int_Blue = RandomNum_Sencond.Next(256);
            return Color.FromArgb(int_Red, int_Green, int_Blue);
        }
 
        #endregion 获取曲线的随机颜色
 
 
        public void SetQueryInfo(long id, Eventech.Model.GroupPoint queryPt)
        {
            if (queryPt == null || queryPt.Q < 0.1)
                return;
            var m = _bindList.First(x => x.ItemID == id);
            if (m == null) return;
 
            StringBuilder builder = new StringBuilder();
 
            m.QueryPtQ = string.Format("{0}  {1}",
IStation.Common.RoundHelper.GetDispValueFlow(Eventech.Common.UnitQHelper.fromM3H(_unitQ, queryPt.Q)),
Eventech.Common.UnitQHelper.GetEnUnitName(this._unitQ));
            builder.AppendFormat("Q:{0}  {1} ",
IStation.Common.RoundHelper.GetDispValueFlow(Eventech.Common.UnitQHelper.fromM3H(_unitQ, queryPt.Q)),
Eventech.Common.UnitQHelper.GetEnUnitName(this._unitQ));
 
 
            m.QueryPtH = string.Format("{0} {1}",
IStation.Common.RoundHelper.GetDispValueHead(Eventech.Common.UnitHHelper.fromM(_unitH, queryPt.H)),
Eventech.Common.UnitHHelper.GetEnUnitName(this._unitH));
            builder.AppendFormat("     H:{0}  {1} ",
IStation.Common.RoundHelper.GetDispValueHead(Eventech.Common.UnitHHelper.fromM(_unitH, queryPt.H)),
Eventech.Common.UnitHHelper.GetEnUnitName(this._unitH));
 
            if (queryPt.E > 0)
            {
                m.QueryPtE = string.Format("{0:N1} %", queryPt.E);
                builder.AppendFormat("   E:{0:N1}%", queryPt.E);
            }
 
            if (queryPt.P > 0)
            {
                m.QueryPtP = string.Format("{0} {1} ", IStation.Common.RoundHelper.GetDispValuePower(
                    Eventech.Common.UnitPHelper.fromKW(_unitP, queryPt.P)),
                    Eventech.Common.UnitPHelper.GetEnUnitName(this._unitP));
                builder.AppendFormat("   P:{0} {1} ", IStation.Common.RoundHelper.GetDispValuePower(
                    Eventech.Common.UnitPHelper.fromKW(_unitP, queryPt.P)),
                    Eventech.Common.UnitPHelper.GetEnUnitName(this._unitP));
            }
 
            this.gridControl1.RefreshDataSource();
        }
 
 
        private void MenuItem删除Speed_Click(object sender, EventArgs e)
        {
            var m = this._bindList[_clickIndex];
            if (null == m)
            {
                return;
            }
            this._bindList.RemoveAt(_clickIndex);
            if (OnDeleteTestItem != null)
            {
                OnDeleteTestItem(m.ItemID);
            }
 
            _clickIndex = 0;
        }
 
        #region GridView
 
        private void GridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            // if (e.Column == colDelete)
            // {
            //     //    var m = this._bindList[e.RowHandle];
            //     //    e.Appearance.ForeColor = m.DispColor;
            //     //    if (m.IsOverRatedSpeed)
            //     //    {
            //     //        e.Appearance.BackColor = Color.PaleVioletRed;
            //     //    }
            //}
 
            //SpeedListItem colorItem = e.Item as SpeedListItem;
            //if (colorItem == null)
            //    return;
            //e.Appearance.ForeColor = colorItem.DispColor;
        }
 
        private void GridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //if (e.Value == null)
            //    return;
 
 
 
        }
 
 
        private void GridView_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column == colColor)
            {
                var index = e.RowHandle;
                if (index < 0)
                    return;
                var item = _bindList[index];
                item.DispColor = (Color)e.Value;
                if (OnChangeColor != null)
                    OnChangeColor(item.ItemID, item.DispColor);
            }
 
        }
        private void GridView_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            if (e.Column == colDelete)
            {
 
                var m = this._bindList[e.RowHandle];
                if (null == m)
                {
                    return;
                }
                this._bindList.RemoveAt(e.RowHandle);
                if (OnDeleteTestItem != null)
                {
                    OnDeleteTestItem(m.ItemID);
                }
 
 
 
            }
        }
        private int _clickIndex = 0;
 
        private void GridView_RowClick(object sender, RowClickEventArgs e)
        {
            if (e.RowHandle < 0) return;
 
            //gridViewPumpID = (gridView1.GetRow(e.RowHandle) as System.Data.DataRowView).Row.Field<long>("PumpID");
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //_clickViewModel = gridViewPump.GetRow(e.RowHandle) as IStation.XingHao.Part;
                //if (e.RowHandle > 0)//最大不用删除
                {
                    _clickIndex = e.RowHandle;
                    multiSpeedMenuStrip.Show(gridControl1, e.Location);
                }
            }
            else
            {
                //SetRibbonButtonDisp(IStation.WinFrmUI.SeriesTreeView.eNodeLevel.Pump);
            }
        }
 
        #endregion GridView
    }
}