source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.Example.CrossComponent.WindowsApp/WindowsApplicationMainWindow.cs@ 1551

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

Initial Import of BMX4

File size: 10.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using IndianHealthService.BMXNet.WinForm;
9using IndianHealthService.BMXNet.WinForm.Configuration;
10using System.Reflection;
11using System.IO;
12using IndianHealthService.BMXNet.Model;
13using IndianHealthService.BMXNet.WinForm.Model;
14using IndianHealthService.BMXNet.Services;
15
16namespace IndianHealthService.BMXNet.Example.CrossComponent.WindowsApp
17{
18 public partial class WindowsApplicationMainWindow : Form
19 {
20 public WindowsApplicationMainWindow()
21 {
22 InitializeComponent();
23 }
24
25
26 private WinFramework _framework = null;
27
28 public WinFramework Framework
29 {
30 get { return _framework; }
31 set { _framework = value; }
32 }
33
34 private RemoteSession _remoteSession = null;
35
36 public RemoteSession RemoteSession
37 {
38 get { return _remoteSession; }
39 set { _remoteSession = value; }
40 }
41
42
43 private void WindowsApplicationMainWindow_Load(object sender, EventArgs e)
44 {
45 bool usePrimarySession = this.Framework == null;
46
47 if (this.Framework == null)
48 {
49 this.Framework = WinFramework.CreateWithNetworkBroker(true,new NullLog());
50
51 this.Framework.LoadConnectionSpecs(LocalPersistentStore.CreateDefaultStorage(true), "MyApplication", "v5");
52
53 if (this.Framework.ConnectionSettings.ConnectionSpecs.Count == 0)
54 {
55 try
56 {
57 Assembly priorAssembly = Assembly.LoadFrom("PriorBmxForEvidence/BMXNet30.dll");
58 this.Framework.LoadConnectionSpecsAndMergeWithExistingBMXConfiguration(priorAssembly, LocalPersistentStore.CreateDefaultStorage(true), "MyApplication", "v5");
59 }
60 catch
61 {
62 }
63 }
64
65
66 LoginProcess login = this.Framework.CreateLoginProcess();
67
68 if (login.HasDefaultConnectionWithUseWindowsAuth)
69 {
70 login.AttemptWindowsAuthLogin();
71 }
72
73 if (!login.WasLoginAttempted || !login.WasSuccessful)
74 {
75 login.AttemptUserInputLogin("iCare Login", 3, true, this);
76 }
77
78 if (!login.WasSuccessful)
79 {
80 this.Close();
81 return;
82 }
83 LocalSession local = this.Framework.LocalSession;
84
85 if ((this.Framework.User.Division==null) && !this.Framework.AttemptUserInputSetDivision("Set Initial Division", this))
86 {
87 this.Close();
88 return;
89 }
90 }
91
92 this.RemoteSession =
93 usePrimarySession
94 ? this.Framework.Broker.PrimaryRemoteSession
95 : this.Framework.Broker.RemoteSessionPool.OpenSession();
96
97 this.AddControl();
98
99 this.Framework.Context.Changed += new EventHandler<ContextChangedArgs>(Context_Changed);
100 this.currentCheckBox.Checked = this.Framework.BootStrapSettings.GetBool("CurrentVisit", true);
101 this.patientCombo.Focus();
102
103 this.UpdateTitle();
104
105 }
106
107 private Context _managedContext = null;
108
109 public Context ManagedContext
110 {
111 get { return _managedContext; }
112 set { _managedContext = value; }
113 }
114
115 void Context_Changed(object sender, ContextChangedArgs e)
116 {
117 if (e.IsPatientChange)
118 {
119 if (e.IsPatientChange && e.AfterContext.Patient == null)
120 {
121 this.patientCombo.Items.Clear();
122 this.patientCombo.Text = "";
123 }
124 this.UpdateVisits();
125 }
126 }
127
128 private void AddControl()
129 {
130 UserInfoControl control = new UserInfoControl();
131 (control as LocalConsumer).LocalSession = this.Framework.LocalSession;
132 (control as RemoteSessionConsumer).RemoteSession = this.RemoteSession;
133
134 control.Dock = DockStyle.Fill;
135
136 this.controlPanel.Controls.Add(control);
137 }
138
139 private void button1_Click(object sender, EventArgs e)
140 {
141 AboutDialog dialog = new AboutDialog();
142 dialog.ShowDialog(this);
143 }
144
145
146 public Patient SelectedPatient
147 {
148 get { return (Patient)this.patientCombo.SelectedItem; }
149 }
150
151 private void patientCombo_SelectedIndexChanged(object sender, EventArgs e)
152 {
153 this.Framework.Context.ChangePatient(this.SelectedPatient);
154 }
155
156 private void UpdateVisits()
157 {
158 this.visitComboBox.BeginUpdate();
159 this.visitComboBox.Items.Clear();
160 if (this.SelectedPatient != null)
161 {
162 List<Visit> visits = this.Framework.Visits(this.SelectedPatient, 20);
163 this.visitComboBox.Items.AddRange(visits.ToArray());
164 this.visitComboBox.SelectedIndex = (this.currentCheckBox.Checked ? Math.Min(visits.Count - 1, 0) : -1);
165 }
166 this.visitComboBox.EndUpdate();
167 }
168
169 private void findButton_Click(object sender, EventArgs e)
170 {
171 this.DoSearch();
172 }
173
174 protected void DoSearch()
175 {
176
177 List<Patient> found = this.Framework.FindPatients(this.patientCombo.Text, 20);
178
179 this.patientCombo.BeginUpdate();
180 this.patientCombo.Items.Clear();
181 foreach (Patient each in found)
182 {
183 this.patientCombo.Items.Add(each);
184 }
185
186 if (found.Count == 1)
187 {
188 this.patientCombo.SelectedItem = found[0];
189 }
190 else if (found.Count == 0)
191 {
192 this.patientCombo.Text = "<No patients found>";
193 this.patientCombo.Focus();
194 }
195 else
196 {
197 this.patientCombo.Text = found.Count.ToString() + " patients found...";
198 }
199
200 this.patientCombo.EndUpdate();
201 }
202
203 private void patientCombo_KeyDown(object sender, KeyEventArgs e)
204 {
205 if (e.KeyCode == Keys.Enter)
206 {
207 this.DoSearch();
208 }
209 }
210
211 private void resetButton_Click(object sender, EventArgs e)
212 {
213 this.Framework.Context.ChangePatient(this.Framework.Context.Patient);
214 }
215
216 private void refreshButton_Click(object sender, EventArgs e)
217 {
218 this.Framework.TriggerLocalEvent("REFRESH", "UserSelected");
219 }
220
221 public Visit SelectedVisit
222 {
223 get { return (Visit)this.visitComboBox.SelectedItem; }
224 }
225
226
227 private void visitComboBox_SelectedIndexChanged(object sender, EventArgs e)
228 {
229 this.Framework.Context.ChangeVisit(this.SelectedVisit);
230
231 }
232
233 private void divisionButton_Click(object sender, EventArgs e)
234 {
235 if (this.Framework.AttemptUserInputSetDivision("Change Divsion @ " + DateTime.Now.ToLongTimeString(), this))
236 {
237 this.patientCombo.Items.Clear();
238 this.patientCombo.Text = null;
239 this.patientCombo.Focus();
240 }
241
242 }
243
244 private void keyEntry_TextChanged(object sender, EventArgs e)
245 {
246 this.keyEntry.BackColor = Color.White;
247 }
248
249 private void keyButton_Click(object sender, EventArgs e)
250 {
251 this.keyEntry.BackColor = this.Framework.User.HasSecurityKey(this.keyEntry.Text.Trim()) ? Color.LightGreen : Color.Red;
252 }
253
254 private void aboutDialogToolStripMenuItem_Click(object sender, EventArgs e)
255 {
256 new AboutDialog().ShowDialog(this);
257 }
258
259 private void bMXVersionInfoToolStripMenuItem_Click(object sender, EventArgs e)
260 {
261 // DataTable peek = this.Framework.Bmx.VersionInfo;
262 this.NotYetImplemented();
263 }
264
265 private void NotYetImplemented()
266 {
267 MessageBox.Show("Not yet implement", "Demo App Message");
268 }
269
270 private void WindowsApplicationMainWindow_FormClosing(object sender, FormClosingEventArgs e)
271 {
272 if (this.RemoteSession != null)
273 {
274 this.RemoteSession.Close();
275 }
276 }
277
278 private void spawnSessionToolStripMenuItem_Click(object sender, EventArgs e)
279 {
280 WindowsApplicationMainWindow window = new WindowsApplicationMainWindow();
281 window.Framework = this.Framework;
282 window.Show();
283 }
284
285 public void UpdateTitle()
286 {
287 this.Text = "BMX Test Bench :: " + this.RemoteSession.ToString();
288 }
289
290 private void closeRemoteSessionToolStripMenuItem_Click(object sender, EventArgs e)
291 {
292 this.RemoteSession.Close();
293 }
294
295 private void remoteTriggerButton_Click(object sender, EventArgs e)
296 {
297 String eventName = this.remoteEventTriggerCombo.Text.Trim();
298 String eventParam = this.remoteParamTriggerCombo.Text.Trim();
299
300 if (eventName.Length > 0)
301 {
302 int result=this.RemoteSession.EventServices.TriggerEvent(eventName, eventParam, this.remoteCallBackCheck.Checked);
303 }
304 }
305
306 private void localTriggerButton_Click(object sender, EventArgs e)
307 {
308 String eventName = this.localEventTriggerCombo.Text.Trim();
309 String eventParam = this.localParamTriggerCombo.Text.Trim();
310
311 if (eventName.Length > 0)
312 {
313 this.Framework.TriggerLocalEvent(eventName, eventParam);
314 }
315 }
316
317 private void logViewerToolStripMenuItem_Click(object sender, EventArgs e)
318 {
319
320 }
321 }
322}
Note: See TracBrowser for help on using the repository browser.