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
using DevExpress.Drawing.Internal.Fonts.Interop;
using DevExpress.Office.Utils;
using IStation.WinFrmUI.CalcErQu;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI
{
 
    public partial class RunTimeRangePanel : Panel
    {
        public RunTimeRangePanel()
        {
            
        }
        /// <summary>
        /// 绘制对象列表
        /// </summary> 
        List<CalcModel.PumpRunRange> _block_item_list = null;
 
        DateTime _startTime = DateTime.Today;
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="isSelect"></param>
        public void SetRangePumpCount(List<CalcModel.PumpRunRange> block_item_list)
        {
            if(block_item_list == null || block_item_list.Count() == 0)
            {
                return;
            }
            _startTime = DateTime.Today;
            this._block_item_list = block_item_list; 
            this.Refresh();
        }
 
 
        /// <summary>
        /// 初始化项大小
        /// </summary>
        public void InitialItemSize()
        {
            //if (_block_item_list == null || !_block_item_list.Any())
            //    return;
 
 
 
            //int last_right_x = 10;
            //int last_loc_y = 10;
            //for (int i = 0; i < _block_item_list.Count; i++)
            //{
            //    var item = _block_item_list[i];
            //    var current_loc_x = last_right_x;
 
            //    if (item.TextVisible)
            //    {
            //        if (current_loc_x + item.Width > this.Width - 50)
            //        {
            //            last_loc_y = last_loc_y + item.Height + 10;
            //            current_loc_x = 10;
            //            item.IsLineStartBlck = true;
            //            _block_item_list[i - 1].IsLineEndBlck = true;
            //        }
 
            //    }
            //    else
            //    {
            //        if (current_loc_x + item.Width > this.Width - 20)
            //        {
            //            last_loc_y = last_loc_y + item.Height + 10;
            //            current_loc_x = 10;
            //            item.IsLineStartBlck = true;
            //            _block_item_list[i - 1].IsLineEndBlck = true;
            //        }
            //    }
            //    if (i == 0)
            //    {
            //        item.IsLineStartBlck = true;
            //    }
            //    if (i == _block_item_list.Count - 1)
            //    {
            //        item.IsLineEndBlck = true;
            //    }
            //    last_right_x = current_loc_x + item.Width;
            //    item.Resize(current_loc_x, last_loc_y);
            //}
 
 
 
            this.Refresh();
        }
 
 
        #region override
 
 
 
 
 
        //
        public static Color SelectColor =   Color.DarkGreen ;
 
 
 
 
        /// <summary>
        /// 重绘事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignMode)
                return;
            if (_block_item_list == null || _block_item_list.Count() == 0)
                return;
 
            int today_minute = 24 * 60;
 
            base.OnPaint(e);
 
 
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;//抗锯齿
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高,即消除锯齿 // 设置GDI高质量模式抗锯齿
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            var g = e.Graphics;
            float pump_block_height = 22;
            float pump_block_space = 8;
            float pump_block_start = 15;
            int drawWidth = this.Width - 30;
            using (Brush gpBrush = new SolidBrush(SelectColor))
            {
 
 
                foreach (var block in _block_item_list)
                {
 
                    float startMinute = Convert.ToSingle(
                        (block.StartTime - _startTime).TotalMinutes * drawWidth / today_minute);
                    float endMinute = Convert.ToSingle((block.EndTime - _startTime).TotalMinutes * drawWidth / today_minute);
 
 
 
                    float _width = endMinute - startMinute;
 
 
 
 
 
                    if (block.PumpNumber == 0)
                    {
                        continue;
                    }
                    PointF posi1 = new PointF(startMinute + 15, pump_block_start);
                    RectangleF rect1 = new RectangleF(posi1, new SizeF(_width, pump_block_height));
                    g.FillRectangle(gpBrush, rect1);
 
 
                    if (block.PumpNumber > 1)
                    {
                        PointF posi2 = new PointF(startMinute + 15, pump_block_start + pump_block_height + pump_block_space);
                        RectangleF rect2 = new RectangleF(posi2, new SizeF(_width, pump_block_height));
                        g.FillRectangle(gpBrush, rect2);
                    }
 
                    if (block.PumpNumber > 2)
                    {
                        PointF posi3 = new PointF(startMinute + 15, pump_block_start + pump_block_height * 2 + pump_block_space * 2);
                        RectangleF rect3 = new RectangleF(posi3, new SizeF(_width, pump_block_height));
                        g.FillRectangle(gpBrush, rect3);
                    }
                    if (block.PumpNumber > 3)
                    {
                        PointF posi3 = new PointF(startMinute + 15, pump_block_start + pump_block_height * 3 + pump_block_space * 3);
                        RectangleF rect3 = new RectangleF(posi3, new SizeF(_width, pump_block_height));
                        g.FillRectangle(gpBrush, rect3);
                    }
                    if (block.PumpNumber > 4)
                    {
                        PointF posi3 = new PointF(startMinute + 15, pump_block_start + pump_block_height * 4 + pump_block_space * 4);
                        RectangleF rect3 = new RectangleF(posi3, new SizeF(_width, pump_block_height));
                        g.FillRectangle(gpBrush, rect3);
                    }
                }
 
            }
 
 
        }
 
 
 
 
 
        #endregion
 
 
    }
}