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