-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormAddDetector.cs
197 lines (175 loc) · 7.66 KB
/
FormAddDetector.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
Gamma Analyzer - Controlling application for Burn
Copyright (C) 2016 Norwegian Radiation Protection Authority
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Authors: Dag robole,
using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using log4net;
namespace crash
{
public partial class FormAddDetector : Form
{
private ILog log = null;
private Detector detector = null;
public string DetectorType { get; set; }
public string Serialnumber { get; set; }
public int MaxNumChannels { get; set; }
public int NumChannels { get; set; }
public int MinHV { get; set; }
public int MaxHV { get; set; }
public int HV { get; set; }
public double CoarseGain { get; set; }
public double FineGain { get; set; }
public int Livetime { get; set; }
public double LLD { get; set; }
public double ULD { get; set; }
public string PluginName { get; set; }
public string GEScript { get; set; }
public FormAddDetector(ILog l, Detector d)
{
InitializeComponent();
log = l;
detector = d;
}
private void FormAddDetector_Load(object sender, EventArgs e)
{
tbMinHV.KeyPress += CustomEvents.Integer_KeyPress;
tbMaxHV.KeyPress += CustomEvents.Integer_KeyPress;
tbHV.KeyPress += CustomEvents.Integer_KeyPress;
tbFineGain.KeyPress += CustomEvents.Numeric_KeyPress;
tbLivetime.KeyPress += CustomEvents.Integer_KeyPress;
tbLLD.KeyPress += CustomEvents.Numeric_KeyPress;
tbULD.KeyPress += CustomEvents.Numeric_KeyPress;
for (int i = 32; i < 65536; i *= 2)
cboxMaxNumChannels.Items.Add(i.ToString());
if (detector != null)
{
tbTypeName.Text = detector.TypeName;
tbSerialnumber.Text = detector.Serialnumber;
tbSerialnumber.ReadOnly = true;
int idx = cboxMaxNumChannels.FindStringExact(detector.MaxNumChannels.ToString());
if (idx > -1)
cboxMaxNumChannels.SelectedItem = cboxMaxNumChannels.Items[idx];
tbMinHV.Text = detector.MinVoltage.ToString();
tbMaxHV.Text = detector.MaxVoltage.ToString();
tbHV.Text = detector.Voltage.ToString();
cboxCoarseGain.SelectedIndex = cboxCoarseGain.FindStringExact(detector.CoarseGain.ToString());
tbFineGain.Text = detector.FineGain.ToString();
tbLivetime.Text = detector.Livetime.ToString();
tbLLD.Text = detector.LLD.ToString();
tbULD.Text = detector.ULD.ToString();
tbPluginName.Text = detector.PluginName;
tbGEScript.Text = detector.GEScript;
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(tbSerialnumber.Text.Trim())
|| String.IsNullOrEmpty(tbTypeName.Text.Trim())
|| String.IsNullOrEmpty(cboxMaxNumChannels.Text.Trim())
|| String.IsNullOrEmpty(cboxNumChannels.Text.Trim())
|| String.IsNullOrEmpty(tbMinHV.Text.Trim())
|| String.IsNullOrEmpty(tbMaxHV.Text.Trim())
|| String.IsNullOrEmpty(tbHV.Text.Trim())
|| String.IsNullOrEmpty(tbFineGain.Text.Trim())
|| String.IsNullOrEmpty(tbLivetime.Text.Trim())
|| String.IsNullOrEmpty(tbLLD.Text.Trim())
|| String.IsNullOrEmpty(tbULD.Text.Trim())
|| String.IsNullOrEmpty(tbPluginName.Text.Trim())
|| String.IsNullOrEmpty(tbGEScript.Text.Trim()))
{
MessageBox.Show("One or more required fields missing");
return;
}
try
{
DetectorType = tbTypeName.Text.Trim();
Serialnumber = tbSerialnumber.Text.Trim();
MaxNumChannels = Convert.ToInt32(cboxMaxNumChannels.SelectedItem);
NumChannels = Convert.ToInt32(cboxNumChannels.SelectedItem);
MinHV = Convert.ToInt32(tbMinHV.Text.Trim());
MaxHV = Convert.ToInt32(tbMaxHV.Text.Trim());
HV = Convert.ToInt32(tbHV.Text.Trim());
CoarseGain = Convert.ToDouble(cboxCoarseGain.Text, CultureInfo.InvariantCulture);
FineGain = Convert.ToDouble(tbFineGain.Text.Trim(), CultureInfo.InvariantCulture);
Livetime = Convert.ToInt32(tbLivetime.Text.Trim());
LLD = Convert.ToDouble(tbLLD.Text.Trim());
ULD = Convert.ToDouble(tbULD.Text.Trim());
PluginName = tbPluginName.Text.Trim();
GEScript = tbGEScript.Text.Trim();
}
catch(Exception ex)
{
log.Error("Add detector: Invalid number format", ex);
MessageBox.Show("Invalid number format");
return;
}
if (FineGain < 1.0 || FineGain > 5.0)
{
log.Error("Fine gain out of range");
MessageBox.Show("Fine gain out of range");
return;
}
if (LLD < 0d)
{
log.Error("LLD can not be less than zero");
MessageBox.Show("LLD can not be less than zero");
return;
}
if (ULD > 130d)
{
log.Error("ULD can not be bigger than 130%");
MessageBox.Show("ULD can not be bigger than 130%");
return;
}
if (LLD > ULD)
{
log.Error("LLD can not be bigger than ULD");
MessageBox.Show("LLD can not be bigger than ULD");
return;
}
if (HV < MinHV || HV > MaxHV)
{
log.Error("Voltage out of range");
MessageBox.Show("Voltage out of range");
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void cboxMaxNumChannels_SelectedIndexChanged(object sender, EventArgs e)
{
int max = Convert.ToInt32(cboxMaxNumChannels.SelectedItem);
cboxNumChannels.Items.Clear();
for (int i = 32; i <= max; i *= 2)
cboxNumChannels.Items.Add(i.ToString());
if (detector != null)
{
int idx = cboxNumChannels.FindStringExact(detector.NumChannels.ToString());
if (idx > -1)
cboxNumChannels.SelectedItem = cboxNumChannels.Items[idx];
else
cboxNumChannels.SelectedItem = cboxNumChannels.Items[0];
}
}
}
}