SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
PeriodDashboard.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Media;
5 using System.Globalization;
6 using System.Text.RegularExpressions;
7 
8 namespace SeciControls
9 {
13  public partial class PeriodDashboard : BaseDashboardControl
14  {
15  private String _oldTitle;
16  private Boolean _codeChangingTitle = false;
17  private Brush _brushWarning;
18  private Brush _brushNormal;
19 
20  public PeriodDashboard()
21  {
22  InitializeComponent();
23  _brushWarning = (SolidColorBrush)this.FindResource("WarningTextBrush");
24  _brushNormal = (SolidColorBrush)this.FindResource("NormalTextBrush");
25 
26  if (!Seci.Definitions.Status.EnableDashboardTitleEdit)
27  {
28  txtTitle.Visibility = System.Windows.Visibility.Visible;
29  txtEditTitle.Visibility = System.Windows.Visibility.Collapsed;
30  }
31  }
32 
33  public override Boolean IsExpanded()
34  {
35  return expander1.IsExpanded;
36  }
37 
38  private void txtTitle_TextChanged(object sender, TextChangedEventArgs e)
39  {
40  if (btnSet != null && !_codeChangingTitle)
41  {
42  if (btnSet.Visibility == Visibility.Collapsed)
43  {
44  btnSet.Visibility = Visibility.Visible;
45  btnCancel.Visibility = Visibility.Visible;
46  _oldTitle = Seci.Standard.Dae.RunTitle;
47  }
48  }
49  }
50 
51  private void btnSet_Click(object sender, RoutedEventArgs e)
52  {
53  if (_oldTitle.Trim() != Seci.Standard.Dae.RunTitle.Trim())
54  {
55  //The title has been changed by other means during the edit (i.e. via Open GENIE)
56  if (MessageBox.Show("The current run title has been changed to \"" + Seci.Standard.Dae.RunTitle +
57  "\" do you wish to replace it with your changes?", "Title Changed During Edit",
58  MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
59  {
60  txtTitle.Text = Seci.Standard.Dae.RunTitle;
61  btnSet.Visibility = Visibility.Collapsed;
62  btnCancel.Visibility = Visibility.Collapsed;
63  _oldTitle = "";
64  return;
65  }
66  }
67 
68  //Set new title
69  Seci.Standard.Dae.SetTitle(txtEditTitle.Text);
70 
71  btnSet.Visibility = Visibility.Collapsed;
72  btnCancel.Visibility = Visibility.Collapsed;
73  _oldTitle = "";
74 
75  _codeChangingTitle = true;
76  txtTitle.Text = "Updating...";
77  _codeChangingTitle = false;
78  }
79 
80  private void btnCancel_Click(object sender, RoutedEventArgs e)
81  {
82  txtTitle.Text = Seci.Standard.Dae.RunTitle;
83  btnSet.Visibility = Visibility.Collapsed;
84  btnCancel.Visibility = Visibility.Collapsed;
85  _oldTitle = "";
86  }
87 
88  private void expander1_StateChanged(object sender, RoutedEventArgs e)
89  {
90  if (mainGrid != null)
91  {
92  if (expander1.IsExpanded)
93  {
94  mainGrid.Visibility = Visibility.Visible;
95  RoutedEventArgs newEventArgs = new RoutedEventArgs(PeriodDashboard.OnExpandedEvent);
96  RaiseEvent(newEventArgs);
97  }
98  else
99  {
100  mainGrid.Visibility = Visibility.Collapsed;
101  RoutedEventArgs newEventArgs = new RoutedEventArgs(PeriodDashboard.OnUnexpandedEvent);
102  RaiseEvent(newEventArgs);
103  }
104  }
105  }
106 
107  public override void UpdateControl()
108  {
109  //Top row
110  txtInst.Text = Seci.Definitions.Status.Instrument.ToUpper();
111 
112  if (Seci.Standard.Dae.RunNumber == null)
113  {
114  //probably a problem with the DAE
115  txtStatus.Text = "UNKNOWN";
116  return;
117  }
118 
119  //Remove leading zeroes from run number
120  txtRunNum.Text = Regex.Replace(Seci.Standard.Dae.RunNumber, @"^0*", "");
121  setStatusColour(Seci.Standard.Dae.RunStatus);
122 
123  if (Seci.Standard.Dae.RunStatus == "SETUP")
124  {
125  txtRunNumLabel.Text = "Next Run";
126  }
127  else
128  {
129  txtRunNumLabel.Text = "Run";
130  }
131 
132  //Middle area
133  DateTime time = DateTime.Now;
134  txtTime.Text = time.ToShortTimeString() + " " + time.Day + " " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(time.Month) + " " + time.Year;
135  txtUsers.Text = Seci.Standard.Dae.UserName;
136 
137  //If the title is being edited while the title is updated by other means close the edit
138  if (txtEditTitle.Visibility == Visibility.Visible && btnSet.Visibility == Visibility.Visible)
139  {
140  if (_oldTitle.Trim() != Seci.Standard.Dae.RunTitle.Trim())
141  {
142  txtEditTitle.Text = Seci.Standard.Dae.RunTitle;
143  btnSet.Visibility = Visibility.Collapsed;
144  btnCancel.Visibility = Visibility.Collapsed;
145  }
146  }
147  else if (txtEditTitle.Visibility == Visibility.Visible)
148  {
149  _codeChangingTitle = true;
150  txtEditTitle.Text = Seci.Standard.Dae.RunTitle;
151  _codeChangingTitle = false;
152  }
153  else if (txtTitle.Visibility == Visibility.Visible)
154  {
155  txtTitle.Text = Seci.Standard.Dae.RunTitle;
156  }
157 
158  //Bottom area
159  txtRunTime.Text = Seci.Standard.Dae.RunDurationTotal;
160  txtFrames.Text = Seci.Standard.Dae.GoodFramesTotal + " / " + Seci.Standard.Dae.RawFramesTotal;
161 
162  if (IsMuon)
163  {
164  txtCurrTotal.Text = Seci.Standard.Dae.CountRate;
165  txtMonCounts.Text = Seci.Standard.Dae.TotalDaeCounts;
166  txtShutter.Text = Seci.Standard.BeamLogger.GetKickerStatus();
167  }
168  else
169  {
170  String curr = Seci.Standard.Dae.BeamCurrent;
171  String tot = Seci.Standard.Dae.TotalUAmps;
172 
173  if (!curr.Contains("e") && curr.IndexOf('.') != -1 && curr.IndexOf('.') + 2 < curr.Length)
174  {
175  curr = curr.Substring(0, curr.IndexOf('.') + 2);
176  }
177 
178  if (!tot.Contains("e") && tot.IndexOf('.') != -1 && tot.IndexOf('.') + 4 < tot.Length)
179  {
180  tot = tot.Substring(0, tot.IndexOf('.') + 4);
181  }
182 
183  txtCurrTotal.Text = curr + " / " + tot;
184  txtShutter.Text = Seci.Standard.BeamLogger.GetShutterStatus();
185  if (txtShutter.Text.ToLower() != "open")
186  {
187  txtShutter.Foreground = _brushWarning;
188  }
189  else
190  {
191  txtShutter.Foreground = _brushNormal;
192  }
193  txtMonCounts.Text = Seci.Standard.Dae.MonitorCounts;
194  }
195 
196  txtPeriod.Text = Seci.Standard.Dae.CurrentPeriod + " of " + Seci.Standard.Dae.NumberOfPeriods;
197  txtPeriodFrames.Text = Seci.Standard.Dae.GoodFramesPeriod + " / " + Seci.Standard.Dae.RawFramesPeriod;
198  txtPeriodRunTime.Text = Seci.Standard.Dae.RunDurationPeriod;
199  }
200 
201  private void setStatusColour(String runStatus)
202  {
203  string status = runStatus.ToUpper();
204  txtStatus.Text = status;
205 
206  Brush brush;
207 
208  switch (status)
209  {
210  case "PROCESSING":
211  brush = new SolidColorBrush(Colors.Yellow);
212  break;
213  case "RUNNING":
214  brush = new SolidColorBrush(Colors.LightGreen);
215  break;
216  case "SETUP":
217  brush = new SolidColorBrush(Colors.LightBlue);
218  break;
219  case "PAUSED":
220  brush = new SolidColorBrush(Colors.Red);
221  break;
222  case "WAITING":
223  brush = new SolidColorBrush(Colors.Goldenrod);
224  break;
225  case "VETOING":
226  brush = new SolidColorBrush(Colors.Goldenrod);
227  break;
228  case "ENDING":
229  brush = new SolidColorBrush(Colors.RoyalBlue);
230  break;
231  case "SAVING":
232  brush = new SolidColorBrush(Colors.RoyalBlue);
233  break;
234  default:
235  brush = new SolidColorBrush(Colors.White);
236  break;
237  }
238 
239  topRow.Background = brush;
240  }
241  }
242 }
void setStatusColour(String runStatus)
static readonly RoutedEvent OnExpandedEvent
void expander1_StateChanged(object sender, RoutedEventArgs e)
void btnSet_Click(object sender, RoutedEventArgs e)
Interaction logic for AlternativeDashboard.xaml
void btnCancel_Click(object sender, RoutedEventArgs e)
void txtTitle_TextChanged(object sender, TextChangedEventArgs e)
static readonly RoutedEvent OnUnexpandedEvent