forked from IgorGorbunov/RABot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timers.cs
76 lines (68 loc) · 2.36 KB
/
Timers.cs
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
using System;
using System.Windows.Controls;
using System.Windows.Media;
public static class Timers
{
private static System.Windows.Forms.Timer _timerMoex, _timerLocal;
private static Label _labelMoex, _labelLocal;
private static readonly DateTime StartOpen = new DateTime(1,1,1,9,55,0);
private static readonly DateTime EndOpen = new DateTime(1, 1, 1, 10, 10, 0);
private static readonly DateTime StartClose = new DateTime(1, 1, 1, 18, 30, 0);
private static readonly DateTime EndClose = new DateTime(1, 1, 1, 18, 45, 0);
public static void InitTimers(Label labelMoex, Label labelLocal)
{
_labelMoex = labelMoex;
_timerMoex = new System.Windows.Forms.Timer
{
Interval = 1000
};
_timerMoex.Start();
_timerMoex.Tick += TimerMoexTick;
_labelLocal = labelLocal;
_timerLocal = new System.Windows.Forms.Timer
{
Interval = 1000
};
_timerLocal.Start();
_timerLocal.Tick += TimerLocalTick;
}
private static void TimerMoexTick(Object myObject, EventArgs myEventArgs)
{
DateTime moexTime = DateTime.Now.AddHours(-1);
_labelMoex.Content = moexTime.ToLongTimeString();
SetStyle();
}
private static void TimerLocalTick(Object myObject, EventArgs myEventArgs)
{
_labelLocal.Content = DateTime.Now.ToLongTimeString();
}
private static void SetStyle()
{
DateTime now = DateTime.Now.AddHours(-1);
DateTime nowTime = new DateTime(1,1,1, now.Hour, now.Minute, now.Second);
if (nowTime > StartOpen &&
nowTime < EndOpen)
{
_labelMoex.Foreground = Brushes.Blue;
_labelLocal.Foreground = Brushes.Blue;
}
else if (nowTime > EndOpen &&
nowTime < StartClose)
{
_labelMoex.Foreground = Brushes.Green;
_labelLocal.Foreground = Brushes.Green;
}
else if (nowTime > StartClose &&
nowTime < EndClose)
{
_labelMoex.Foreground = Brushes.Red;
_labelLocal.Foreground = Brushes.Red;
}
else if (nowTime > EndClose ||
nowTime < StartOpen)
{
_labelMoex.Foreground = Brushes.Pink;
_labelLocal.Foreground = Brushes.Pink;
}
}
}