1 | using System;
|
---|
2 | using System.Data;
|
---|
3 | using System.Diagnostics;
|
---|
4 | using System.IO;
|
---|
5 | using System.IO.IsolatedStorage;
|
---|
6 | using System.Runtime.Serialization;
|
---|
7 | using System.Runtime.Serialization.Formatters;
|
---|
8 | using System.Runtime.Serialization.Formatters.Soap;
|
---|
9 | using System.Windows.Forms;
|
---|
10 | using System.Security.Principal;
|
---|
11 | using System.Text;
|
---|
12 | using System.Security.Cryptography;
|
---|
13 | using System.Timers;
|
---|
14 | using System.Threading;
|
---|
15 |
|
---|
16 |
|
---|
17 | namespace IndianHealthService.BMXNet
|
---|
18 | {
|
---|
19 | public class BMXNetEventArgs : EventArgs
|
---|
20 | {
|
---|
21 | public string BMXParam;
|
---|
22 | public string BMXEvent;
|
---|
23 | }
|
---|
24 |
|
---|
25 | /// <summary>
|
---|
26 | /// Contains methods and properties to support RPMS Login for .NET applications
|
---|
27 | /// </summary>
|
---|
28 | public class BMXNetConnectInfo : System.Windows.Forms.Control
|
---|
29 | {
|
---|
30 |
|
---|
31 | /// <summary>
|
---|
32 | /// Serializes RPMS server address and port
|
---|
33 | /// </summary>
|
---|
34 | [SerializableAttribute]
|
---|
35 | private class ServerData
|
---|
36 | {
|
---|
37 | public string m_sAddress = "";
|
---|
38 | public int m_nPort = 0;
|
---|
39 | public string m_sNamespace = "";
|
---|
40 |
|
---|
41 | public ServerData()
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | public ServerData(string sAddress, int nPort)
|
---|
46 | {
|
---|
47 | this.m_nPort = nPort;
|
---|
48 | this.m_sAddress = sAddress;
|
---|
49 | this.m_sNamespace = "";
|
---|
50 | }
|
---|
51 | public ServerData(string sAddress, int nPort, string sNamespace)
|
---|
52 | {
|
---|
53 | this.m_nPort = nPort;
|
---|
54 | this.m_sAddress = sAddress;
|
---|
55 | this.m_sNamespace = sNamespace;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public BMXNetConnectInfo()
|
---|
60 | {
|
---|
61 | m_BMXNetLib = new BMXNetLib();
|
---|
62 |
|
---|
63 | //Initialize BMXNetEvent timer
|
---|
64 | m_timerEvent = new System.Timers.Timer();
|
---|
65 | m_timerEvent.Elapsed+=new ElapsedEventHandler(OnEventTimer);
|
---|
66 | m_timerEvent.Interval = 10000;
|
---|
67 | m_timerEvent.Enabled = false;
|
---|
68 | }
|
---|
69 |
|
---|
70 | #region BMXNetEvent
|
---|
71 |
|
---|
72 | private System.Timers.Timer m_timerEvent;
|
---|
73 | public delegate void BMXNetEventDelegate(Object obj, BMXNetEventArgs e);
|
---|
74 | public event BMXNetEventDelegate BMXNetEvent;
|
---|
75 |
|
---|
76 | /// <summary>
|
---|
77 | /// Enables and disables event polling for the RPMS connection
|
---|
78 | /// </summary>
|
---|
79 | public bool EventPollingEnabled
|
---|
80 | {
|
---|
81 | get
|
---|
82 | {
|
---|
83 | return m_timerEvent.Enabled;
|
---|
84 | }
|
---|
85 | set
|
---|
86 | {
|
---|
87 | // Debug.Write("ConnectInfo handle: " + this.Handle.ToString() + "\n");
|
---|
88 | //System.IntPtr pHandle = this.Handle;
|
---|
89 | m_timerEvent.Enabled = value;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | /// <summary>
|
---|
94 | /// Sets and retrieves the interval in milliseconds for RPMS event polling
|
---|
95 | /// </summary>
|
---|
96 | public double EventPollingInterval
|
---|
97 | {
|
---|
98 | get
|
---|
99 | {
|
---|
100 | return m_timerEvent.Interval;
|
---|
101 | }
|
---|
102 | set
|
---|
103 | {
|
---|
104 | m_timerEvent.Interval = value;
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | /// <summary>
|
---|
109 | /// Register interest in an RPMS event.
|
---|
110 | /// </summary>
|
---|
111 | /// <param name="EventName"></param>
|
---|
112 | /// <returns></returns>
|
---|
113 | public int SubscribeEvent(string EventName)
|
---|
114 | {
|
---|
115 | try
|
---|
116 | {
|
---|
117 | //System.IntPtr pHandle = this.Handle;
|
---|
118 | DataTable dt;
|
---|
119 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable);
|
---|
120 | if (this.IsHandleCreated == false)
|
---|
121 | {
|
---|
122 | this.CreateHandle();
|
---|
123 | }
|
---|
124 | dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT REGISTER^" + EventName, "dt"});
|
---|
125 |
|
---|
126 | // dt = RPMSDataTable("BMX EVENT REGISTER^" + EventName, "dt");
|
---|
127 | DataRow dr = dt.Rows[0];
|
---|
128 | int nRet = (int) dr["ERRORID"];
|
---|
129 | return nRet;
|
---|
130 | }
|
---|
131 | catch (Exception ex)
|
---|
132 | {
|
---|
133 | Debug.Write(ex.Message);
|
---|
134 | return 99;
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | /// <summary>
|
---|
139 | /// Unregister an RPMS event
|
---|
140 | /// </summary>
|
---|
141 | /// <param name="EventName"></param>
|
---|
142 | /// <returns></returns>
|
---|
143 | public int UnSubscribeEvent(string EventName)
|
---|
144 | {
|
---|
145 | try
|
---|
146 | {
|
---|
147 | DataTable dt;
|
---|
148 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable);
|
---|
149 | if (this.IsHandleCreated == false)
|
---|
150 | {
|
---|
151 | this.CreateHandle();
|
---|
152 | }
|
---|
153 | dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT UNREGISTER^" + EventName, "dt"});
|
---|
154 |
|
---|
155 | DataRow dr = dt.Rows[0];
|
---|
156 | int nRet = (int) dr["ERRORID"];
|
---|
157 | return nRet;
|
---|
158 | }
|
---|
159 | catch (Exception ex)
|
---|
160 | {
|
---|
161 | Debug.Write(ex.Message);
|
---|
162 | return 99;
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | /// <summary>
|
---|
167 | /// Raise an RPMS event
|
---|
168 | /// </summary>
|
---|
169 | /// <param name="EventName">The name of the event to raise</param>
|
---|
170 | /// <param name="Param">Parameters associated with the event</param>
|
---|
171 | /// <param name="RaiseBack">True if the event should be raised back to the caller</param>
|
---|
172 | /// <returns></returns>
|
---|
173 | public int RaiseEvent(string EventName, string Param, bool RaiseBack)
|
---|
174 | {
|
---|
175 | string sBack = (RaiseBack == true)?"TRUE":"FALSE";
|
---|
176 | try
|
---|
177 | {
|
---|
178 | DataTable dt;
|
---|
179 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable);
|
---|
180 | if (this.IsHandleCreated == false)
|
---|
181 | {
|
---|
182 | this.CreateHandle();
|
---|
183 | }
|
---|
184 | dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT RAISE^" + EventName + "^" + Param + "^" + sBack + "^", "dt"});
|
---|
185 |
|
---|
186 | DataRow dr = dt.Rows[0];
|
---|
187 | int nRet = (int) dr["ERRORID"];
|
---|
188 | return nRet;
|
---|
189 | }
|
---|
190 | catch (Exception ex)
|
---|
191 | {
|
---|
192 | Debug.Write(ex.Message);
|
---|
193 | return 99;
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | /// <summary>
|
---|
198 | /// Sets and retrieves the number of times that the Event Timer will generage a BMXNet AutoFire event.
|
---|
199 | /// For example, if AutoFire == 3, then every 3rd time the Event Timer fires, it will generate an AutoFire event.
|
---|
200 | /// </summary>
|
---|
201 | public int AutoFire
|
---|
202 | {
|
---|
203 | get
|
---|
204 | {
|
---|
205 | return m_nAutoFireIncrements;
|
---|
206 | }
|
---|
207 | set
|
---|
208 | {
|
---|
209 | m_nAutoFireIncrements = value;
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | //Retrieve events registered by this session
|
---|
214 | private int m_nAutoFireIncrements = 0;
|
---|
215 | private int m_nAutoFireCount = 0;
|
---|
216 |
|
---|
217 | private void OnEventTimer(object source, ElapsedEventArgs e)
|
---|
218 | {
|
---|
219 | try
|
---|
220 | {
|
---|
221 | this.bmxNetLib.BMXRWL.AcquireWriterLock(5);
|
---|
222 | try
|
---|
223 | {
|
---|
224 | this.m_timerEvent.Enabled = false;
|
---|
225 |
|
---|
226 | Object obj = this;
|
---|
227 | BMXNetEventArgs args = new BMXNetEventArgs();
|
---|
228 | m_nAutoFireCount++;
|
---|
229 | if ((m_nAutoFireIncrements > 0)&&(m_nAutoFireCount >= m_nAutoFireIncrements))
|
---|
230 | {
|
---|
231 | m_nAutoFireCount = 0;
|
---|
232 | args.BMXEvent = "BMXNet AutoFire";
|
---|
233 | args.BMXParam = "";
|
---|
234 | if (BMXNetEvent != null)
|
---|
235 | {
|
---|
236 | BMXNetEvent(obj, args);
|
---|
237 | }
|
---|
238 | this.m_timerEvent.Enabled = true;
|
---|
239 | return;
|
---|
240 | }
|
---|
241 |
|
---|
242 | if (m_BMXNetLib.Connected == false)
|
---|
243 | {
|
---|
244 | this.m_timerEvent.Enabled = true;
|
---|
245 | return;
|
---|
246 | }
|
---|
247 |
|
---|
248 | DataTable dtEvents = new DataTable("BMXNetEvents");
|
---|
249 |
|
---|
250 | try
|
---|
251 | {
|
---|
252 | if (this.IsHandleCreated == false)
|
---|
253 | {
|
---|
254 | this.CreateHandle();
|
---|
255 | }
|
---|
256 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable);
|
---|
257 | dtEvents = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT POLL", "BMXNetEvents"});
|
---|
258 | }
|
---|
259 | catch (Exception ex)
|
---|
260 | {
|
---|
261 | string sMsg = ex.Message;
|
---|
262 | this.m_timerEvent.Enabled = true;
|
---|
263 | return;
|
---|
264 | }
|
---|
265 |
|
---|
266 | try
|
---|
267 | {
|
---|
268 | if (dtEvents.Rows.Count == 0)
|
---|
269 | {
|
---|
270 | this.m_timerEvent.Enabled = true;
|
---|
271 | return;
|
---|
272 | }
|
---|
273 | }
|
---|
274 | catch(Exception ex)
|
---|
275 | {
|
---|
276 | Debug.Write("upper Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n");
|
---|
277 | }
|
---|
278 | try
|
---|
279 | {
|
---|
280 | //If events exist, raise BMXNetEvent
|
---|
281 | foreach (DataRow dr in dtEvents.Rows)
|
---|
282 | {
|
---|
283 | args.BMXEvent = dr["EVENT"].ToString();
|
---|
284 | args.BMXParam = dr["PARAM"].ToString();
|
---|
285 | if (BMXNetEvent != null)
|
---|
286 | {
|
---|
287 | BMXNetEvent(obj, args);
|
---|
288 | }
|
---|
289 | }
|
---|
290 | this.m_timerEvent.Enabled = true;
|
---|
291 | return;
|
---|
292 | }
|
---|
293 | catch(Exception ex)
|
---|
294 | {
|
---|
295 | Debug.Write("lower Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n");
|
---|
296 | }
|
---|
297 | }
|
---|
298 | catch(Exception ex)
|
---|
299 | {
|
---|
300 | Debug.Write("Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n");
|
---|
301 | }
|
---|
302 | finally
|
---|
303 | {
|
---|
304 | this.bmxNetLib.BMXRWL.ReleaseWriterLock();
|
---|
305 | this.m_timerEvent.Enabled = true;
|
---|
306 | }
|
---|
307 | }
|
---|
308 | catch
|
---|
309 | {
|
---|
310 | Debug.Write(" OnEventTimer failed to obtain lock.\n");
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | #endregion BMXNetEvent
|
---|
315 |
|
---|
316 | #region Fields
|
---|
317 |
|
---|
318 | private ServerData m_ServerData;
|
---|
319 | private string m_sServerAddress;
|
---|
320 | private int m_nServerPort;
|
---|
321 | private string m_sServerNamespace;
|
---|
322 | private string m_sDUZ2;
|
---|
323 | private int m_nDivisionCount = 0;
|
---|
324 | private string m_sUserName;
|
---|
325 | private string m_sDivision;
|
---|
326 | private string m_sAppcontext;
|
---|
327 | private BMXNetLib m_BMXNetLib;
|
---|
328 | private bool m_bAutoServer = false;
|
---|
329 | private bool m_bAutoLogin = false;
|
---|
330 |
|
---|
331 | #endregion Fields
|
---|
332 |
|
---|
333 | #region Properties
|
---|
334 |
|
---|
335 | // /// <summary>
|
---|
336 | // /// Set and retrieve the timeout in milliseconds for locking the transmit port.
|
---|
337 | // /// If the transmit port is unavailable an ApplicationException will be thrown.
|
---|
338 | // /// </summary>
|
---|
339 | // public int TransmitLockTimeout
|
---|
340 | // {
|
---|
341 | // get
|
---|
342 | // {
|
---|
343 | // return m_nTransmitLockTimeout;
|
---|
344 | // }
|
---|
345 | // set
|
---|
346 | // {
|
---|
347 | // m_nTransmitLockTimeout = value;
|
---|
348 | // }
|
---|
349 | // }
|
---|
350 |
|
---|
351 | /// <summary>
|
---|
352 | /// Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server.
|
---|
353 | /// If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed.
|
---|
354 | /// The default is 30 seconds.
|
---|
355 | /// </summary>
|
---|
356 | public int ReceiveTimeout
|
---|
357 | {
|
---|
358 | get { return m_BMXNetLib.ReceiveTimeout; }
|
---|
359 | set { m_BMXNetLib.ReceiveTimeout = value; }
|
---|
360 | }
|
---|
361 |
|
---|
362 | public string MServerNameSpace
|
---|
363 | {
|
---|
364 | get
|
---|
365 | {
|
---|
366 | return m_BMXNetLib.MServerNamespace;
|
---|
367 | }
|
---|
368 | set
|
---|
369 | {
|
---|
370 | m_BMXNetLib.MServerNamespace = value;
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | public BMXNetLib bmxNetLib
|
---|
375 | {
|
---|
376 | get
|
---|
377 | {
|
---|
378 | return m_BMXNetLib;
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | public string AppContext
|
---|
383 | {
|
---|
384 | get
|
---|
385 | {
|
---|
386 | return m_sAppcontext;
|
---|
387 | }
|
---|
388 | set
|
---|
389 | {
|
---|
390 | if (m_BMXNetLib.Connected == true)
|
---|
391 | {
|
---|
392 | try
|
---|
393 | {
|
---|
394 | try
|
---|
395 | {
|
---|
396 | m_BMXNetLib.AppContext = value;
|
---|
397 | m_sAppcontext = value;
|
---|
398 | }
|
---|
399 | catch (Exception ex)
|
---|
400 | {
|
---|
401 | Debug.Write(ex.Message);
|
---|
402 | throw ex;
|
---|
403 | }
|
---|
404 | finally
|
---|
405 | {
|
---|
406 | }
|
---|
407 | }
|
---|
408 | catch (ApplicationException aex)
|
---|
409 | {
|
---|
410 | // The writer lock request timed out.
|
---|
411 | Debug.Write("BMXNetConnectInfo.AppContext lock request timed out.\n");
|
---|
412 | throw aex;
|
---|
413 | }
|
---|
414 | }//end if
|
---|
415 | }//end set
|
---|
416 | }
|
---|
417 |
|
---|
418 | public bool Connected
|
---|
419 | {
|
---|
420 | get
|
---|
421 | {
|
---|
422 | return m_BMXNetLib.Connected;
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | public string UserName
|
---|
427 | {
|
---|
428 | get
|
---|
429 | {
|
---|
430 | return this.m_sUserName;
|
---|
431 | }
|
---|
432 | }
|
---|
433 |
|
---|
434 | public string DivisionName
|
---|
435 | {
|
---|
436 | get
|
---|
437 | {
|
---|
438 | return this.m_sDivision;
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | /// <summary>
|
---|
443 | /// Returns a string representation of DUZ
|
---|
444 | /// </summary>
|
---|
445 | public string DUZ
|
---|
446 | {
|
---|
447 | get
|
---|
448 | {
|
---|
449 | return this.bmxNetLib.DUZ;
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | /// <summary>
|
---|
454 | /// Sets and Returns DUZ(2)
|
---|
455 | /// </summary>
|
---|
456 | public string DUZ2
|
---|
457 | {
|
---|
458 | get
|
---|
459 | {
|
---|
460 | return m_sDUZ2;
|
---|
461 | }
|
---|
462 | set
|
---|
463 | {
|
---|
464 | try
|
---|
465 | {
|
---|
466 | //Set DUZ(2) in M partition
|
---|
467 | DataTable dt = this.RPMSDataTable("BMXSetFac^" + value, "SetDUZ2");
|
---|
468 | Debug.Assert(dt.Rows.Count == 1);
|
---|
469 | DataRow dr = dt.Rows[0];
|
---|
470 | string sDUZ2 = dr["FACILITY_IEN"].ToString();
|
---|
471 | if (sDUZ2 != "0")
|
---|
472 | {
|
---|
473 | m_sDUZ2 = sDUZ2;
|
---|
474 | this.m_sDivision = dr["FACILITY_NAME"].ToString();
|
---|
475 | }
|
---|
476 | }
|
---|
477 | catch (Exception ex)
|
---|
478 | {
|
---|
479 | Debug.Write("DUZ2.Set failed: " + ex.Message + "\n");
|
---|
480 | }
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | /// <summary>
|
---|
485 | /// Gets the address of the RPMS Server
|
---|
486 | /// </summary>
|
---|
487 | public string MServerAddress
|
---|
488 | {
|
---|
489 | get
|
---|
490 | {
|
---|
491 | return this.m_sServerAddress;
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | /// <summary>
|
---|
496 | /// Gets the port on which the MServer is connected
|
---|
497 | /// </summary>
|
---|
498 | public int MServerPort
|
---|
499 | {
|
---|
500 | get
|
---|
501 | {
|
---|
502 | return this.m_nServerPort;
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | public DataTable UserDivisions
|
---|
507 | {
|
---|
508 | get
|
---|
509 | {
|
---|
510 | DataTable dt = this.GetUserDivisions();
|
---|
511 | return dt;
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | #endregion Properties
|
---|
516 |
|
---|
517 | #region Methods
|
---|
518 |
|
---|
519 | public void CloseConnection()
|
---|
520 | {
|
---|
521 | //TODO: Make thread safe
|
---|
522 | this.m_bAutoServer = false;
|
---|
523 | this.m_bAutoLogin = false;
|
---|
524 | m_BMXNetLib.CloseConnection();
|
---|
525 | }
|
---|
526 |
|
---|
527 | /// <summary>
|
---|
528 | /// For backwards compatibility. Internally calls LoadConnectInfo()
|
---|
529 | /// </summary>
|
---|
530 | public void Login()
|
---|
531 | {
|
---|
532 | LoadConnectInfo();
|
---|
533 | }
|
---|
534 |
|
---|
535 | /// <summary>
|
---|
536 | /// Change the internet address and port of the RPMS server
|
---|
537 | /// Throws a BMXNetException if user cancels
|
---|
538 | /// </summary>
|
---|
539 | public void ChangeServerInfo()
|
---|
540 | {
|
---|
541 | //Get existing values from isolated storage
|
---|
542 | ServerData serverData = new ServerData();
|
---|
543 | Stream stStorage = null;
|
---|
544 | try
|
---|
545 | {
|
---|
546 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly();
|
---|
547 | string sFileName = "mserver0200.dat";
|
---|
548 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Open, isStore);
|
---|
549 | IFormatter formatter = new SoapFormatter();
|
---|
550 | serverData = (ServerData) formatter.Deserialize(stStorage);
|
---|
551 | stStorage.Close();
|
---|
552 | }
|
---|
553 | catch (Exception ex)
|
---|
554 | {
|
---|
555 | Debug.Write(ex.Message);
|
---|
556 | if (stStorage != null)
|
---|
557 | stStorage.Close();
|
---|
558 | }
|
---|
559 |
|
---|
560 | try
|
---|
561 | {
|
---|
562 | DServerInfo dsi = new DServerInfo();
|
---|
563 | dsi.InitializePage(serverData.m_sAddress,serverData.m_nPort, serverData.m_sNamespace);
|
---|
564 | if (dsi.ShowDialog() != DialogResult.OK)
|
---|
565 | {
|
---|
566 | throw new BMXNetException("User cancelled.");
|
---|
567 | }
|
---|
568 | serverData.m_sAddress = dsi.MServerAddress;
|
---|
569 | serverData.m_nPort = dsi.MServerPort;
|
---|
570 | serverData.m_sNamespace = dsi.MServerNamespace;
|
---|
571 |
|
---|
572 | this.m_sServerAddress = dsi.MServerAddress;
|
---|
573 | this.m_nServerPort = dsi.MServerPort;
|
---|
574 | this.m_sServerNamespace = dsi.MServerNamespace;
|
---|
575 |
|
---|
576 | //Save port and address to isolated storage
|
---|
577 | try
|
---|
578 | {
|
---|
579 | string sFileName = "mserver0200.dat";
|
---|
580 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly();
|
---|
581 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Create, isStore);
|
---|
582 | IFormatter formatter = new SoapFormatter();
|
---|
583 | formatter.Serialize(stStorage, serverData);
|
---|
584 | stStorage.Close();
|
---|
585 | }
|
---|
586 | catch (Exception ex)
|
---|
587 | {
|
---|
588 | Debug.Write(ex.Message);
|
---|
589 | if (stStorage != null)
|
---|
590 | stStorage.Close();
|
---|
591 | }
|
---|
592 |
|
---|
593 | }
|
---|
594 | catch (Exception ex)
|
---|
595 | {
|
---|
596 | Debug.Write(ex.Message);
|
---|
597 | if (stStorage != null)
|
---|
598 | stStorage.Close();
|
---|
599 | if (ex.Message == "User cancelled.")
|
---|
600 | {
|
---|
601 | throw ex;
|
---|
602 | }
|
---|
603 | }
|
---|
604 |
|
---|
605 | }
|
---|
606 |
|
---|
607 | private void GetServerInfo(ref int nPort, ref string sAddress, ref string sNamespace)
|
---|
608 | {
|
---|
609 | //Get values from isolated storage
|
---|
610 | bool bLoaded = false;
|
---|
611 | Stream stStorage = null;
|
---|
612 | try
|
---|
613 | {
|
---|
614 | m_ServerData = new ServerData();
|
---|
615 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly();
|
---|
616 | string sFileName = "mserver0200.dat";
|
---|
617 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Open, isStore);
|
---|
618 | IFormatter formatter = new SoapFormatter();
|
---|
619 | m_ServerData = (ServerData) formatter.Deserialize(stStorage);
|
---|
620 | stStorage.Close();
|
---|
621 | sAddress = m_ServerData.m_sAddress;
|
---|
622 | nPort = m_ServerData.m_nPort;
|
---|
623 | sNamespace = m_ServerData.m_sNamespace;
|
---|
624 |
|
---|
625 | bLoaded = true;
|
---|
626 | return;
|
---|
627 | }
|
---|
628 | catch (Exception ex)
|
---|
629 | {
|
---|
630 | Debug.Write(ex.Message);
|
---|
631 | if (stStorage != null)
|
---|
632 | stStorage.Close();
|
---|
633 | }
|
---|
634 | try
|
---|
635 | {
|
---|
636 | //If unable to deserialize, display dialog to collect values
|
---|
637 | if (bLoaded == false)
|
---|
638 | {
|
---|
639 | DServerInfo dsi = new DServerInfo();
|
---|
640 | dsi.InitializePage("",10501,"");
|
---|
641 | if (dsi.ShowDialog() != DialogResult.OK)
|
---|
642 | {
|
---|
643 | throw new BMXNetException("Unable to get M Server information");
|
---|
644 | }
|
---|
645 | m_ServerData.m_sAddress = dsi.MServerAddress;
|
---|
646 | m_ServerData.m_nPort = dsi.MServerPort;
|
---|
647 | m_ServerData.m_sNamespace = dsi.MServerNamespace;
|
---|
648 | }
|
---|
649 |
|
---|
650 | sAddress = m_ServerData.m_sAddress;
|
---|
651 | nPort = m_ServerData.m_nPort;
|
---|
652 | sNamespace = m_ServerData.m_sNamespace;
|
---|
653 |
|
---|
654 | //Save port and address to isolated storage
|
---|
655 | try
|
---|
656 | {
|
---|
657 | string sFileName = "mserver0200.dat";
|
---|
658 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly();
|
---|
659 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Create, isStore);
|
---|
660 | IFormatter formatter = new SoapFormatter();
|
---|
661 | formatter.Serialize(stStorage, m_ServerData);
|
---|
662 | stStorage.Close();
|
---|
663 | }
|
---|
664 | catch (Exception ex)
|
---|
665 | {
|
---|
666 | Debug.Write(ex.Message);
|
---|
667 | if (stStorage != null)
|
---|
668 | stStorage.Close();
|
---|
669 | }
|
---|
670 |
|
---|
671 | return;
|
---|
672 | }
|
---|
673 | catch (Exception ex)
|
---|
674 | {
|
---|
675 | Debug.Write(ex.Message);
|
---|
676 | if (stStorage != null)
|
---|
677 | stStorage.Close();
|
---|
678 | throw ex;
|
---|
679 | }
|
---|
680 |
|
---|
681 | }
|
---|
682 |
|
---|
683 | /// <summary>
|
---|
684 | /// Called to connect to an M server
|
---|
685 | /// Server address, port, Access and Verify codes will be
|
---|
686 | /// prompted for depending on whether these values are
|
---|
687 | /// cached.
|
---|
688 | /// </summary>
|
---|
689 | public void LoadConnectInfo()
|
---|
690 | {
|
---|
691 | m_bAutoServer = true;
|
---|
692 | m_bAutoLogin = true;
|
---|
693 | LoadConnectInfo("",0,"","");
|
---|
694 | }
|
---|
695 |
|
---|
696 | /// <summary>
|
---|
697 | /// Called to connect to the M server specified by
|
---|
698 | /// server address and listener port. The default namespace on the server will be used.
|
---|
699 | /// Access and Verify codes will be prompted if
|
---|
700 | /// valid values for the current Windows Identity are
|
---|
701 | /// not cached on the server.
|
---|
702 | /// </summary>
|
---|
703 | /// <param name="MServerAddress">The IP address or name of the MServer</param>
|
---|
704 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param>
|
---|
705 | public void LoadConnectInfo(string MServerAddress, int Port)
|
---|
706 | {
|
---|
707 | LoadConnectInfo(MServerAddress, Port, "", "", "");
|
---|
708 | }
|
---|
709 |
|
---|
710 | /// <summary>
|
---|
711 | /// Called to connect to the M server specified by
|
---|
712 | /// server address, listener port and namespace.
|
---|
713 | /// Access and Verify codes will be prompted if
|
---|
714 | /// valid values for the current Windows Identity are
|
---|
715 | /// not cached on the server.
|
---|
716 | /// </summary>
|
---|
717 | /// <param name="MServerAddress">The IP address or name of the MServer</param>
|
---|
718 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param>
|
---|
719 | /// <param name="Namespace">The namespace in which the BMXNet application will run</param>
|
---|
720 | public void LoadConnectInfo(string MServerAddress, int Port, string Namespace)
|
---|
721 | {
|
---|
722 | m_bAutoServer = false;
|
---|
723 | m_bAutoLogin = true;
|
---|
724 | LoadConnectInfo(MServerAddress, Port,"","", Namespace);
|
---|
725 | }
|
---|
726 |
|
---|
727 | /// <summary>
|
---|
728 | /// Called to connect to an M server
|
---|
729 | /// using specific Access and Verify codes.
|
---|
730 | /// Server address and port will be prompted if they
|
---|
731 | /// are not cached in local storage.
|
---|
732 | /// </summary>
|
---|
733 | /// <param name="AccessCode">The user's access code</param>
|
---|
734 | /// <param name="VerifyCode">The user's verify code</param>
|
---|
735 | public void LoadConnectInfo(string AccessCode, string VerifyCode)
|
---|
736 | {
|
---|
737 | m_bAutoServer = true;
|
---|
738 | m_bAutoLogin = false;
|
---|
739 | LoadConnectInfo("", 0,AccessCode,VerifyCode);
|
---|
740 | }
|
---|
741 |
|
---|
742 | /// <summary>
|
---|
743 | /// Called to connect to a specific M server
|
---|
744 | /// using specific Access and Verify codes.
|
---|
745 | /// </summary>
|
---|
746 | /// <param name="AccessCode">The user's access code</param>
|
---|
747 | /// <param name="VerifyCode">The user's verify code</param>
|
---|
748 | /// <param name="MServerAddress">The IP address or name of the MServer</param>
|
---|
749 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param>
|
---|
750 | public void LoadConnectInfo(string MServerAddress, int Port,
|
---|
751 | string AccessCode, string VerifyCode)
|
---|
752 | {
|
---|
753 | LoadConnectInfo(MServerAddress, Port, AccessCode, VerifyCode, "");
|
---|
754 | }
|
---|
755 |
|
---|
756 | /// <summary>
|
---|
757 | /// Called to connect to a specific namespace on the M server
|
---|
758 | /// using specific Access and Verify codes.
|
---|
759 | /// </summary>
|
---|
760 | /// <param name="AccessCode">The user's access code</param>
|
---|
761 | /// <param name="VerifyCode">The user's verify code</param>
|
---|
762 | /// <param name="MServerAddress">The IP address or name of the MServer</param>
|
---|
763 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param>
|
---|
764 | /// <param name="Namespace">The namespace in which the BMXNet application will run</param>
|
---|
765 | public void LoadConnectInfo(string MServerAddress, int Port,
|
---|
766 | string AccessCode, string VerifyCode, string Namespace)
|
---|
767 | {
|
---|
768 | //Throws exception if unable to connect to RPMS
|
---|
769 |
|
---|
770 | /*
|
---|
771 | * Get RPMS Server Address and Port from local storage.
|
---|
772 | * Prompt for them if they're not there.
|
---|
773 | *
|
---|
774 | * Throw exception if unable to get address/port
|
---|
775 | */
|
---|
776 |
|
---|
777 | if (m_bAutoServer == true)
|
---|
778 | {
|
---|
779 | string sAddress = "";
|
---|
780 | int nPort = 0;
|
---|
781 | string sNamespace = "";
|
---|
782 | try
|
---|
783 | {
|
---|
784 | GetServerInfo(ref nPort, ref sAddress, ref sNamespace);
|
---|
785 | m_nServerPort = nPort;
|
---|
786 | m_sServerAddress = sAddress;
|
---|
787 | m_sServerNamespace = sNamespace;
|
---|
788 | }
|
---|
789 | catch (Exception ex)
|
---|
790 | {
|
---|
791 | Debug.Write(ex.Message);
|
---|
792 | throw ex;
|
---|
793 | }
|
---|
794 | }
|
---|
795 | else
|
---|
796 | {
|
---|
797 | m_sServerAddress = MServerAddress;
|
---|
798 | m_nServerPort = Port;
|
---|
799 | m_sServerNamespace = Namespace;
|
---|
800 | }
|
---|
801 |
|
---|
802 | /*
|
---|
803 | * Connect to RPMS using current windows identity
|
---|
804 | * Execute BMXNetGetCodes(NTDomain/UserName) to get encrypted AV codes
|
---|
805 | *
|
---|
806 | */
|
---|
807 |
|
---|
808 | m_BMXNetLib.CloseConnection();
|
---|
809 | m_BMXNetLib.MServerPort = m_nServerPort;
|
---|
810 | m_BMXNetLib.MServerNamespace = m_sServerNamespace;
|
---|
811 |
|
---|
812 | string sLoginError = "";
|
---|
813 | WindowsIdentity winIdentity = WindowsIdentity.GetCurrent();
|
---|
814 | string sIdentName = winIdentity.Name;
|
---|
815 | string sIdentType = winIdentity.AuthenticationType;
|
---|
816 | bool bIdentIsAuth = winIdentity.IsAuthenticated;
|
---|
817 | bool bRet = false;
|
---|
818 | if (m_bAutoLogin == true)
|
---|
819 | {
|
---|
820 | try
|
---|
821 | {
|
---|
822 | //Attempt Auto-login using WindowsIdentity
|
---|
823 |
|
---|
824 | if (bIdentIsAuth == false)
|
---|
825 | {
|
---|
826 | throw new BMXNetException("Current Windows User is not authenticated");
|
---|
827 | }
|
---|
828 | bRet = m_BMXNetLib.OpenConnection(m_sServerAddress, winIdentity);
|
---|
829 |
|
---|
830 | try
|
---|
831 | {
|
---|
832 | string sDuz = m_BMXNetLib.DUZ;
|
---|
833 | int nDuz = Convert.ToInt16(sDuz);
|
---|
834 | }
|
---|
835 | catch (Exception exCV)
|
---|
836 | {
|
---|
837 | Debug.Write("OpenConnection failed: " + exCV.Message);
|
---|
838 | //Debug.Assert(false);
|
---|
839 | throw new Exception(exCV.Message);
|
---|
840 | }
|
---|
841 | }
|
---|
842 | catch (Exception ex)
|
---|
843 | {
|
---|
844 | Debug.Write(ex.Message);
|
---|
845 | sLoginError = ex.Message;
|
---|
846 | }
|
---|
847 | }
|
---|
848 |
|
---|
849 | if (m_BMXNetLib.Connected == false) //BMXNET Login failed or m_bAutoLogin == false
|
---|
850 | {
|
---|
851 | try
|
---|
852 | {
|
---|
853 | //If autologin was attempted and
|
---|
854 | //error message anything other than
|
---|
855 | //"invalid AV code pair"
|
---|
856 | // or "User BMXNET,APPLICATION does not have access to option BMXRPC",
|
---|
857 | // or current windows user is not authenticated or is a guest
|
---|
858 | //then rethrow exception.
|
---|
859 | if ((m_bAutoLogin == true)
|
---|
860 | &&(BMXNetLib.FindSubString(sLoginError, "Not a valid ACCESS CODE/VERIFY CODE pair.") == -1)
|
---|
861 | &&(BMXNetLib.FindSubString(sLoginError, "User BMXNET,APPLICATION does not have access to option BMXRPC") == -1)
|
---|
862 | &&(BMXNetLib.FindSubString(sLoginError, "Not a valid Windows Identity map value.") == -1)
|
---|
863 | &&(BMXNetLib.FindSubString(sLoginError, "Current Windows User is not authenticated") == -1)
|
---|
864 | &&(BMXNetLib.FindSubString(sLoginError, "Windows Integrated Security Not Allowed on this port.") == -1)
|
---|
865 | )
|
---|
866 | {
|
---|
867 | throw new BMXNetException(sLoginError);
|
---|
868 | }
|
---|
869 |
|
---|
870 | //Display dialog to collect user-input AV
|
---|
871 |
|
---|
872 | DLoginInfo dLog = new DLoginInfo();
|
---|
873 | DialogResult bStop = DialogResult.OK;
|
---|
874 | m_BMXNetLib.CloseConnection();
|
---|
875 | if ((AccessCode == "") && (VerifyCode == ""))
|
---|
876 | {
|
---|
877 | //nothing was passed in, so display a dialog to collect AV codes
|
---|
878 | do
|
---|
879 | {
|
---|
880 | dLog.InitializePage("","");
|
---|
881 | bStop = dLog.ShowDialog();
|
---|
882 | if (bStop == DialogResult.Cancel)
|
---|
883 | {
|
---|
884 | throw new BMXNetException("User cancelled login.");
|
---|
885 | }
|
---|
886 | try
|
---|
887 | {
|
---|
888 | string sTempAccess = dLog.AccessCode;
|
---|
889 | string sTempVerify = dLog.VerifyCode;
|
---|
890 | bRet = m_BMXNetLib.OpenConnection(m_sServerAddress, sTempAccess, sTempVerify);
|
---|
891 | }
|
---|
892 | catch (Exception ex)
|
---|
893 | {
|
---|
894 | Debug.Write(ex.Message);
|
---|
895 | //MessageBox.Show(ex.Message, "RPMS Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
896 | throw new Exception(ex.Message); ;
|
---|
897 | }
|
---|
898 | }while ((bStop == DialogResult.OK) && (m_BMXNetLib.Connected == false));
|
---|
899 | }
|
---|
900 | else //caller passed in AV codes
|
---|
901 | {
|
---|
902 | try
|
---|
903 | {
|
---|
904 | //Connect using caller's AV
|
---|
905 | bRet = m_BMXNetLib.OpenConnection(m_sServerAddress, AccessCode, VerifyCode);
|
---|
906 | }
|
---|
907 | catch (Exception ex)
|
---|
908 | {
|
---|
909 | Debug.Write(ex.Message);
|
---|
910 | //MessageBox.Show(ex.Message, "RPMS Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
911 | throw new BMXNetException(ex.Message);
|
---|
912 | }
|
---|
913 | }
|
---|
914 |
|
---|
915 | //Map Windows Identity to logged-in RPMS user
|
---|
916 | if ((bIdentIsAuth == true) && (m_BMXNetLib.Connected == true))
|
---|
917 | {
|
---|
918 | m_BMXNetLib.AppContext = "BMXRPC";
|
---|
919 | string sRes = m_BMXNetLib.TransmitRPC("BMXNetSetUser", sIdentName);
|
---|
920 | Debug.Write("LoadConnectInfo BMXNetSetUser returned " + sRes + "\n");
|
---|
921 | }
|
---|
922 | }
|
---|
923 | catch (Exception ex)
|
---|
924 | {
|
---|
925 | Debug.Write(ex.Message);
|
---|
926 | m_BMXNetLib.CloseConnection();
|
---|
927 | throw ex; //this exception will be caught by the caller.
|
---|
928 | }
|
---|
929 | }//End if (m_BMXNetLib.Connected == false)
|
---|
930 |
|
---|
931 | try
|
---|
932 | {
|
---|
933 | Debug.Assert(m_BMXNetLib.Connected == true);
|
---|
934 | m_BMXNetLib.AppContext = "BMXRPC";
|
---|
935 | string sRpc = "BMX USER";
|
---|
936 | Debug.Assert(m_BMXNetLib.AppContext == "BMXRPC");
|
---|
937 |
|
---|
938 | bool bCtxt = false;
|
---|
939 | int nCtxt = 0;
|
---|
940 | do
|
---|
941 | {
|
---|
942 | try
|
---|
943 | {
|
---|
944 | m_sUserName = m_BMXNetLib.TransmitRPC(sRpc, this.DUZ);
|
---|
945 | bCtxt = true;
|
---|
946 | Debug.Write("BMXNet::LoadConnectInfo succeeded.\n");
|
---|
947 | }
|
---|
948 | catch (Exception ex)
|
---|
949 | {
|
---|
950 | Debug.Write("BMXNet::LoadConnectInfo retrying: " + ex.Message + "\n");
|
---|
951 | m_BMXNetLib.AppContext = "BMXRPC";
|
---|
952 | nCtxt++;
|
---|
953 | if (nCtxt > 4)
|
---|
954 | throw ex;
|
---|
955 | }
|
---|
956 | }while (bCtxt == false);
|
---|
957 |
|
---|
958 |
|
---|
959 | System.Data.DataTable rsDivisions;
|
---|
960 | rsDivisions = this.GetUserDivisions();
|
---|
961 | m_nDivisionCount = rsDivisions.Rows.Count;
|
---|
962 |
|
---|
963 | //The MOST_RECENT_LOOKUP field contains DUZ(2)
|
---|
964 | foreach (System.Data.DataRow r in rsDivisions.Rows)
|
---|
965 | {
|
---|
966 | string sTemp = r["MOST_RECENT_LOOKUP"].ToString();
|
---|
967 | if ((sTemp == "1") || (rsDivisions.Rows.Count == 1))
|
---|
968 | {
|
---|
969 | this.m_sDivision = r["FACILITY_NAME"].ToString();
|
---|
970 | this.m_sDUZ2 = r["FACILITY_IEN"].ToString();
|
---|
971 | break;
|
---|
972 | }
|
---|
973 | }
|
---|
974 | }
|
---|
975 | catch(Exception bmxEx)
|
---|
976 | {
|
---|
977 | m_BMXNetLib.CloseConnection();
|
---|
978 | string sMessage = bmxEx.Message + bmxEx.StackTrace;
|
---|
979 | throw new BMXNetException(sMessage);
|
---|
980 | }
|
---|
981 | return;
|
---|
982 | }
|
---|
983 |
|
---|
984 | private DataTable GetUserDivisions()
|
---|
985 | {
|
---|
986 | try
|
---|
987 | {
|
---|
988 | DataTable tb = this.RPMSDataTable("BMXGetFacRS^" + this.DUZ, "DivisionTable");
|
---|
989 | return tb;
|
---|
990 | }
|
---|
991 | catch (Exception bmxEx)
|
---|
992 | {
|
---|
993 | string sMessage = bmxEx.Message + bmxEx.StackTrace;
|
---|
994 | throw new BMXNetException(sMessage);
|
---|
995 |
|
---|
996 | }
|
---|
997 | }
|
---|
998 |
|
---|
999 | public void ChangeDivision(System.Windows.Forms.Form frmCaller)
|
---|
1000 | {
|
---|
1001 | DSelectDivision dsd = new DSelectDivision();
|
---|
1002 | dsd.InitializePage(UserDivisions, DUZ2);
|
---|
1003 |
|
---|
1004 | if (dsd.ShowDialog(frmCaller) == DialogResult.Cancel)
|
---|
1005 | return;
|
---|
1006 |
|
---|
1007 | if (dsd.DUZ2 != this.DUZ2)
|
---|
1008 | {
|
---|
1009 | DUZ2 = dsd.DUZ2;
|
---|
1010 | }
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | public string GetDSN(string sAppContext)
|
---|
1014 | {
|
---|
1015 | string sDsn = "Data source=";
|
---|
1016 | if (sAppContext == "")
|
---|
1017 | sAppContext = "BMXRPC";
|
---|
1018 |
|
---|
1019 | if (m_BMXNetLib.Connected == false)
|
---|
1020 | return sDsn.ToString();
|
---|
1021 |
|
---|
1022 | sDsn += this.m_sServerAddress ;
|
---|
1023 | sDsn += ";Location=";
|
---|
1024 | sDsn += this.m_nServerPort.ToString();
|
---|
1025 | sDsn += ";Extended Properties=";
|
---|
1026 | sDsn += sAppContext;
|
---|
1027 |
|
---|
1028 | return sDsn;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 |
|
---|
1032 | public bool Lock(string sVariable, string sIncrement, string sTimeOut)
|
---|
1033 | {
|
---|
1034 | bool bRet = false;
|
---|
1035 | string sErrorMessage = "";
|
---|
1036 |
|
---|
1037 | if (m_BMXNetLib.Connected == false)
|
---|
1038 | {
|
---|
1039 | return bRet;
|
---|
1040 | }
|
---|
1041 | try
|
---|
1042 | {
|
---|
1043 | bRet = this.bmxNetLib.Lock(sVariable, sIncrement, sTimeOut);
|
---|
1044 | return bRet;
|
---|
1045 | }
|
---|
1046 | catch(Exception ex)
|
---|
1047 | {
|
---|
1048 | sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message;
|
---|
1049 | throw ex;
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName);
|
---|
1054 | delegate DataTable RPMSDataTableDelegate2(string CommandString, string TableName, DataSet dsDataSet);
|
---|
1055 |
|
---|
1056 | /// <summary>
|
---|
1057 | /// Creates and names a DataTable using the command in CommandString
|
---|
1058 | /// and the name in TableName.
|
---|
1059 | /// </summary>
|
---|
1060 | /// <param name="CommandString"> The SQL or RPC call</param>
|
---|
1061 | /// <param name="TableName">The name of the resulting table</param>
|
---|
1062 | /// <returns>
|
---|
1063 | /// Returns the resulting DataTable.
|
---|
1064 | /// </returns>
|
---|
1065 | public DataTable RPMSDataTable(string CommandString, string TableName)
|
---|
1066 | {
|
---|
1067 | return this.RPMSDataTable(CommandString, TableName, null);
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | /// <summary>
|
---|
1071 | /// Creates and names a DataTable using the command in CommandString
|
---|
1072 | /// and the name in TableName then adds it to DataSet.
|
---|
1073 | /// </summary>
|
---|
1074 | /// <param name="CommandString">The SQL or RPC call</param>
|
---|
1075 | /// <param name="TableName">The name of the resulting table</param>
|
---|
1076 | /// <param name="dsDataSet">The dataset in which to place the table</param>
|
---|
1077 | /// <returns>
|
---|
1078 | /// Returns the resulting DataTable.
|
---|
1079 | /// </returns>
|
---|
1080 | public DataTable RPMSDataTable(string CommandString, string TableName, DataSet dsDataSet)
|
---|
1081 | {
|
---|
1082 | //Retrieves a recordset from RPMS
|
---|
1083 | //Debug.Assert(this.InvokeRequired == false);
|
---|
1084 | string sErrorMessage = "";
|
---|
1085 | DataTable dtResult = new DataTable(TableName);
|
---|
1086 |
|
---|
1087 | if (m_BMXNetLib.Connected == false)
|
---|
1088 | return dtResult;
|
---|
1089 |
|
---|
1090 | try
|
---|
1091 | {
|
---|
1092 | BMXNetConnection rpmsConn = new BMXNetConnection(m_BMXNetLib);
|
---|
1093 | BMXNetCommand cmd = (BMXNetCommand) rpmsConn.CreateCommand();
|
---|
1094 | BMXNetDataAdapter da = new BMXNetDataAdapter();
|
---|
1095 |
|
---|
1096 | cmd.CommandText = CommandString;
|
---|
1097 | da.SelectCommand = cmd;
|
---|
1098 | if (dsDataSet == null)
|
---|
1099 | {
|
---|
1100 | da.Fill(dtResult);
|
---|
1101 | }
|
---|
1102 | else
|
---|
1103 | {
|
---|
1104 | da.Fill(dsDataSet, TableName);
|
---|
1105 | dtResult = dsDataSet.Tables[TableName];
|
---|
1106 | }
|
---|
1107 | Debug.Write(dtResult.TableName + " DataTable retrieved\n");
|
---|
1108 | return dtResult;
|
---|
1109 | }
|
---|
1110 | catch (Exception ex)
|
---|
1111 | {
|
---|
1112 | sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message;
|
---|
1113 | throw ex;
|
---|
1114 | }
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | public int RPMSDataTableAsyncQue(string CommandString, string EventName)
|
---|
1118 | {
|
---|
1119 | try
|
---|
1120 | {
|
---|
1121 | string sCommand = "BMX ASYNC QUEUE^";
|
---|
1122 | //replace ^'s in CommandString with $c(30)'s
|
---|
1123 | char[] cDelim = new char[1];
|
---|
1124 | cDelim[0] = (char) 30;
|
---|
1125 | string sDelim = cDelim[0].ToString();
|
---|
1126 | CommandString = CommandString.Replace("^", sDelim);
|
---|
1127 | sCommand = sCommand + CommandString + "^" + EventName;
|
---|
1128 |
|
---|
1129 | DataTable dt = new DataTable();
|
---|
1130 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable);
|
---|
1131 | if (this.IsHandleCreated == false)
|
---|
1132 | {
|
---|
1133 | this.CreateHandle();
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | dt = (DataTable) this.Invoke(rdtd, new object[] {sCommand, "Que"});
|
---|
1137 |
|
---|
1138 | DataRow dr = dt.Rows[0];
|
---|
1139 | int nErrorID = Convert.ToInt32(dr["ERRORID"]);
|
---|
1140 | int nParam = Convert.ToInt32(dr["PARAM"]);
|
---|
1141 |
|
---|
1142 | if (nErrorID == 0)
|
---|
1143 | {
|
---|
1144 | return 0;
|
---|
1145 | }
|
---|
1146 | else
|
---|
1147 | {
|
---|
1148 | return nParam;
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 | catch (Exception ex)
|
---|
1152 | {
|
---|
1153 | Debug.Write("RPMSDataTableAsyncQue error: " + ex.Message + "\n");
|
---|
1154 | throw ex;
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | public DataTable RPMSDataTableAsyncGet(string AsyncInfo, string TableName)
|
---|
1159 | {
|
---|
1160 | return RPMSDataTableAsyncGet(AsyncInfo, TableName, null);
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | public DataTable RPMSDataTableAsyncGet(string AsyncInfo, string TableName, DataSet dsDataSet)
|
---|
1164 | {
|
---|
1165 | try
|
---|
1166 | {
|
---|
1167 | string sCommand = "BMX ASYNC GET^" + AsyncInfo;
|
---|
1168 |
|
---|
1169 | DataTable dt;
|
---|
1170 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable);
|
---|
1171 | RPMSDataTableDelegate2 rdtd2 = new RPMSDataTableDelegate2(RPMSDataTable);
|
---|
1172 | if (this.IsHandleCreated == false)
|
---|
1173 | {
|
---|
1174 | this.CreateHandle();
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | if (dsDataSet == null)
|
---|
1178 | {
|
---|
1179 | dt = (DataTable) this.Invoke(rdtd, new object[] {sCommand, TableName});
|
---|
1180 | }
|
---|
1181 | else
|
---|
1182 | {
|
---|
1183 | dt = (DataTable) this.Invoke(rdtd2, new object[] {sCommand, TableName, dsDataSet});
|
---|
1184 | }
|
---|
1185 | return dt;
|
---|
1186 | }
|
---|
1187 | catch (Exception ex)
|
---|
1188 | {
|
---|
1189 | Debug.Write("RPMSDataTableAsyncGet error: " + ex.Message + "\n");
|
---|
1190 | throw ex;
|
---|
1191 | }
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | #endregion Methods
|
---|
1195 |
|
---|
1196 | }
|
---|
1197 | }
|
---|