source: Scheduling/branches/BMX4Support/ConnectInfo.cs@ 1213

Last change on this file since 1213 was 614, checked in by Sam Habiel, 15 years ago

Initial committ of scheduling package

File size: 6.3 KB
Line 
1using System;
2using System.Windows.Forms;
3//using RPX20Lib;
4using System.Data;
5//using System.Data.OleDb;
6using System.Text;
7using IndianHealthService.BMXNet;
8using System.Reflection;
9using System.Diagnostics;
10
11namespace IndianHealthService.ClinicalScheduling
12{
13 /// <summary>
14 /// Contains information about the RPMS connection
15 /// </summary>
16 public class CGConnectInfo
17 {
18 public CGConnectInfo()
19 {
20 //
21 // TODO: Add constructor logic here
22 //
23 }
24
25 private bool m_bConnected;
26 string m_sVerify;
27 string m_sAccess;
28 string m_sServerAddress;
29 int m_nServerPort;
30 private string m_sDUZ;
31 private string m_sDUZ2;
32 private int m_nDivisionCount = 0;
33 private string m_sUserName;
34 private string m_sDivision;
35
36
37
38 public bool Connected
39 {
40 get
41 {
42 return m_bConnected;
43 }
44 }
45
46 public bool LoadConnectInfo()
47 {
48
49 //Returns True if able to connect to RPMS
50
51
52 //Step 1
53 //Get RPMS Server Address and Port from Registry.
54 //Prompt for them if they're not there.
55 //Return False if unable to get address/port
56
57
58
59///////////////////////////////////////////////////////////////////
60
61///////////////////////////////////////////////////////////////////
62
63 //Old Version Below:
64 //Loads and decypts M Connection info from registry
65 //Tests connection
66 //Sets m_bConnected based on test
67 //returns m_bConnected
68
69 //(see ConnectInfo.cpp)
70
71 string sTempAddress;
72 sTempAddress = "127.0.0.1";
73// sTempAddress = "161.223.91.10";
74 int nTempPort = 0;
75
76 // Load from registry (HKCU)
77
78 // Decrypt Access and Verify codes
79
80 string sTempAccess2 = "HMWXXX8"; //TODO: Get from registry
81// sTempAccess2 = "JANXXX1"; //TODO: Get from registry
82// if (!DecryptString(pbAccessData, &lAccessSize, sTempAccess2))
83// return FALSE;
84//
85 string sTempVerify2 = "MOLLYB8"; //TODO: Get from registry
86// sTempVerify2 = "JANXXX2"; //TODO: Get from registry
87// if (!DecryptString(pbVerifyData, &lVerifySize, sTempVerify2))
88// return FALSE;
89
90 m_sAccess = sTempAccess2;
91 m_sVerify = sTempVerify2;
92 m_sServerAddress = sTempAddress;
93 if (m_sServerAddress == "")
94 {
95 m_sServerAddress = "RPMSWindow";
96 m_sAccess = "";
97 m_sVerify = "";
98 }
99 m_nServerPort = nTempPort;
100 if (m_nServerPort == 0)
101 m_nServerPort = 9200;
102
103// RPX20Lib.MConnect m;
104// m = new MConnectClass();
105 BMXNetLib m = new BMXNetLib();
106 m.MServerPort = m_nServerPort;
107 m.AppContext="BMXRPC";
108 bool bRet = false;
109 try
110 {
111 bRet = m.OpenConnection(sTempAddress, sTempAccess2, sTempVerify2);
112 }
113 catch (BMXNetException exBMX)
114 {
115 throw exBMX;
116 }
117 catch (Exception bmxEx)
118 {
119 string sMessage = bmxEx.Message + bmxEx.StackTrace;
120 throw new BMXNetException(sMessage);
121 }
122
123 if (bRet == true){
124 try {
125 this.m_sAccess = sTempAccess2;
126 this.m_sVerify = sTempVerify2;
127 this.m_sServerAddress = sTempAddress;
128 this.m_nServerPort = m.MServerPort;
129 this.m_sDUZ = m.DUZ;
130
131 string sRpc = "BMX USER";
132 m_sUserName = m.TransmitRPC(sRpc, m_sDUZ);
133
134
135 System.Data.DataTable rsDivisions;
136 rsDivisions = this.GetUserDivisions(m_sAccess, m_sVerify, m_sServerAddress, m_nServerPort);
137 m_nDivisionCount = rsDivisions.Rows.Count;
138
139 foreach (System.Data.DataRow r in rsDivisions.Rows)
140 {
141 string sTemp = r["MOST_RECENT_LOOKUP"].ToString();
142 if (sTemp == "1")
143 {
144 this.m_sDivision = r["FACILITY_NAME"].ToString();
145 this.m_sDUZ2 = r["FACILITY_IEN"].ToString();
146 break;
147 }
148 }
149
150 m_bConnected = true;
151 }
152 catch(Exception bmxEx)
153 {
154 m_bConnected = false;
155 string sMessage = bmxEx.Message + bmxEx.StackTrace;
156 throw new BMXNetException(sMessage);
157 }
158 }
159
160 return m_bConnected;
161 }
162
163 bool TestConnection(string sAccess, string sVerify, string sAddress, int nPort)
164 {
165 // Try RPMS Connection & set m_bconnected TRUE if successful
166// RPX20Lib.MConnect m;
167// m = new MConnectClass();
168 BMXNetLib m = new BMXNetLib();
169 bool bRet = false;
170 try
171 {
172 //from old MServices->Login
173 m.MServerPort = nPort;
174 bRet = m.OpenConnection(sAddress, sAccess, sVerify);
175 this.m_sDUZ = m.DUZ;
176 }
177 catch(Exception ex)
178 {
179 Debug.Write("CConnectInfo::TestConnection: Error: " + ex.Message);
180 bRet = false;
181 }
182 finally
183 {
184 m.CloseConnection();
185 }
186 return bRet;
187 }
188
189 private DataTable GetUserDivisions(string sTempAccess2, string sTempVerify2, string sTempAddress, int MServerPort)
190 {
191 try
192 {
193 //Connection string model:
194 //"Provider=BMXODB.RPMS.1;Data source=127.0.0.1;Location=9200;Extended Properties=BMXRPC;Password=HMWXXX8^MOLLYB8"
195 string sConn;
196 sConn = "Data source=" + sTempAddress + ";Location=" + MServerPort.ToString() + ";Extended Properties=BMXRPC;Password=" + sTempAccess2 + "^" + sTempVerify2;
197 BMXNetConnection rpmsConn = new BMXNetConnection(sConn);
198 rpmsConn.Open();
199
200 BMXNetCommand cmd = (BMXNetCommand) rpmsConn.CreateCommand();
201 cmd.CommandText = "BMXGetFacRS^" + m_sDUZ;
202
203 BMXNetDataAdapter da = new BMXNetDataAdapter();
204 da.SelectCommand = cmd;
205
206 DataSet dsDivisions = new DataSet("Divisions");
207 da.Fill(dsDivisions, "DivisionTable");
208 DataTable tb = dsDivisions.Tables["DivisionTable"];
209 return tb;
210 }
211 catch (Exception bmxEx)
212 {
213 string sMessage = bmxEx.Message + bmxEx.StackTrace;
214 throw new BMXNetException(sMessage);
215
216 }
217 }
218
219 public string UserName
220 {
221 get
222 {
223 return this.m_sUserName;
224 }
225 }
226
227 public string DivisionName
228 {
229 get
230 {
231 return this.m_sDivision;
232 }
233 }
234
235 public string GetDSN(string sAppContext)
236 {
237 string sDsn = "Data source=";
238 if (sAppContext == "")
239 sAppContext = "BMXRPC";
240
241 if (this.m_bConnected == false)
242 return sDsn.ToString();
243
244 sDsn += this.m_sServerAddress ;
245 sDsn += ";Location=";
246 sDsn += this.m_nServerPort.ToString();
247 sDsn += ";Extended Properties=";
248 sDsn += sAppContext;
249 sDsn += ";Password=";
250 sDsn += this.m_sAccess;
251 sDsn += "^";
252 sDsn += this.m_sVerify;
253
254 return sDsn;
255 }
256
257 /// <summary>
258 /// String representation of DUZ
259 /// </summary>
260 public string DUZ
261 {
262 get
263 {
264 return m_sDUZ;
265 }
266 }
267
268
269 }
270}
Note: See TracBrowser for help on using the repository browser.