SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
RBFinder.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Shapes;
13 
14 namespace SeciControls
15 {
19  public partial class RBFinder : Window
20  {
22  public event EventHandler OnCancel;
23  public event EventHandler OnOK;
24 
25  public String RB;
26  public String[,] Users;
27 
28  public RBFinder()
29  {
30  InitializeComponent();
31  }
32 
33  private void Window_Loaded(object sender, RoutedEventArgs e)
34  {
35  _holder = new RBDataHolder();
36  txtInstrument.Text = _holder.InstName;
38  }
39 
40  private void getExperimenters()
41  {
42  comName.ItemsSource = _holder.GetExperimenters();
43  }
44 
45  private void comName_SelectionChanged(object sender, SelectionChangedEventArgs e)
46  {
47  txtRbNo.Text = "";
48 
49  comDate.ItemsSource = null;
50  comDate.Text = "";
51 
52  if (comName.SelectedIndex != -1)
53  {
54  getDates(comName.SelectedItem.ToString());
55  }
56  }
57 
58  private void getDates(String Exptr)
59  {
60  comDate.ItemsSource = _holder.GetDates(Exptr);
61 
62  if (comDate.Items.Count == 1)
63  {
64  comDate.SelectedIndex = 0;
65  }
66  }
67 
68  private void comDate_SelectionChanged(object sender, SelectionChangedEventArgs e)
69  {
70  txtRbNo.Text = "";
71 
72  if (comDate.SelectedIndex != -1)
73  {
74  getRB(comDate.SelectedItem.ToString());
75 
76  //Check times against current date
77  var date = _holder.Dates[comDate.SelectedIndex];
78  if (_holder.DateOK(date))
79  {
80  txtWarning.Visibility = System.Windows.Visibility.Hidden;
81  }
82  else
83  {
84  txtWarning.Visibility = System.Windows.Visibility.Visible;
85  }
86  }
87  }
88 
89  private void getRB(String date)
90  {
91  String rbNum = date.Substring(date.IndexOf("[RB = ") + 6);
92  rbNum = rbNum.Substring(0, rbNum.Length - 1);
93 
94  txtRbNo.Text = rbNum;
95  }
96 
97  private void btnUseRb_Click(object sender, RoutedEventArgs e)
98  {
99  if (txtRbNo.Text != "")
100  {
101  RB = txtRbNo.Text;
102  setUsers(_holder.RetrieveUsersByRb(txtRbNo.Text));
103  DialogResult = true;
104  this.Close();
105  }
106  }
107 
108  private void btnCancel_Click(object sender, RoutedEventArgs e)
109  {
110  DialogResult = false;
111  this.Close();
112  }
113 
114  private void setUsers(List<User> users)
115  {
116  try
117  {
118  String[,] values = new String[users.Count, 3];
119 
120  for (int i = 0; i < users.Count; ++i)
121  {
122  PI pi = users[i] as PI;
123  Contact contact = users[i] as Contact;
124 
125  if (pi != null)
126  {
127  values[i, 0] = users[i].Name;
128  values[i, 1] = users[i].Institute;
129  values[i, 2] = "PI";
130  }
131  else if (contact != null)
132  {
133  values[i, 0] = users[i].Name;
134  values[i, 1] = users[i].Institute;
135  values[i, 2] = "Contact";
136  }
137  else
138  {
139  values[i, 0] = users[i].Name;
140  values[i, 1] = users[i].Institute;
141  values[i, 2] = "";
142  }
143  }
144 
145  Users = values;
146  }
147  catch
148  {
149  }
150  }
151  }
152 }
153 
void comDate_SelectionChanged(object sender, SelectionChangedEventArgs e)
EventHandler OnCancel
void setUsers(List< User > users)
Interaction logic for RBFinder.xaml
void getRB(String date)
void btnCancel_Click(object sender, RoutedEventArgs e)
void Window_Loaded(object sender, RoutedEventArgs e)
void getDates(String Exptr)
void comName_SelectionChanged(object sender, SelectionChangedEventArgs e)
void btnUseRb_Click(object sender, RoutedEventArgs e)
RBDataHolder _holder
bool DateOK(Tuple< DateTime, DateTime > daterange)
List< User > RetrieveUsersByRb(String rbnumber)