-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormAutoRun.cs
175 lines (152 loc) · 7.51 KB
/
FormAutoRun.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
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
// --------------------------------------------------------------------------------
// VariScan module
//
// Description:
//
// Environment: Windows 10 executable, 32 and 64 bit
//
// Usage: TBD
//
// Author: (REM) Rick McAlister, [email protected]
//
// Edit Log: Rev 1.0 Initial Version
//
// Date Who Vers Description
// ----------- --- ----- -------------------------------------------------------
//
// ---------------------------------------------------------------------------------
//
using System;
using System.Windows.Forms;
namespace VariScan
{
public partial class FormAutoRun : Form
{
public FormAutoRun()
{
//When an instance of the autostart form is created,
// the text boxes -- start up filepath, shutdown filepath, start up time
// are filled in from the AGNSurvey configuration file. That//s it.
InitializeComponent();
Configuration cfg = new Configuration();
StagingDateTimePicker.Checked = Convert.ToBoolean(cfg.StageSystemOn);
StageSystemFilePathBox.Text = cfg.StageSystemPath;
StagingDateTimePicker.Value = Convert.ToDateTime(cfg.StageSystemTime);
StartingDateTimePicker.Checked = Convert.ToBoolean(cfg.StartUpOn);
StartUpFilePathBox.Text = cfg.StartUpPath;
StartingDateTimePicker.Value = Convert.ToDateTime(cfg.StartUpTime);
ShutdownDateTimePicker.Checked = Convert.ToBoolean(cfg.ShutDownOn);
ShutDownFilePathBox.Text = cfg.ShutDownPath;
ShutdownDateTimePicker.Value = Convert.ToDateTime(cfg.ShutDownTime);
//if (sddt > StartingDateTimePicker.Value) ShutdownDateTimePicker.Value = sddt;
//else ShutdownDateTimePicker.Value = sddt.AddDays(1);
ResyncSchedule();
}
private void StageSystemBrowseButton_Click(object sender, EventArgs e)
{
//Upon clicking the Browse button on the Stage System filename box,
// A file selection dialog is run to pick up a filepath for the
// system staging file. The result, if chosen, is entered in the stage System filename box
// in the form, and the AGNSurvey configuration file updated accordingly.
DialogResult stageSystemPathDiag = StageSystemFileDialog.ShowDialog();
if (stageSystemPathDiag == System.Windows.Forms.DialogResult.OK)
{
Configuration cfg = new Configuration();
cfg.StageSystemPath = StageSystemFileDialog.FileName;
StageSystemFilePathBox.Text = StageSystemFileDialog.FileName;
return;
}
}
private void StartUpBrowseButton_Click(object sender, EventArgs e)
{
//Upon clicking the Browse button on the Start Up filename box,
// A file selection dialog is run to pick up a filepath for the
// start up file. The result, if chosen, is entered in the start up filename box
// in the form, and the AGNSurvey configuration file updated accordingly.
DialogResult startUpPathDiag = StartUpFileDialog.ShowDialog();
if (startUpPathDiag == System.Windows.Forms.DialogResult.OK)
{
Configuration cfg = new Configuration();
cfg.StartUpPath = StartUpFileDialog.FileName;
StartUpFilePathBox.Text = StartUpFileDialog.FileName;
return;
}
}
private void ShutDownBrowseButton_Click(object sender, EventArgs e)
{
//Upon clicking the Browse button on the Shutdown filename box,
// A file selection dialog is run to pick up a filepath for the
// shutdown file. The result, if chosen, is entered in the shutdown filename box
// in the form, and the AGNSurvey configuration file updated accordingly.
DialogResult shutDownPathDiag = ShutDownFileDialog.ShowDialog();
if (shutDownPathDiag == System.Windows.Forms.DialogResult.OK)
{
Configuration cfg = new Configuration();
cfg.ShutDownPath = ShutDownFileDialog.FileName;
ShutDownFilePathBox.Text = ShutDownFileDialog.FileName;
return;
}
}
private void OKButton_Click(object sender, EventArgs e)
{
//Upon clicking the OK button,
//Save configured times and close form
Configuration cfg = new Configuration();
cfg.StageSystemTime = StagingDateTimePicker.Value.ToString("yyyy/MM/dd HH:mm:ss");
cfg.StartUpTime = StartingDateTimePicker.Value.ToString("yyyy/MM/dd HH:mm:ss");
cfg.ShutDownTime = ShutdownDateTimePicker.Value.ToString("yyyy/MM/dd HH:mm:ss");
//Store program switches
cfg.StageSystemOn = StagingDateTimePicker.Checked.ToString();
cfg.StartUpOn = StartingDateTimePicker.Checked.ToString();
cfg.ShutDownOn = ShutdownDateTimePicker.Checked.ToString();
Close();
return;
}
private void ResyncSchedule()
{
//Values for stage, start and shutdown times are reset to the current datetime, if
//their current values precede the current datetime.
//Otherwise, it is assumpted that the operator knows what he/she is doing
Configuration cfg = new Configuration();
//Store Program times for each
// Get the time from the form
// Check the current AM or PM and compare against the program AM or PM
// if the same then leave the date as the same,
// if different, then set date as next day (i.e. morning)
DateTime currentMoment = DateTime.Now;
Boolean currentlyAM = IsAM(currentMoment);
//if stage time is earlier than current time then set stage time to now
DateTime sst = StagingDateTimePicker.Value;
if (sst < currentMoment) sst = DateTime.Now;
//if start time is earlier than current time then set start to now
DateTime sut = StartingDateTimePicker.Value;
if (sut < currentMoment) sut = DateTime.Now;
//If end time is earlier than current time then change the end time
// to tomorrow, at the same time of day
DateTime sdt = ShutdownDateTimePicker.Value;
if (sdt < currentMoment) sdt = DateTime.Now.Date.AddDays(1) + sdt.TimeOfDay;
//figure out how long this session is going to be. If greater than a day, cut the
// shut down time by one day.
while ((sdt - sut).Days >= 1) sdt = sdt.AddDays(-1);
//Save the entered datetimes to the configuration.xml file and close out
StagingDateTimePicker.Value = sst;
StartingDateTimePicker.Value = sut;
ShutdownDateTimePicker.Value = sdt;
}
private Boolean IsAM(DateTime dayTime)
{
//Returns true is this dayTime is between 0 and 11:59 and the current time is not, that is in the AM.
if ((dayTime.Hour < 12) && (DateTime.Now.Hour > 12))
{ return true; }
else
{ return false; }
}
private DateTime UpdateToNow(DateTime oldDate)
{
//if oldDate is earlier than the current datetime, then return the
//current datetime, otherwise return the old datetime
if (oldDate < DateTime.Now) return DateTime.Now;
return oldDate;
}
}
}