source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.Example.CrossComponent/UserInfoControl.cs@ 1492

Last change on this file since 1492 was 1146, checked in by Sam Habiel, 14 years ago

Initial Import of BMX4

File size: 12.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Windows.Forms;
7using IndianHealthService.BMXNet.Services;
8
9namespace IndianHealthService.BMXNet.Example.CrossComponent
10{
11 public partial class UserInfoControl : UserControl, LocalConsumer, RemoteSessionConsumer
12 {
13 public UserInfoControl()
14 {
15 InitializeComponent();
16 }
17
18 private RemoteSession _remoteSession = null;
19
20 public RemoteSession RemoteSession
21 {
22 get { return _remoteSession; }
23 set { _remoteSession = value; }
24 }
25
26 private LocalSession _localSession = null;
27
28 public LocalSession LocalSession
29 {
30 get { return _localSession; }
31 set { _localSession = value; }
32 }
33
34 private void UserInfoControl_Load(object sender, EventArgs e)
35 {
36 if (this.LocalSession != null)
37 {
38 this.LocalSession.Context.Changing += new EventHandler<IndianHealthService.BMXNet.Model.ContextChangingArgs>(Context_Changing);
39 this.LocalSession.Context.Changed += new EventHandler<IndianHealthService.BMXNet.Model.ContextChangedArgs>(Context_Changed);
40 this.LocalSession.EventServices.RefreshRequested += new EventHandler(EventServices_RefreshRequested);
41 this.LocalSession.EventServices.ApplicationEvent += new EventHandler<LocalEventArgs>(EventServices_ApplicationEvent);
42 }
43
44 if (this.RemoteSession != null)
45 {
46 this.RemoteSession.EventServices.InvokedControl = this;
47 this.RemoteSession.EventServices.RpmsEvent += new EventHandler<RemoteEventArgs>(EventServices_RpmsEvent);
48 this.RemoteSession.EventServices.TimerEvent += new EventHandler(EventServices_TimerEvent);
49 }
50
51 this.eventLogList.Clear();
52 this.eventLogList.Columns.Add("", 20);
53 this.eventLogList.Columns.Add("Context", 80);
54 this.eventLogList.Columns.Add("Event", 100);
55 this.eventLogList.Columns.Add("Details", 250);
56
57 this.queryEntry.Text = "BMX ADO SS^IHS PATIENT^^~1~20~5";
58 this.UpdateLabels();
59 this.UpdatePollingLabel();
60 }
61
62 void Context_Changing(object sender, IndianHealthService.BMXNet.Model.ContextChangingArgs e)
63 {
64 e.Cancel = this.vetoCheckBox.Checked;
65 }
66
67 void EventServices_ApplicationEvent(object sender, LocalEventArgs e)
68 {
69 ListViewItem item = new ListViewItem((this.eventLogList.Items.Count + 1).ToString());
70 item.SubItems.Add("Local");
71 item.SubItems.Add(e.EventType);
72 item.SubItems.Add(e.Details);
73 this.eventLogList.Items.Insert(0, item);
74 }
75
76 protected void EventServices_TimerEvent(object sender, EventArgs e)
77 {
78 RemoteEventArgs args = new RemoteEventArgs();
79 args.EventType = "Timer";
80 args.Details = DateTime.Now.ToShortTimeString();
81
82 this.UiSubscriptionLog(args);
83 }
84
85 protected void EventServices_RpmsEvent(object sender, RemoteEventArgs e)
86 {
87 this.UiSubscriptionLog(e);
88 }
89
90 public void UiSubscriptionLog(RemoteEventArgs e)
91 {
92 ListViewItem item = new ListViewItem((this.eventLogList.Items.Count + 1).ToString());
93 item.SubItems.Add("Remote");
94 item.SubItems.Add(e.EventType);
95 item.SubItems.Add(e.Details);
96 this.eventLogList.Items.Insert(0, item);
97 }
98
99 void EventServices_RefreshRequested(object sender, EventArgs e)
100 {
101 LocalEventArgs args = new LocalEventArgs();
102 args.EventType = "REFRESH";
103 this.EventServices_ApplicationEvent(null, args);
104
105 this.UpdateLabels();
106 }
107
108 private void UpdateLabels()
109 {
110 try
111 {
112 if (this.LocalSession == null)
113 {
114 this.userNameLabel.Text =
115 this.patientLabel.Text =
116 this.visitLabel.Text =
117 this.divisionLabel.Text = "Not connected to BMX Framework";
118
119 this.grid.DataSource = null;
120 }
121 else
122 {
123 this.enableRemoteEvents.Checked = this.RemoteSession.EventServices.IsEventPollingEnabled;
124
125 //LocalSession and RemoteSession should have the write info
126 this.userNameLabel.Text = this.RemoteSession.User == null ? "No user" : this.RemoteSession.User.Name;
127 this.divisionLabel.Text = this.RemoteSession.User == null ? "No division" : this.RemoteSession.User.Division.Name;
128 this.patientLabel.Text = this.LocalSession.Context.HasPatient ? this.LocalSession.Context.Patient.PatientName : "No patient";
129 this.visitLabel.Text = this.LocalSession.Context.HasVisit ? this.LocalSession.Context.Visit.ToString() : "No visit";
130
131 try
132 {
133 string rawQuery = this.queryEntry.Text;
134 string query = rawQuery;
135 if (this.LocalSession.Context.HasPatient)
136 {
137 rawQuery.Replace("@P", this.LocalSession.Context.Patient.Ien);
138 }
139 if (this.LocalSession.Context.HasVisit)
140 {
141 query = rawQuery.Replace("@V", this.LocalSession.Context.Visit.Ien);
142 }
143 query = rawQuery.Replace("@U", this.LocalSession.User.Duz);
144 this.queryLabel.Text = query;
145 this.grid.DataSource = this.RemoteSession.TableFromCommand(query);
146
147
148 this.queryEntry.BackColor = Color.LightGreen;
149 }
150 catch
151 {
152 this.grid.DataSource = null;
153 this.queryEntry.BackColor = Color.Red;
154 }
155 }
156
157 this.lastUpdateLabel.Text = DateTime.Now.ToLongTimeString();
158 }
159 catch (Exception p)
160 {
161 MessageBox.Show(p.StackTrace);
162 }
163 }
164
165 private String _configurationParameter = "Not connected to BMX Framework";
166
167 public String ConfigurationParameter
168 {
169 get { return _configurationParameter; }
170 set
171 {
172 this._configurationParameter = value;
173 this.UpdateLabels();
174 }
175 }
176 void Context_Changed(object sender, IndianHealthService.BMXNet.Model.ContextChangedArgs e)
177 {
178 this.UpdateLabels();
179 }
180
181 private void queryEntry_TextChanged(object sender, EventArgs e)
182 {
183 this.queryEntry.BackColor = Color.White;
184 }
185
186 private List<string> _localSubscriptions = new List<string>();
187
188 public List<string> LocalSubscriptions
189 {
190 get { return _localSubscriptions; }
191 set { _localSubscriptions = value; }
192 }
193
194
195 private List<string> _subscriptions = new List<string>();
196
197 public List<string> Subscriptions
198 {
199 get { return _subscriptions; }
200 set { _subscriptions = value; }
201 }
202
203 public String FireEventName
204 {
205 get { return this.fireEventEntry.Text.Trim(); }
206 }
207
208
209 public String SubscriptionEventName
210 {
211 get { return this.subscriptionEvent.Text.Trim(); }
212 }
213
214 private void subscribeButton_Click(object sender, EventArgs e)
215 {
216 if ((this.SubscriptionEventName.Length > 0) && !this.Subscriptions.Contains(this.SubscriptionEventName))
217 {
218 int result = this.RemoteSession.EventServices.Subscribe(this.SubscriptionEventName);
219 this.Subscriptions.Add(this.SubscriptionEventName);
220 this.UpdateEventList();
221 }
222 }
223
224 private void UpdateEventList()
225 {
226
227 this.subscriptionList.BeginUpdate();
228 this.subscriptionList.Items.Clear();
229 foreach (String each in this.Subscriptions)
230 {
231 this.subscriptionList.Items.Add(each);
232 }
233 this.subscriptionList.EndUpdate();
234
235 this.localSubscriptions.BeginUpdate();
236 this.localSubscriptions.Items.Clear();
237 foreach (String each in this.LocalSubscriptions)
238 {
239 this.localSubscriptions.Items.Add(each);
240 }
241 this.localSubscriptions.EndUpdate();
242 }
243
244 private void unsubscribeButton_Click(object sender, EventArgs e)
245 {
246 if (this.Subscriptions.Contains(this.SubscriptionEventName))
247 {
248 this.RemoteSession.EventServices.Unsubscribe(this.SubscriptionEventName);
249 this.Subscriptions.Remove(this.SubscriptionEventName);
250 this.UpdateEventList();
251 }
252 }
253
254 private void button3_Click(object sender, EventArgs e)
255 {
256 if (this.FireEventName.Length > 0)
257 {
258 this.RemoteSession.EventServices.TriggerEvent(this.FireEventName, this.parameterEntry.Text.Trim(), this.raiseBackCheckbox.Checked);
259 }
260 }
261
262 private void subscriptionList_SelectedIndexChanged(object sender, EventArgs e)
263 {
264 this.subscriptionEvent.Text = this.subscriptionList.SelectedItem.ToString();
265 this.fireEventEntry.Text = this.subscriptionList.SelectedItem.ToString();
266 }
267
268 private void pollingTrack_ValueChanged(object sender, EventArgs e)
269 {
270 this.RemoteSession.EventServices.EventPollingInterval = this.pollingTrack.Value * 1000;
271 this.UpdatePollingLabel();
272 }
273
274 protected void UpdatePollingLabel()
275 {
276 this.pollingLabel.Text = "Polling Interval: " + ((int)(this.RemoteSession.EventServices.EventPollingInterval / 1000)).ToString().PadLeft(4);
277 }
278
279 private void enableRemoteEvents_CheckedChanged(object sender, EventArgs e)
280 {
281 this.RemoteSession.EventServices.IsEventPollingEnabled = this.enableRemoteEvents.Checked;
282 }
283
284 private void queryEntry_TextChanged_1(object sender, EventArgs e)
285 {
286
287 }
288
289 private void fireLocalEntry_TextChanged(object sender, EventArgs e)
290 {
291 }
292
293
294 private void localSubscribeButton_Click(object sender, EventArgs e)
295 {
296 String eventName = this.localEvent.Text.Trim();
297 if ((eventName.Length > 0) && !this.LocalSubscriptions.Contains(eventName))
298 {
299 this.LocalSession.EventServices.Subscribe(eventName);
300 this.LocalSubscriptions.Add(eventName);
301 this.UpdateEventList();
302 }
303 }
304
305 private void localUnsubscribeButton_Click(object sender, EventArgs e)
306 {
307 String eventName = this.localEvent.Text.Trim();
308 if (this.LocalSubscriptions.Contains(eventName))
309 {
310 this.LocalSession.EventServices.Unsubscribe(eventName);
311 this.LocalSubscriptions.Remove(eventName);
312 this.UpdateEventList();
313 }
314 }
315
316 private void localSubscriptions_SelectedIndexChanged(object sender, EventArgs e)
317 {
318 this.localEvent.Text = this.localSubscriptions.SelectedItem.ToString();
319 this.fireLocalEvent.Text = this.localSubscriptions.SelectedItem.ToString();
320 }
321
322
323 public String LocalFireEventName
324 {
325 get { return this.fireLocalEvent.Text.Trim(); }
326 }
327
328
329 private void triggerLocalButton_Click(object sender, EventArgs e)
330 {
331 if (this.LocalFireEventName.Length > 0)
332 {
333 this.LocalSession.EventServices.TriggerEvent(this.LocalFireEventName, this.fireLocalParameter.Text.Trim());
334
335 }
336 }
337
338 private void vetoCheckBox_CheckedChanged(object sender, EventArgs e)
339 {
340
341 }
342 }
343}
Note: See TracBrowser for help on using the repository browser.