duheng
2024-07-25 713d5218ee2b47c0c92f75c19c49bb7e883cd214
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
using DevExpress.Utils.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
 
namespace IStation.WinFrmUI
{
    public partial class TimeBlockRangeContainer : Panel
    {
        public TimeBlockRangeContainer()
        {
            InitializeComponent();
            this.BackColor = Color.White;
 
            _panel = new TimeBlockRangePanel();
            _panel.Dock = DockStyle.Fill;
            _panel.BackColor = Color.Red;
            this.Controls.Add(_panel);
            _panel.OnFreshPumpRunRange += (list) =>
            {
                if (OnFreshPumpRunRange != null)
                {
                    OnFreshPumpRunRange.Invoke(list);
                }
            };
        }
 
        private TimeBlockRangePanel _panel = null;
 
 
        private int _totalCount = 0;
        private int _calcSpaceMinute = 10;//10分钟一个刻度
        private bool _onInitialize = true;
        private DateTime _startTime, _endTime;
 
        public Action<List<CalcModel.PumpRunRange>> OnFreshPumpRunRange = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary> 
        public void InitialTimeBlock(DateTime start, DateTime end)
        {
    
            var drawBlocks = new List<TimeSmallBlock>();
 
            
    
                _startTime = start;
                _endTime = end;
 
            int blk_index = 0;
            for (var time = _startTime; time <= this._endTime; time = time.AddMinutes(this._calcSpaceMinute))
            { 
                var block = new TimeSmallBlock(blk_index, time);
 
 
                //if (locks.Contains(i))
                //{
                //    block.DrawType = eDrawType.Lock;
                //}
                //else if (middles.Contains(i))
                //{
                //    block.DrawType = eDrawType.Middle;
                //}
                //if (dashLines.Contains(i))
                //{
                //    block.DottedLine = true;
                //}
                blk_index++;
 
                drawBlocks.Add(block);
            }
 
            _totalCount = drawBlocks.Count;
            _panel.Location = this.Location;
            CalcSize(_totalCount);
            _panel.InitialDataSource(drawBlocks);
            _onInitialize = false;
 
            #region 
            if (!string.IsNullOrEmpty(IStation.WinFrmUI.CalcErQu.Properties.Settings.Default.SwitchPumpIgnoreTimes))
            {
                var ttt = IStation.WinFrmUI.CalcErQu.Properties.Settings.Default.SwitchPumpIgnoreTimes.Split(
                    new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var t in ttt)
                {
                    var ddd = t.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                    var st = ddd[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    var ed = ddd[2].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
 
                    int ed_h = Convert.ToInt32(ed[0]);
 
 
                    if (Convert.ToBoolean(ddd[0]))
                    {
                        var IsNexDay = ed_h > 23 ? true : false;
 
                        var StartH = Convert.ToInt32(st[0]);
                        var StartM = Convert.ToInt32(st[1]);
                        var EndH = ed_h > 23 ? ed_h - 24 : ed_h;
                        var EndM = Convert.ToInt32(ed[1]);
 
                        //foreach(var b in drawBlocks)
                        //{
                        //    if(b.Time.Hour >= StartH && b.Time.Minute)
                        //}
                    }
 
 
                }
            }
 
 
 
 
            if (!string.IsNullOrEmpty(IStation.WinFrmUI.CalcErQu.Properties.Settings.Default.OpenPumpIgnoreTimes))
            {
                var ttt = IStation.WinFrmUI.CalcErQu.Properties.Settings.Default.OpenPumpIgnoreTimes.Split(
                    new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var t in ttt)
                {
                    var ddd = t.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                    var st = ddd[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    var ed = ddd[2].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
 
                    int ed_h = Convert.ToInt32(ed[0]);
 
                    //CurrentViewModel v = new CurrentViewModel();
                    //v.IsUse = Convert.ToBoolean(ddd[0]);
                    //v.IsNexDay = ed_h > 23 ? true : false;
 
                    //v.StartH = Convert.ToInt32(st[0]);
                    //v.StartM = Convert.ToInt32(st[1]);
                    //v.EndH = ed_h > 23 ? ed_h - 24 : ed_h;
                    //v.StartM = Convert.ToInt32(ed[1]);
 
                    //list不许开泵时间.Add(v);
                }
            }
 
 
            #endregion
 
 
 
            _onInitialize = false;
        }
 
 
 
 
        /// <summary>
        /// 计算大小
        /// </summary> 
        public void CalcSize(int count)
        {
            _panel.CalcOptimumSize(this.Width, this.Height, count, out int optimalWidth, out int optimalHeight);
            if (optimalHeight > this.Height)
            {
                optimalWidth -= 30;
            }
            _panel.Size = new Size(optimalWidth, optimalHeight);
        }
 
 
 
 
 
        protected override void OnResize(EventArgs eventargs)
        {
            base.OnResize(eventargs);
            if (_onInitialize)
                return;
            CalcSize(_totalCount);
            _panel.InitialItemSize();
        }
 
 
        /// <summary>
        /// 切换
        /// </summary> 
        public void SetSelectBlockPumpCount(int  selectedPumpCount)
        {
 
            _panel.SetSelectBlockPumpCount(selectedPumpCount);
        }
 
    }
}