diff --git a/cs/bmx_0200scr/BMX2/BMXNet.sln b/cs/bmx_0200scr/BMX2/BMXNet.sln new file mode 100644 index 0000000..3879039 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet.sln @@ -0,0 +1,25 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BMXNetTest", "BMXNetTest\BMXNetTest.csproj", "{A3A19C51-73D2-4EEE-A190-F1EFBF477BCB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BMXNet", "BMXNet\BMXNet.csproj", "{DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A3A19C51-73D2-4EEE-A190-F1EFBF477BCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3A19C51-73D2-4EEE-A190-F1EFBF477BCB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3A19C51-73D2-4EEE-A190-F1EFBF477BCB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3A19C51-73D2-4EEE-A190-F1EFBF477BCB}.Release|Any CPU.Build.0 = Release|Any CPU + {DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/cs/bmx_0200scr/BMX2/BMXNet.suo b/cs/bmx_0200scr/BMX2/BMXNet.suo new file mode 100644 index 0000000..2d0365a Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNet.suo differ diff --git a/cs/bmx_0200scr/BMX2/BMXNet/AssemblyInfo.cs b/cs/bmx_0200scr/BMX2/BMXNet/AssemblyInfo.cs new file mode 100644 index 0000000..e85b360 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/AssemblyInfo.cs @@ -0,0 +1,61 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("BMXNet20")] +[assembly: AssemblyDescription("ADO.NET 2.0 Data Provider for RPMS")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Indian Health Service")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("2.0.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] +//[assembly: AssemblyKeyName("")] +[assembly: AssemblyFileVersionAttribute("2.0.0.0")] +[assembly: ComVisibleAttribute(false)] diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNet.csproj b/cs/bmx_0200scr/BMX2/BMXNet/BMXNet.csproj new file mode 100644 index 0000000..4580b81 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNet.csproj @@ -0,0 +1,161 @@ + + + Local + 8.0.50727 + 2.0 + {DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45} + Debug + AnyCPU + + + + + BMXNet20 + IHSPrivateKey.pfx + JScript + Grid + IE50 + true + Library + BMXNet + OnBuildSuccess + + + + + + + true + + + bin\Debug\ + false + 285212672 + false + + + DEBUG;TRACE + bmxnet.xml + true + 4096 + false + 1591 + false + false + false + false + 4 + full + prompt + + + bin\Release\ + false + 285212672 + false + + + TRACE + bmxnet.xml + false + 4096 + false + 1591 + true + false + false + false + 4 + none + prompt + + + + System + + + System.Data + + + System.Drawing + + + System.Runtime.Serialization.Formatters.Soap + + + System.Windows.Forms + + + System.XML + + + + + Code + + + Component + + + Component + + + Component + + + Component + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Form + + + Form + + + Form + + + Code + + + DLoginInfo.cs + Designer + + + DSelectDivision.cs + Designer + + + DServerInfo.cs + Designer + + + + + + + + + + + + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNet.csproj.user b/cs/bmx_0200scr/BMX2/BMXNet/BMXNet.csproj.user new file mode 100644 index 0000000..97b1cb2 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNet.csproj.user @@ -0,0 +1,55 @@ + + + 7.10.3077 + Debug + AnyCPU + c:\documents and settings\administrator\my documents\visual studio projects\clinicalscheduling\calendargrid\bin\release\ + + + + + 0 + ProjectFiles + 0 + + + false + false + false + false + false + + + Program + http://homedev.ihs.gov/otherprgms/clinicalscheduling/ClinicalScheduling.exe + + + C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\IEExec.exe + + + + + true + + + false + false + false + false + false + + + Project + + + + + + + + + + + false + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetAdapter.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetAdapter.cs new file mode 100644 index 0000000..74e85fa --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetAdapter.cs @@ -0,0 +1,374 @@ +using System; +using System.Data; +using System.Data.Common; + +namespace IndianHealthService.BMXNet +{ + public class BMXNetDataAdapter : DbDataAdapter, IDbDataAdapter + { + private BMXNetCommand m_selectCommand; + private BMXNetCommand m_insertCommand; + private BMXNetCommand m_updateCommand; + private BMXNetCommand m_deleteCommand; + + /* + * Inherit from Component through DbDataAdapter. The event + * mechanism is designed to work with the Component.Events + * property. These variables are the keys used to find the + * events in the components list of events. + */ + static private readonly object EventRowUpdated = new object(); + static private readonly object EventRowUpdating = new object(); + + public BMXNetDataAdapter() + { + } + + new public BMXNetCommand SelectCommand + { + get { return m_selectCommand; } + set { m_selectCommand = value; } + } + + IDbCommand IDbDataAdapter.SelectCommand + { + get { return m_selectCommand; } + set { m_selectCommand = (BMXNetCommand)value; } + } + + new public BMXNetCommand InsertCommand + { + get { return m_insertCommand; } + set { m_insertCommand = value; } + } + + IDbCommand IDbDataAdapter.InsertCommand + { + get { return m_insertCommand; } + set { m_insertCommand = (BMXNetCommand)value; } + } + + new public BMXNetCommand UpdateCommand + { + get { return m_updateCommand; } + set { m_updateCommand = value; } + } + + IDbCommand IDbDataAdapter.UpdateCommand + { + get { return m_updateCommand; } + set { m_updateCommand = (BMXNetCommand)value; } + } + + new public BMXNetCommand DeleteCommand + { + get { return m_deleteCommand; } + set { m_deleteCommand = value; } + } + + IDbCommand IDbDataAdapter.DeleteCommand + { + get { return m_deleteCommand; } + set { m_deleteCommand = (BMXNetCommand)value; } + } + + /* + * Implement abstract methods inherited from DbDataAdapter. + */ + + public override int Fill( + DataSet ds + ) + { + //The inital call to base.fill calls the RPC which loads up the array + //After base.fill returns, create a datareader + BMXNetConnection bmxConn = (BMXNetConnection) this.SelectCommand.Connection; + RPMSDb bmxDB = bmxConn.RPMSDb; + + DataTable dt = new DataTable(); + + //Execute the RPC call + base.Fill(dt); + //Get the table name + dt.TableName = bmxDB.ResultSets[0].fmFileID; + dt.ExtendedProperties.Add("fmSeed", bmxDB.ResultSets[0].fmSeed); + + + string sParentTable = dt.TableName; + + //Add the first table to the DataSet + ds.Tables.Add(dt); + + //If bmxDB resultset array count is greater than 1 + int nSets = bmxDB.ResultSets.GetUpperBound(0) + 1; + + if (nSets > 1) + { + //Set primary key for first table + string sKeyField = bmxDB.ResultSets[0].fmKeyField; + DataColumn dcKey = dt.Columns[sKeyField]; + DataColumn[] dcKeys = new DataColumn[1]; + dcKeys[0] = dcKey; + dt.PrimaryKey = dcKeys; + + string[] sRelations = new string[nSets]; + + //loop and get the rest of the tables + for (int k = 1; k < nSets; k++) + { + //Increment the current recordset counter in bmxDB + bmxDB.CurrentRecordSet++; + //Create the next table + dt = new DataTable(); + //Fill it + base.Fill(dt); + //Get the table name + string sChildTable = bmxDB.ResultSets[k].fmFileID; + dt.TableName = sChildTable; + //Add it to the dataset + ds.Tables.Add(dt); + + //Get the foreign key field + string sForeignKey = bmxDB.ResultSets[k].fmForeignKey; + + //Set the data relationship + string sParentKey; + sParentKey = "BMXIEN"; + sParentKey = "PATIENT_IEN"; + + DataRelation dr = new DataRelation("Relation" + k.ToString() , //Relation Name + ds.Tables[sParentTable].Columns[sParentKey], //; //parent + ds.Tables[sChildTable].Columns[sForeignKey]) ;//child + ds.Relations.Add(dr); + } + bmxDB.CurrentRecordSet = 0; + } + return dt.Rows.Count; + } + + override protected DataTable FillSchema( + DataTable dataTable, + SchemaType schemaType, + IDbCommand command, + CommandBehavior behavior + ) + { + behavior = CommandBehavior.SchemaOnly; + BMXNetDataReader dReader =(BMXNetDataReader) command.ExecuteReader(behavior); + DataTable dtSchema = dReader.GetSchemaTable(); + return dtSchema; + } + + override protected int Update( + DataRow[] dataRows, + DataTableMapping tableMapping + ) + { + //Build UpdateCommand's m_sCmdText using UpdateCommand's parameters + // and data in dataRows; + // execute non query and increment nRet; + + string sCmd = ""; + int nRecordsAffected = 0; + + //Get recordset-level info from parameters + BMXNetParameter parm = (BMXNetParameter) UpdateCommand.Parameters[0]; + string sFileID = parm.SourceColumn; + parm = (BMXNetParameter) UpdateCommand.Parameters[1]; + string sKeyField = parm.SourceColumn; + string sKeyID = ""; + char[] cRecDelim = new char[1]; + cRecDelim[0] = (char) 30; + + string sValue = ""; + string sFMFieldID; + string sColumnName; + int nColIndex; + + //Process deletions + foreach (DataRow r in dataRows) + { + if (r.RowState == DataRowState.Deleted) + { + r.RejectChanges(); //so that I can get to the row id + //Build DAS + char cSep = Convert.ToChar(","); + string[] saKeyFields = sKeyField.Split(cSep); + string sTmp = ""; + for (int j = 0; j < saKeyFields.GetLength(0); j++) + { + if (saKeyFields[j] != "") + { + if (j > 0) + sTmp = sTmp + ","; + if (j == saKeyFields.GetLength(0) - 1) + sTmp += "-"; + sTmp += r[saKeyFields[j]]; + } + } + sCmd = sTmp; + sCmd = sFileID + "^" + sCmd + "^"; + UpdateCommand.CommandText = "UPDATE " + sCmd; + int nRet = this.UpdateCommand.ExecuteNonQuery(); + r.Delete(); + nRecordsAffected += nRet; + } + } + + //Process Edits and Adds + foreach (DataRow r in dataRows) + { + if (r.RowState != DataRowState.Deleted) + { + string sMsg = ""; + sKeyID = ""; + for (int j=2; j < UpdateCommand.Parameters.Count; j++) + { + parm = (BMXNetParameter) UpdateCommand.Parameters[j]; + sColumnName = parm.ParameterName; + sFMFieldID = parm.SourceColumn; + //Find a column id in r whose column name is sColumnName + nColIndex = -1; + for (int k = 0; k < r.Table.Columns.Count; k ++) + { + if (r.Table.Columns[k].ColumnName == sColumnName) + { + nColIndex = k; + break; + } + } + if (nColIndex > -1) + { + if (r.ItemArray[nColIndex].GetType() == typeof(System.DateTime)) + { + DateTime dValue = (DateTime) r.ItemArray[nColIndex]; + if ((dValue.Minute == 0) && (dValue.Hour == 0)) + { + sValue = dValue.ToString("M-d-yyyy"); + } + else + { + sValue = dValue.ToString("M-d-yyyy@HH:mm"); + } + } + else + { + sValue = r.ItemArray[nColIndex].ToString(); + } + if (parm.IsKey == false) + { + if (sMsg != "") + sMsg += (char) 30; + sMsg += sFMFieldID + "|" + sValue; + } + } + switch (sFMFieldID) + { + case ".0001": + if (sKeyID == "") + { + sKeyID = sValue + ","; + } + else + { + sKeyID = sValue + "," + sKeyID; + } + break; + case ".001": + if (sKeyID == "") + { + sKeyID = sValue; + } + else + { + sKeyID = sKeyID + sValue; + } + break; + default: + break; + + } + } + sCmd = sFileID + "^" + sKeyID + "^" + sMsg; + UpdateCommand.CommandText = "UPDATE " + sCmd; + int nRet = this.UpdateCommand.ExecuteNonQuery(); + nRecordsAffected += nRet; + }//end if RowState != deleted + }//end for + + return nRecordsAffected; + } + + override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) + { + return new BMXNetRowUpdatedEventArgs(dataRow, command, statementType, tableMapping); + } + + override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) + { + return new BMXNetRowUpdatingEventArgs(dataRow, command, statementType, tableMapping); + } + + override protected void OnRowUpdating(RowUpdatingEventArgs value) + { + BMXNetRowUpdatingEventHandler handler = (BMXNetRowUpdatingEventHandler) Events[EventRowUpdating]; + if ((null != handler) && (value is BMXNetRowUpdatingEventArgs)) + { + handler(this, (BMXNetRowUpdatingEventArgs) value); + } + } + + override protected void OnRowUpdated(RowUpdatedEventArgs value) + { + BMXNetRowUpdatedEventHandler handler = (BMXNetRowUpdatedEventHandler) Events[EventRowUpdated]; + if ((null != handler) && (value is BMXNetRowUpdatedEventArgs)) + { + handler(this, (BMXNetRowUpdatedEventArgs) value); + } + } + + public event BMXNetRowUpdatingEventHandler RowUpdating + { + add { Events.AddHandler(EventRowUpdating, value); } + remove { Events.RemoveHandler(EventRowUpdating, value); } + } + + public event BMXNetRowUpdatedEventHandler RowUpdated + { + add { Events.AddHandler(EventRowUpdated, value); } + remove { Events.RemoveHandler(EventRowUpdated, value); } + } + } + + public delegate void BMXNetRowUpdatingEventHandler(object sender, BMXNetRowUpdatingEventArgs e); + public delegate void BMXNetRowUpdatedEventHandler(object sender, BMXNetRowUpdatedEventArgs e); + + public class BMXNetRowUpdatingEventArgs : RowUpdatingEventArgs + { + public BMXNetRowUpdatingEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) + : base(row, command, statementType, tableMapping) + { + } + + // Hide the inherited implementation of the command property. + new public BMXNetCommand Command + { + get { return (BMXNetCommand)base.Command; } + set { base.Command = value; } + } + } + + public class BMXNetRowUpdatedEventArgs : RowUpdatedEventArgs + { + public BMXNetRowUpdatedEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) + : base(row, command, statementType, tableMapping) + { + } + + // Hide the inherited implementation of the command property. + new public BMXNetCommand Command + { + get { return (BMXNetCommand)base.Command; } + } + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetCommand.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetCommand.cs new file mode 100644 index 0000000..ea6f1d7 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetCommand.cs @@ -0,0 +1,344 @@ +using System; +using System.Data; +using System.Data.Common; + +namespace IndianHealthService.BMXNet +{ + public class BMXNetCommand : System.Data.Common.DbCommand, IDbCommand + { + BMXNetConnection m_connection; + BMXNetTransaction m_txn; + string m_sCmdText; + UpdateRowSource m_updatedRowSource = UpdateRowSource.None; + BMXNetParameterCollection m_parameters = new BMXNetParameterCollection(); + + // the default constructor + public BMXNetCommand() + { + } + + // other constructors + public BMXNetCommand(string cmdText) + { + m_sCmdText = cmdText; + } + + public BMXNetCommand(string cmdText, BMXNetConnection connection) + { + m_sCmdText = cmdText; + m_connection = connection; + } + + public BMXNetCommand(string cmdText, BMXNetConnection connection, BMXNetTransaction txn) + { + m_sCmdText = cmdText; + m_connection = connection; + m_txn = txn; + } + + /**** + * IMPLEMENT THE REQUIRED PROPERTIES. + ****/ + override public string CommandText + { + get { return m_sCmdText; } + set { m_sCmdText = value; } + } + + override public int CommandTimeout + { + /* + * BMXNet does not support a command time-out. As a result, + * for the get, zero is returned because zero indicates an indefinite + * time-out period. For the set, throw an exception. + */ + get { return 0; } + set { if (value != 0) throw new NotSupportedException(); } + } + + override public CommandType CommandType + { + /* + * BMXNet only supports CommandType.Text. + */ + get { return CommandType.Text; } + set { if (value != CommandType.Text) throw new NotSupportedException(); } + } + + protected override DbConnection DbConnection + { + get + { + return m_connection; + } + set + { + if (m_connection != value) + this.Transaction = null; + + m_connection = (BMXNetConnection)value; + } + } + + new public IDbConnection Connection + { + /* + * The user should be able to set or change the connection at + * any time. + */ + get { return m_connection; } + set + { + /* + * The connection is associated with the transaction + * so set the transaction object to return a null reference if the connection + * is reset. + */ + if (m_connection != value) + this.Transaction = null; + + m_connection = (BMXNetConnection)value; + } + } + + new public BMXNetParameterCollection Parameters + { + get { return m_parameters; } + } + + IDataParameterCollection IDbCommand.Parameters + { + get { return m_parameters; } + } + + override protected DbParameterCollection DbParameterCollection + { + get + { + throw new Exception("The method or operation is not implemented."); + } + } + + new public IDbTransaction Transaction + { + /* + * Set the transaction. Consider additional steps to ensure that the transaction + * is compatible with the connection, because the two are usually linked. + */ + get { return m_txn; } + set { m_txn = (BMXNetTransaction)value; } + } + + override protected DbTransaction DbTransaction + { + /* + * Set the transaction. Consider additional steps to ensure that the transaction + * is compatible with the connection, because the two are usually linked. + */ + get + { + throw new Exception("The method or operation is not implemented."); + } + set + { + throw new Exception("The method or operation is not implemented."); + } + } + + override public bool DesignTimeVisible + { + get + {return false ; } + set { ;} + } + + override public UpdateRowSource UpdatedRowSource + { + get { return m_updatedRowSource; } + set { m_updatedRowSource = value; } + } + + + /**** + * IMPLEMENT THE REQUIRED METHODS. + ****/ + override public void Cancel() + { + // BMXNet does not support canceling a command + // once it has been initiated. + throw new NotSupportedException(); + } + + new public IDbDataParameter CreateParameter() + { + return (IDbDataParameter)(new BMXNetParameter()); + } + + override protected DbParameter CreateDbParameter() + { + throw new Exception("The method or operation is not implemented."); + } + + override public int ExecuteNonQuery() + { + /* + * ExecuteNonQuery is intended for commands that do + * not return results, instead returning only the number + * of records affected. + */ + + // There must be a valid and open connection. + if (m_connection == null || m_connection.State != ConnectionState.Open) + throw new InvalidOperationException("Connection must valid and open"); + + // Execute the command. + RPMSDb.RPMSDbResultSet resultset; + m_connection.RPMSDb.Execute(m_sCmdText, out resultset); + + // Return the number of records affected. + return resultset.recordsAffected; + } + + new public IDataReader ExecuteReader() + { + /* + * ExecuteReader should retrieve results from the data source + * and return a DataReader that allows the user to process + * the results. + */ + // There must be a valid and open connection. + if (m_connection == null || m_connection.State != ConnectionState.Open) + throw new InvalidOperationException("Connection must valid and open"); + + // Execute the command. + RPMSDb.RPMSDbResultSet resultset; + m_connection.RPMSDb.Execute(m_sCmdText, out resultset); + + return new BMXNetDataReader(resultset); + } + + new public IDataReader ExecuteReader(CommandBehavior behavior) + { + /* + * ExecuteReader should retrieve results from the data source + * and return a DataReader that allows the user to process + * the results. + */ + + // There must be a valid and open connection. + if (m_connection == null || m_connection.State != ConnectionState.Open) + throw new InvalidOperationException("Connection must valid and open"); + + /*If SchemaOnly or KeyInfo behavior, Set BMXSchema flag + *execute the command, then unset the BMXSchema flag + *Otherwise, just Execute the command. + */ + RPMSDb.RPMSDbResultSet resultset; + if (((behavior & (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo)) > 0)) + { + m_connection.bmxNetLib.TransmitRPC("BMX SCHEMA ONLY", "TRUE"); + m_connection.RPMSDb.Execute(m_sCmdText, out resultset); + m_connection.bmxNetLib.TransmitRPC("BMX SCHEMA ONLY", "FALSE"); + } + else + { + m_connection.RPMSDb.Execute(m_sCmdText, out resultset); + } + + /* + * The only CommandBehavior option supported by BMXNet + * is the automatic closing of the connection + * when the user is done with the reader. + */ + if (behavior == CommandBehavior.CloseConnection) + return new BMXNetDataReader(resultset, m_connection); + else + return new BMXNetDataReader(resultset); + } + + override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) + { + throw new Exception("The method or operation is not implemented."); + } + + override public object ExecuteScalar() + { + /* + * ExecuteScalar assumes that the command will return a single + * row with a single column, or if more rows/columns are returned + * it will return the first column of the first row. + */ + + // There must be a valid and open connection. + if (m_connection == null || m_connection.State != ConnectionState.Open) + throw new InvalidOperationException("Connection must valid and open"); + + // Execute the command. + RPMSDb.RPMSDbResultSet resultset; + m_connection.RPMSDb.Execute(m_sCmdText, out resultset); + + // Return the first column of the first row. + // Return a null reference if there is no data. + if (resultset.data.Length == 0) + return null; + + return resultset.data[0, 0]; + } + + override public void Prepare() + { + // BMXNet Prepare is a no-op. + } + + void IDisposable.Dispose() + { + this.Dispose(true); + System.GC.SuppressFinalize(this); + } + + //private void Dispose(bool disposing) + //{ + // /* + // * Dispose of the object and perform any cleanup. + // */ + //} + + /**** + * IMPLEMENT BMX-Specific METHODS. + ****/ + public void BMXBuildUpdateCommand(DataTable dtSchema) + { + string sText = "UPDATE "; + sText += "@File, "; + sText += "@Record, "; + + //Build Parameters array + BMXNetParameter[] parms = new BMXNetParameter[dtSchema.Rows.Count+2]; + + parms[0] = new BMXNetParameter("@File", DbType.String); + parms[0].SourceVersion = DataRowVersion.Original; + parms[0].SourceColumn = dtSchema.ExtendedProperties["BMXTable"].ToString(); + Parameters.Add(parms[0]); + + parms[1] = new BMXNetParameter("@Record", DbType.String); + parms[1].SourceVersion = DataRowVersion.Original; + parms[1].SourceColumn = dtSchema.ExtendedProperties["BMXKey"].ToString();; + Parameters.Add(parms[1]); + + int i = 1; + foreach (DataRow r in dtSchema.Rows) + { + //Make a parameter for the Key Field and all non-ReadOnly fields + if ( ((bool) r["IsReadOnly"] == false) || ( (bool) r["IsKey"] == true ) ) + { + i++; + parms[i] = new BMXNetParameter(r["ColumnName"].ToString(), DbType.String); + parms[i].SourceVersion = DataRowVersion.Current; + parms[i].SourceColumn = r["BaseColumnName"].ToString(); //FM FieldNumber + parms[i].IsKey = Convert.ToBoolean(r["IsKey"]); + Parameters.Add(parms[i]); + } + } + } + } +} \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnectInfo.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnectInfo.cs new file mode 100644 index 0000000..816b0b8 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnectInfo.cs @@ -0,0 +1,1197 @@ +using System; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.IO.IsolatedStorage; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters; +using System.Runtime.Serialization.Formatters.Soap; +using System.Windows.Forms; +using System.Security.Principal; +using System.Text; +using System.Security.Cryptography; +using System.Timers; +using System.Threading; + + +namespace IndianHealthService.BMXNet +{ + public class BMXNetEventArgs : EventArgs + { + public string BMXParam; + public string BMXEvent; + } + + /// + /// Contains methods and properties to support RPMS Login for .NET applications + /// + public class BMXNetConnectInfo : System.Windows.Forms.Control + { + + /// + /// Serializes RPMS server address and port + /// + [SerializableAttribute] + private class ServerData + { + public string m_sAddress = ""; + public int m_nPort = 0; + public string m_sNamespace = ""; + + public ServerData() + { + } + + public ServerData(string sAddress, int nPort) + { + this.m_nPort = nPort; + this.m_sAddress = sAddress; + this.m_sNamespace = ""; + } + public ServerData(string sAddress, int nPort, string sNamespace) + { + this.m_nPort = nPort; + this.m_sAddress = sAddress; + this.m_sNamespace = sNamespace; + } + } + + public BMXNetConnectInfo() + { + m_BMXNetLib = new BMXNetLib(); + + //Initialize BMXNetEvent timer + m_timerEvent = new System.Timers.Timer(); + m_timerEvent.Elapsed+=new ElapsedEventHandler(OnEventTimer); + m_timerEvent.Interval = 10000; + m_timerEvent.Enabled = false; + } + + #region BMXNetEvent + + private System.Timers.Timer m_timerEvent; + public delegate void BMXNetEventDelegate(Object obj, BMXNetEventArgs e); + public event BMXNetEventDelegate BMXNetEvent; + + /// + /// Enables and disables event polling for the RPMS connection + /// + public bool EventPollingEnabled + { + get + { + return m_timerEvent.Enabled; + } + set + { +// Debug.Write("ConnectInfo handle: " + this.Handle.ToString() + "\n"); + //System.IntPtr pHandle = this.Handle; + m_timerEvent.Enabled = value; + } + } + + /// + /// Sets and retrieves the interval in milliseconds for RPMS event polling + /// + public double EventPollingInterval + { + get + { + return m_timerEvent.Interval; + } + set + { + m_timerEvent.Interval = value; + } + } + + /// + /// Register interest in an RPMS event. + /// + /// + /// + public int SubscribeEvent(string EventName) + { + try + { + //System.IntPtr pHandle = this.Handle; + DataTable dt; + RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); + if (this.IsHandleCreated == false) + { + this.CreateHandle(); + } + dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT REGISTER^" + EventName, "dt"}); + +// dt = RPMSDataTable("BMX EVENT REGISTER^" + EventName, "dt"); + DataRow dr = dt.Rows[0]; + int nRet = (int) dr["ERRORID"]; + return nRet; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + return 99; + } + } + + /// + /// Unregister an RPMS event + /// + /// + /// + public int UnSubscribeEvent(string EventName) + { + try + { + DataTable dt; + RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); + if (this.IsHandleCreated == false) + { + this.CreateHandle(); + } + dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT UNREGISTER^" + EventName, "dt"}); + + DataRow dr = dt.Rows[0]; + int nRet = (int) dr["ERRORID"]; + return nRet; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + return 99; + } + } + + /// + /// Raise an RPMS event + /// + /// The name of the event to raise + /// Parameters associated with the event + /// True if the event should be raised back to the caller + /// + public int RaiseEvent(string EventName, string Param, bool RaiseBack) + { + string sBack = (RaiseBack == true)?"TRUE":"FALSE"; + try + { + DataTable dt; + RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); + if (this.IsHandleCreated == false) + { + this.CreateHandle(); + } + dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT RAISE^" + EventName + "^" + Param + "^" + sBack + "^", "dt"}); + + DataRow dr = dt.Rows[0]; + int nRet = (int) dr["ERRORID"]; + return nRet; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + return 99; + } + } + + /// + /// Sets and retrieves the number of times that the Event Timer will generage a BMXNet AutoFire event. + /// For example, if AutoFire == 3, then every 3rd time the Event Timer fires, it will generate an AutoFire event. + /// + public int AutoFire + { + get + { + return m_nAutoFireIncrements; + } + set + { + m_nAutoFireIncrements = value; + } + } + + //Retrieve events registered by this session + private int m_nAutoFireIncrements = 0; + private int m_nAutoFireCount = 0; + + private void OnEventTimer(object source, ElapsedEventArgs e) + { + try + { + this.bmxNetLib.BMXRWL.AcquireWriterLock(5); + try + { + this.m_timerEvent.Enabled = false; + + Object obj = this; + BMXNetEventArgs args = new BMXNetEventArgs(); + m_nAutoFireCount++; + if ((m_nAutoFireIncrements > 0)&&(m_nAutoFireCount >= m_nAutoFireIncrements)) + { + m_nAutoFireCount = 0; + args.BMXEvent = "BMXNet AutoFire"; + args.BMXParam = ""; + if (BMXNetEvent != null) + { + BMXNetEvent(obj, args); + } + this.m_timerEvent.Enabled = true; + return; + } + + if (m_BMXNetLib.Connected == false) + { + this.m_timerEvent.Enabled = true; + return; + } + + DataTable dtEvents = new DataTable("BMXNetEvents"); + + try + { + if (this.IsHandleCreated == false) + { + this.CreateHandle(); + } + RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); + dtEvents = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT POLL", "BMXNetEvents"}); + } + catch (Exception ex) + { + string sMsg = ex.Message; + this.m_timerEvent.Enabled = true; + return; + } + + try + { + if (dtEvents.Rows.Count == 0) + { + this.m_timerEvent.Enabled = true; + return; + } + } + catch(Exception ex) + { + Debug.Write("upper Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n"); + } + try + { + //If events exist, raise BMXNetEvent + foreach (DataRow dr in dtEvents.Rows) + { + args.BMXEvent = dr["EVENT"].ToString(); + args.BMXParam = dr["PARAM"].ToString(); + if (BMXNetEvent != null) + { + BMXNetEvent(obj, args); + } + } + this.m_timerEvent.Enabled = true; + return; + } + catch(Exception ex) + { + Debug.Write("lower Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n"); + } + } + catch(Exception ex) + { + Debug.Write("Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n"); + } + finally + { + this.bmxNetLib.BMXRWL.ReleaseWriterLock(); + this.m_timerEvent.Enabled = true; + } + } + catch + { + Debug.Write(" OnEventTimer failed to obtain lock.\n"); + } + } + + #endregion BMXNetEvent + + #region Fields + + private ServerData m_ServerData; + private string m_sServerAddress; + private int m_nServerPort; + private string m_sServerNamespace; + private string m_sDUZ2; + private int m_nDivisionCount = 0; + private string m_sUserName; + private string m_sDivision; + private string m_sAppcontext; + private BMXNetLib m_BMXNetLib; + private bool m_bAutoServer = false; + private bool m_bAutoLogin = false; + + #endregion Fields + + #region Properties + +// /// +// /// Set and retrieve the timeout in milliseconds for locking the transmit port. +// /// If the transmit port is unavailable an ApplicationException will be thrown. +// /// +// public int TransmitLockTimeout +// { +// get +// { +// return m_nTransmitLockTimeout; +// } +// set +// { +// m_nTransmitLockTimeout = value; +// } +// } + + /// + /// Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. + /// If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. + /// The default is 30 seconds. + /// + public int ReceiveTimeout + { + get { return m_BMXNetLib.ReceiveTimeout; } + set { m_BMXNetLib.ReceiveTimeout = value; } + } + + public string MServerNameSpace + { + get + { + return m_BMXNetLib.MServerNamespace; + } + set + { + m_BMXNetLib.MServerNamespace = value; + } + } + + public BMXNetLib bmxNetLib + { + get + { + return m_BMXNetLib; + } + } + + public string AppContext + { + get + { + return m_sAppcontext; + } + set + { + if (m_BMXNetLib.Connected == true) + { + try + { + try + { + m_BMXNetLib.AppContext = value; + m_sAppcontext = value; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + throw ex; + } + finally + { + } + } + catch (ApplicationException aex) + { + // The writer lock request timed out. + Debug.Write("BMXNetConnectInfo.AppContext lock request timed out.\n"); + throw aex; + } + }//end if + }//end set + } + + public bool Connected + { + get + { + return m_BMXNetLib.Connected; + } + } + + public string UserName + { + get + { + return this.m_sUserName; + } + } + + public string DivisionName + { + get + { + return this.m_sDivision; + } + } + + /// + /// Returns a string representation of DUZ + /// + public string DUZ + { + get + { + return this.bmxNetLib.DUZ; + } + } + + /// + /// Sets and Returns DUZ(2) + /// + public string DUZ2 + { + get + { + return m_sDUZ2; + } + set + { + try + { + //Set DUZ(2) in M partition + DataTable dt = this.RPMSDataTable("BMXSetFac^" + value, "SetDUZ2"); + Debug.Assert(dt.Rows.Count == 1); + DataRow dr = dt.Rows[0]; + string sDUZ2 = dr["FACILITY_IEN"].ToString(); + if (sDUZ2 != "0") + { + m_sDUZ2 = sDUZ2; + this.m_sDivision = dr["FACILITY_NAME"].ToString(); + } + } + catch (Exception ex) + { + Debug.Write("DUZ2.Set failed: " + ex.Message + "\n"); + } + } + } + + /// + /// Gets the address of the RPMS Server + /// + public string MServerAddress + { + get + { + return this.m_sServerAddress; + } + } + + /// + /// Gets the port on which the MServer is connected + /// + public int MServerPort + { + get + { + return this.m_nServerPort; + } + } + + public DataTable UserDivisions + { + get + { + DataTable dt = this.GetUserDivisions(); + return dt; + } + } + + #endregion Properties + + #region Methods + + public void CloseConnection() + { + //TODO: Make thread safe + this.m_bAutoServer = false; + this.m_bAutoLogin = false; + m_BMXNetLib.CloseConnection(); + } + + /// + /// For backwards compatibility. Internally calls LoadConnectInfo() + /// + public void Login() + { + LoadConnectInfo(); + } + + /// + /// Change the internet address and port of the RPMS server + /// Throws a BMXNetException if user cancels + /// + public void ChangeServerInfo() + { + //Get existing values from isolated storage + ServerData serverData = new ServerData(); + Stream stStorage = null; + try + { + IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); + string sFileName = "mserver0200.dat"; + stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Open, isStore); + IFormatter formatter = new SoapFormatter(); + serverData = (ServerData) formatter.Deserialize(stStorage); + stStorage.Close(); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + if (stStorage != null) + stStorage.Close(); + } + + try + { + DServerInfo dsi = new DServerInfo(); + dsi.InitializePage(serverData.m_sAddress,serverData.m_nPort, serverData.m_sNamespace); + if (dsi.ShowDialog() != DialogResult.OK) + { + throw new BMXNetException("User cancelled."); + } + serverData.m_sAddress = dsi.MServerAddress; + serverData.m_nPort = dsi.MServerPort; + serverData.m_sNamespace = dsi.MServerNamespace; + + this.m_sServerAddress = dsi.MServerAddress; + this.m_nServerPort = dsi.MServerPort; + this.m_sServerNamespace = dsi.MServerNamespace; + + //Save port and address to isolated storage + try + { + string sFileName = "mserver0200.dat"; + IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); + stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Create, isStore); + IFormatter formatter = new SoapFormatter(); + formatter.Serialize(stStorage, serverData); + stStorage.Close(); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + if (stStorage != null) + stStorage.Close(); + } + + } + catch (Exception ex) + { + Debug.Write(ex.Message); + if (stStorage != null) + stStorage.Close(); + if (ex.Message == "User cancelled.") + { + throw ex; + } + } + + } + + private void GetServerInfo(ref int nPort, ref string sAddress, ref string sNamespace) + { + //Get values from isolated storage + bool bLoaded = false; + Stream stStorage = null; + try + { + m_ServerData = new ServerData(); + IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); + string sFileName = "mserver0200.dat"; + stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Open, isStore); + IFormatter formatter = new SoapFormatter(); + m_ServerData = (ServerData) formatter.Deserialize(stStorage); + stStorage.Close(); + sAddress = m_ServerData.m_sAddress; + nPort = m_ServerData.m_nPort; + sNamespace = m_ServerData.m_sNamespace; + + bLoaded = true; + return; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + if (stStorage != null) + stStorage.Close(); + } + try + { + //If unable to deserialize, display dialog to collect values + if (bLoaded == false) + { + DServerInfo dsi = new DServerInfo(); + dsi.InitializePage("",10501,""); + if (dsi.ShowDialog() != DialogResult.OK) + { + throw new BMXNetException("Unable to get M Server information"); + } + m_ServerData.m_sAddress = dsi.MServerAddress; + m_ServerData.m_nPort = dsi.MServerPort; + m_ServerData.m_sNamespace = dsi.MServerNamespace; + } + + sAddress = m_ServerData.m_sAddress; + nPort = m_ServerData.m_nPort; + sNamespace = m_ServerData.m_sNamespace; + + //Save port and address to isolated storage + try + { + string sFileName = "mserver0200.dat"; + IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); + stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Create, isStore); + IFormatter formatter = new SoapFormatter(); + formatter.Serialize(stStorage, m_ServerData); + stStorage.Close(); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + if (stStorage != null) + stStorage.Close(); + } + + return; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + if (stStorage != null) + stStorage.Close(); + throw ex; + } + + } + + /// + /// Called to connect to an M server + /// Server address, port, Access and Verify codes will be + /// prompted for depending on whether these values are + /// cached. + /// + public void LoadConnectInfo() + { + m_bAutoServer = true; + m_bAutoLogin = true; + LoadConnectInfo("",0,"",""); + } + + /// + /// Called to connect to the M server specified by + /// server address and listener port. The default namespace on the server will be used. + /// Access and Verify codes will be prompted if + /// valid values for the current Windows Identity are + /// not cached on the server. + /// + /// The IP address or name of the MServer + /// The port on which the BMXNet Monitor is listening + public void LoadConnectInfo(string MServerAddress, int Port) + { + LoadConnectInfo(MServerAddress, Port, "", "", ""); + } + + /// + /// Called to connect to the M server specified by + /// server address, listener port and namespace. + /// Access and Verify codes will be prompted if + /// valid values for the current Windows Identity are + /// not cached on the server. + /// + /// The IP address or name of the MServer + /// The port on which the BMXNet Monitor is listening + /// The namespace in which the BMXNet application will run + public void LoadConnectInfo(string MServerAddress, int Port, string Namespace) + { + m_bAutoServer = false; + m_bAutoLogin = true; + LoadConnectInfo(MServerAddress, Port,"","", Namespace); + } + + /// + /// Called to connect to an M server + /// using specific Access and Verify codes. + /// Server address and port will be prompted if they + /// are not cached in local storage. + /// + /// The user's access code + /// The user's verify code + public void LoadConnectInfo(string AccessCode, string VerifyCode) + { + m_bAutoServer = true; + m_bAutoLogin = false; + LoadConnectInfo("", 0,AccessCode,VerifyCode); + } + + /// + /// Called to connect to a specific M server + /// using specific Access and Verify codes. + /// + /// The user's access code + /// The user's verify code + /// The IP address or name of the MServer + /// The port on which the BMXNet Monitor is listening + public void LoadConnectInfo(string MServerAddress, int Port, + string AccessCode, string VerifyCode) + { + LoadConnectInfo(MServerAddress, Port, AccessCode, VerifyCode, ""); + } + + /// + /// Called to connect to a specific namespace on the M server + /// using specific Access and Verify codes. + /// + /// The user's access code + /// The user's verify code + /// The IP address or name of the MServer + /// The port on which the BMXNet Monitor is listening + /// The namespace in which the BMXNet application will run + public void LoadConnectInfo(string MServerAddress, int Port, + string AccessCode, string VerifyCode, string Namespace) + { + //Throws exception if unable to connect to RPMS + + /* + * Get RPMS Server Address and Port from local storage. + * Prompt for them if they're not there. + * + * Throw exception if unable to get address/port + */ + + if (m_bAutoServer == true) + { + string sAddress = ""; + int nPort = 0; + string sNamespace = ""; + try + { + GetServerInfo(ref nPort, ref sAddress, ref sNamespace); + m_nServerPort = nPort; + m_sServerAddress = sAddress; + m_sServerNamespace = sNamespace; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + throw ex; + } + } + else + { + m_sServerAddress = MServerAddress; + m_nServerPort = Port; + m_sServerNamespace = Namespace; + } + + /* + * Connect to RPMS using current windows identity + * Execute BMXNetGetCodes(NTDomain/UserName) to get encrypted AV codes + * + */ + + m_BMXNetLib.CloseConnection(); + m_BMXNetLib.MServerPort = m_nServerPort; + m_BMXNetLib.MServerNamespace = m_sServerNamespace; + + string sLoginError = ""; + WindowsIdentity winIdentity = WindowsIdentity.GetCurrent(); + string sIdentName = winIdentity.Name; + string sIdentType = winIdentity.AuthenticationType; + bool bIdentIsAuth = winIdentity.IsAuthenticated; + bool bRet = false; + if (m_bAutoLogin == true) + { + try + { + //Attempt Auto-login using WindowsIdentity + + if (bIdentIsAuth == false) + { + throw new BMXNetException("Current Windows User is not authenticated"); + } + bRet = m_BMXNetLib.OpenConnection(m_sServerAddress, winIdentity); + + try + { + string sDuz = m_BMXNetLib.DUZ; + int nDuz = Convert.ToInt16(sDuz); + } + catch (Exception exCV) + { + Debug.Write("OpenConnection failed: " + exCV.Message); + //Debug.Assert(false); + throw new Exception(exCV.Message); + } + } + catch (Exception ex) + { + Debug.Write(ex.Message); + sLoginError = ex.Message; + } + } + + if (m_BMXNetLib.Connected == false) //BMXNET Login failed or m_bAutoLogin == false + { + try + { + //If autologin was attempted and + //error message anything other than + //"invalid AV code pair" + // or "User BMXNET,APPLICATION does not have access to option BMXRPC", + // or current windows user is not authenticated or is a guest + //then rethrow exception. + if ((m_bAutoLogin == true) + &&(BMXNetLib.FindSubString(sLoginError, "Not a valid ACCESS CODE/VERIFY CODE pair.") == -1) + &&(BMXNetLib.FindSubString(sLoginError, "User BMXNET,APPLICATION does not have access to option BMXRPC") == -1) + &&(BMXNetLib.FindSubString(sLoginError, "Not a valid Windows Identity map value.") == -1) + &&(BMXNetLib.FindSubString(sLoginError, "Current Windows User is not authenticated") == -1) + &&(BMXNetLib.FindSubString(sLoginError, "Windows Integrated Security Not Allowed on this port.") == -1) + ) + { + throw new BMXNetException(sLoginError); + } + + //Display dialog to collect user-input AV + + DLoginInfo dLog = new DLoginInfo(); + DialogResult bStop = DialogResult.OK; + m_BMXNetLib.CloseConnection(); + if ((AccessCode == "") && (VerifyCode == "")) + { + //nothing was passed in, so display a dialog to collect AV codes + do + { + dLog.InitializePage("",""); + bStop = dLog.ShowDialog(); + if (bStop == DialogResult.Cancel) + { + throw new BMXNetException("User cancelled login."); + } + try + { + string sTempAccess = dLog.AccessCode; + string sTempVerify = dLog.VerifyCode; + bRet = m_BMXNetLib.OpenConnection(m_sServerAddress, sTempAccess, sTempVerify); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + //MessageBox.Show(ex.Message, "RPMS Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + throw new Exception(ex.Message); ; + } + }while ((bStop == DialogResult.OK) && (m_BMXNetLib.Connected == false)); + } + else //caller passed in AV codes + { + try + { + //Connect using caller's AV + bRet = m_BMXNetLib.OpenConnection(m_sServerAddress, AccessCode, VerifyCode); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + //MessageBox.Show(ex.Message, "RPMS Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + throw new BMXNetException(ex.Message); + } + } + + //Map Windows Identity to logged-in RPMS user + if ((bIdentIsAuth == true) && (m_BMXNetLib.Connected == true)) + { + m_BMXNetLib.AppContext = "BMXRPC"; + string sRes = m_BMXNetLib.TransmitRPC("BMXNetSetUser", sIdentName); + Debug.Write("LoadConnectInfo BMXNetSetUser returned " + sRes + "\n"); + } + } + catch (Exception ex) + { + Debug.Write(ex.Message); + m_BMXNetLib.CloseConnection(); + throw ex; //this exception will be caught by the caller. + } + }//End if (m_BMXNetLib.Connected == false) + + try + { + Debug.Assert(m_BMXNetLib.Connected == true); + m_BMXNetLib.AppContext = "BMXRPC"; + string sRpc = "BMX USER"; + Debug.Assert(m_BMXNetLib.AppContext == "BMXRPC"); + + bool bCtxt = false; + int nCtxt = 0; + do + { + try + { + m_sUserName = m_BMXNetLib.TransmitRPC(sRpc, this.DUZ); + bCtxt = true; + Debug.Write("BMXNet::LoadConnectInfo succeeded.\n"); + } + catch (Exception ex) + { + Debug.Write("BMXNet::LoadConnectInfo retrying: " + ex.Message + "\n"); + m_BMXNetLib.AppContext = "BMXRPC"; + nCtxt++; + if (nCtxt > 4) + throw ex; + } + }while (bCtxt == false); + + + System.Data.DataTable rsDivisions; + rsDivisions = this.GetUserDivisions(); + m_nDivisionCount = rsDivisions.Rows.Count; + + //The MOST_RECENT_LOOKUP field contains DUZ(2) + foreach (System.Data.DataRow r in rsDivisions.Rows) + { + string sTemp = r["MOST_RECENT_LOOKUP"].ToString(); + if ((sTemp == "1") || (rsDivisions.Rows.Count == 1)) + { + this.m_sDivision = r["FACILITY_NAME"].ToString(); + this.m_sDUZ2 = r["FACILITY_IEN"].ToString(); + break; + } + } + } + catch(Exception bmxEx) + { + m_BMXNetLib.CloseConnection(); + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + } + return; + } + + private DataTable GetUserDivisions() + { + try + { + DataTable tb = this.RPMSDataTable("BMXGetFacRS^" + this.DUZ, "DivisionTable"); + return tb; + } + catch (Exception bmxEx) + { + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + + } + } + + public void ChangeDivision(System.Windows.Forms.Form frmCaller) + { + DSelectDivision dsd = new DSelectDivision(); + dsd.InitializePage(UserDivisions, DUZ2); + + if (dsd.ShowDialog(frmCaller) == DialogResult.Cancel) + return; + + if (dsd.DUZ2 != this.DUZ2) + { + DUZ2 = dsd.DUZ2; + } + } + + public string GetDSN(string sAppContext) + { + string sDsn = "Data source="; + if (sAppContext == "") + sAppContext = "BMXRPC"; + + if (m_BMXNetLib.Connected == false) + return sDsn.ToString(); + + sDsn += this.m_sServerAddress ; + sDsn += ";Location="; + sDsn += this.m_nServerPort.ToString(); + sDsn += ";Extended Properties="; + sDsn += sAppContext; + + return sDsn; + } + + + public bool Lock(string sVariable, string sIncrement, string sTimeOut) + { + bool bRet = false; + string sErrorMessage = ""; + + if (m_BMXNetLib.Connected == false) + { + return bRet; + } + try + { + bRet = this.bmxNetLib.Lock(sVariable, sIncrement, sTimeOut); + return bRet; + } + catch(Exception ex) + { + sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message; + throw ex; + } + } + + delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName); + delegate DataTable RPMSDataTableDelegate2(string CommandString, string TableName, DataSet dsDataSet); + + /// + /// Creates and names a DataTable using the command in CommandString + /// and the name in TableName. + /// + /// The SQL or RPC call + /// The name of the resulting table + /// + /// Returns the resulting DataTable. + /// + public DataTable RPMSDataTable(string CommandString, string TableName) + { + return this.RPMSDataTable(CommandString, TableName, null); + } + + /// + /// Creates and names a DataTable using the command in CommandString + /// and the name in TableName then adds it to DataSet. + /// + /// The SQL or RPC call + /// The name of the resulting table + /// The dataset in which to place the table + /// + /// Returns the resulting DataTable. + /// + public DataTable RPMSDataTable(string CommandString, string TableName, DataSet dsDataSet) + { + //Retrieves a recordset from RPMS + //Debug.Assert(this.InvokeRequired == false); + string sErrorMessage = ""; + DataTable dtResult = new DataTable(TableName); + + if (m_BMXNetLib.Connected == false) + return dtResult; + + try + { + BMXNetConnection rpmsConn = new BMXNetConnection(m_BMXNetLib); + BMXNetCommand cmd = (BMXNetCommand) rpmsConn.CreateCommand(); + BMXNetDataAdapter da = new BMXNetDataAdapter(); + + cmd.CommandText = CommandString; + da.SelectCommand = cmd; + if (dsDataSet == null) + { + da.Fill(dtResult); + } + else + { + da.Fill(dsDataSet, TableName); + dtResult = dsDataSet.Tables[TableName]; + } + Debug.Write(dtResult.TableName + " DataTable retrieved\n"); + return dtResult; + } + catch (Exception ex) + { + sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message; + throw ex; + } + } + + public int RPMSDataTableAsyncQue(string CommandString, string EventName) + { + try + { + string sCommand = "BMX ASYNC QUEUE^"; + //replace ^'s in CommandString with $c(30)'s + char[] cDelim = new char[1]; + cDelim[0] = (char) 30; + string sDelim = cDelim[0].ToString(); + CommandString = CommandString.Replace("^", sDelim); + sCommand = sCommand + CommandString + "^" + EventName; + + DataTable dt = new DataTable(); + RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); + if (this.IsHandleCreated == false) + { + this.CreateHandle(); + } + + dt = (DataTable) this.Invoke(rdtd, new object[] {sCommand, "Que"}); + + DataRow dr = dt.Rows[0]; + int nErrorID = Convert.ToInt32(dr["ERRORID"]); + int nParam = Convert.ToInt32(dr["PARAM"]); + + if (nErrorID == 0) + { + return 0; + } + else + { + return nParam; + } + } + catch (Exception ex) + { + Debug.Write("RPMSDataTableAsyncQue error: " + ex.Message + "\n"); + throw ex; + } + } + + public DataTable RPMSDataTableAsyncGet(string AsyncInfo, string TableName) + { + return RPMSDataTableAsyncGet(AsyncInfo, TableName, null); + } + + public DataTable RPMSDataTableAsyncGet(string AsyncInfo, string TableName, DataSet dsDataSet) + { + try + { + string sCommand = "BMX ASYNC GET^" + AsyncInfo; + + DataTable dt; + RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); + RPMSDataTableDelegate2 rdtd2 = new RPMSDataTableDelegate2(RPMSDataTable); + if (this.IsHandleCreated == false) + { + this.CreateHandle(); + } + + if (dsDataSet == null) + { + dt = (DataTable) this.Invoke(rdtd, new object[] {sCommand, TableName}); + } + else + { + dt = (DataTable) this.Invoke(rdtd2, new object[] {sCommand, TableName, dsDataSet}); + } + return dt; + } + catch (Exception ex) + { + Debug.Write("RPMSDataTableAsyncGet error: " + ex.Message + "\n"); + throw ex; + } + } + + #endregion Methods + + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnection.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnection.cs new file mode 100644 index 0000000..65b0743 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnection.cs @@ -0,0 +1,326 @@ +using System; +using System.Data; +using System.Diagnostics; +using System.Reflection; +using System.Security.Principal; + +namespace IndianHealthService.BMXNet +{ + public class BMXNetConnection : System.Data.Common.DbConnection, IDbConnection + { + private ConnectionState m_state; + private string m_sConnString; + private BMXNetLib m_rpx; + private RPMSDb m_RPMSDb; + private int m_nTimeout; + private string m_sDatabase; + + private string m_sAccess; + private string m_sVerify; + private int m_nPort; + private string m_sAddress; + private string m_sAppContext; + private bool m_bUseWinIdent; + + // default constructor. + public BMXNetConnection() + { + // Initialize the connection object into the closed state. + m_state = ConnectionState.Closed; + this.m_rpx = new BMXNetLib(); + } + + public BMXNetConnection(string sConnString) + { + // Initialize the connection object into a closed state. + m_state = ConnectionState.Closed; + this.ConnectionString = sConnString; + this.m_rpx = new BMXNetLib(); + } + + public BMXNetConnection(BMXNetLib bmxLib) + { + if (bmxLib.Connected == true) + { + m_state = ConnectionState.Open; + m_rpx = bmxLib; + m_RPMSDb = new RPMSDb(m_rpx); + + } + else + { + m_state = ConnectionState.Closed; + } + } + + /**** + * IMPLEMENT THE REQUIRED PROPERTIES. + ****/ + override public string ConnectionString + { + get + { + return m_sConnString; + } + set + { + m_nTimeout = 0; + try + { + // Parse values from connect string + m_sConnString = value; + string sSemi = ";"; + string sEq = "="; + string sU = "^"; + char[] cSemi = sSemi.ToCharArray(); + char[] cEq = sEq.ToCharArray(); + char[] cU = sU.ToCharArray(); + string [] saSplit = m_sConnString.Split(cSemi); + string [] saProp; + string [] saTemp; + string sPropName; + string sPropVal; + for (int j = 0; j= m_resultset.data.Length / m_resultset.metaData.Length) + return false; + else + return true; + } + + public DataTable GetSchemaTable() + { + DataTable dtSchema = new DataTable(); + + dtSchema.Columns.Add("ColumnName", typeof(System.String)); + dtSchema.Columns.Add("ColumnSize", typeof(Int32)); + dtSchema.Columns.Add("ColumnOrdinal", typeof(Int32)); + dtSchema.Columns.Add("NumericPrecision", typeof(Int16)); + dtSchema.Columns.Add("NumericScale", typeof(Int16)); + dtSchema.Columns.Add("DataType", typeof(System.Type)); + dtSchema.Columns.Add("AllowDBNull", typeof(bool)); + dtSchema.Columns.Add("IsReadOnly", typeof(bool)); + dtSchema.Columns.Add("IsUnique", typeof(bool)); + dtSchema.Columns.Add("IsRowVersion", typeof(bool)); + dtSchema.Columns.Add("IsKey", typeof(bool)); + dtSchema.Columns.Add("IsAutoIncrement", typeof(bool)); + dtSchema.Columns.Add("IsLong", typeof(bool)); + dtSchema.Columns.Add("BaseTableName", typeof(System.String)); + dtSchema.Columns.Add("BaseColumnName", typeof(System.String)); + + dtSchema.ExtendedProperties.Add("BMXTable", m_resultset.fmFileID); + dtSchema.ExtendedProperties.Add("BMXKey", m_resultset.fmKeyField); + + for (int i=0; i < m_resultset.metaData.GetLength(0); i++) + { + DataRow r = dtSchema.NewRow(); + r["BaseTableName"] = m_resultset.fmFileID; + r["BaseColumnName"] = m_resultset.metaData[i].fmFieldID; + r["ColumnName"] = m_resultset.metaData[i].name; + r["ColumnSize"] = m_resultset.metaData[i].maxSize; + r["ColumnOrdinal"] = i; + r["NumericPrecision"] = 0; + r["NumericScale"] = 0; + r["DataType"] = m_resultset.metaData[i].type; + r["AllowDBNull"] = false; + r["IsReadOnly"] = m_resultset.metaData[i].fmReadOnly; + r["IsUnique"] = false; + if (m_resultset.metaData[i].name == "BMXIEN") + r["IsUnique"] = true; + r["IsRowVersion"] = false; + r["IsKey"] = m_resultset.metaData[i].fmKeyField; + r["IsAutoIncrement"] = false; + r["IsLong"] = false; + + dtSchema.Rows.Add(r); + } + return dtSchema; + } + + /**** + * METHODS / PROPERTIES FROM IDataRecord. + ****/ + public int FieldCount + { + // Return the count of the number of columns, which in + // this case is the size of the column metadata + // array. + get { return m_resultset.metaData.Length; } + } + + public String GetName(int i) + { + return m_resultset.metaData[i].name; + } + + public String GetDataTypeName(int i) + { + /* + * Usually this would return the name of the type + * as used on the back end, for example 'smallint' or 'varchar'. + * BMXNet returns the simple name of the .NET Framework type. + */ + return m_resultset.metaData[i].type.Name; + } + + public Type GetFieldType(int i) + { + // Return the actual Type class for the data type. + return m_resultset.metaData[i].type; + } + + public Object GetValue(int i) + { + return m_resultset.data[m_nPos, i]; + } + + public int GetValues(object[] values) + { + int i = 0, j = 0; + for ( ; i < values.Length && j < m_resultset.metaData.Length; i++, j++) + { + values[i] = m_resultset.data[m_nPos, j]; + } + + return i; + } + + public int GetOrdinal(string name) + { + // Look for the ordinal of the column with the same name and return it. + for (int i = 0; i < m_resultset.metaData.Length; i++) + { + if (0 == _cultureAwareCompare(name, m_resultset.metaData[i].name)) + { + return i; + } + } + + // Throw an exception if the ordinal cannot be found. + throw new IndexOutOfRangeException("Could not find specified column in results"); + } + + public object this [ int i ] + { + get { return m_resultset.data[m_nPos, i]; } + } + + public object this [ String name ] + { + // Look up the ordinal and return + // the value at that position. + get { return this[GetOrdinal(name)]; } + } + + public bool GetBoolean(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (bool)m_resultset.data[m_nPos, i]; + } + + public byte GetByte(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (byte)m_resultset.data[m_nPos, i]; + } + + public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) + { + // BMXNet does not support this method. + throw new NotSupportedException("GetBytes not supported."); + } + + public char GetChar(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (char)m_resultset.data[m_nPos, i]; + } + + public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) + { + // BMXNet does not support this method. + throw new NotSupportedException("GetChars not supported."); + } + + public Guid GetGuid(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (Guid)m_resultset.data[m_nPos, i]; + } + + public Int16 GetInt16(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (Int16)m_resultset.data[m_nPos, i]; + } + + public Int32 GetInt32(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (Int32)m_resultset.data[m_nPos, i]; + } + + public Int64 GetInt64(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (Int64)m_resultset.data[m_nPos, i]; + } + + public float GetFloat(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (float)m_resultset.data[m_nPos, i]; + } + + public double GetDouble(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (double)m_resultset.data[m_nPos, i]; + } + + public String GetString(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (String)m_resultset.data[m_nPos, i]; + } + + public Decimal GetDecimal(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (Decimal)m_resultset.data[m_nPos, i]; + } + + public DateTime GetDateTime(int i) + { + /* + * Force the cast to return the type. InvalidCastException + * should be thrown if the data is not already of the correct type. + */ + return (DateTime)m_resultset.data[m_nPos, i]; + } + + public IDataReader GetData(int i) + { + /* + * BMXNet code does not support this method. Need, + * to implement this in order to expose nested tables and + * other hierarchical data. + */ + throw new NotSupportedException("GetData not supported."); + } + + public bool IsDBNull(int i) + { + return m_resultset.data[m_nPos, i] == DBNull.Value; + } + + /* + * Implementation specific methods. + */ + private int _cultureAwareCompare(string strA, string strB) + { + return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase); + } + + void IDisposable.Dispose() + { + this.Dispose(true); + System.GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposing) + { + try + { + this.Close(); + } + catch (Exception e) + { + throw new SystemException("An exception of type " + e.GetType() + + " was encountered while closing the BMXNetDataReader."); + } + } + } + + } +} \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetEkres.txt b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetEkres.txt new file mode 100644 index 0000000..77863f9 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetEkres.txt @@ -0,0 +1,20 @@ +wkEo-ZJt!dG)49K{nX1BS$vH<&:Myf*>Ae0jQW=;|#PsO`'%+rmb[gpqN,l6/hFC@DcUa ]z~R}"V\iIxu?872.(TYL5_3 +rKv`R;M/9BqAF%&tSs#Vh)dO1DZP> *fX'u[.4lY=-mg_ci802N7LTG<]!CWo:3?{+,5Q}(@jaExn$~p\IyHwzU"|k6Jeb +\pV(ZJk"WQmCn!Y,y@1d+~8s?[lNMxgHEt=uw|X:qSLjAI*}6zoF{T3#;ca)/h5%`P4$r]G'9e2if_>UDKb7H=CT8S! +NZW:1}K$byP;jk)7'`x90B|cq@iSsEnu,(l-hf.&Y_?J#R]+voQXU8mrV[!p4tg~OMez CAaGFD6H53%L/dT2<*>"{\wI= +vCiJ[D_0xR32c*4.P"G{r7}E8wUgyudF+6-:B=$(sY,LkbHa#'@Q +hvMX,'4Ty;[a8/{6l~F_V"}qLI\!@x(D7bRmUH]W15J%N0BYPkrs&9:$)Zj>u|zwQ=ieC-oGA.#?tfdcO3gp`S+En K2*< +jd!W5[];4'?ghBzIFN}fAK"#`p_TqtD*1E37XGVs@0nmSe+Y6Qyo-aUu%i8c=H2vJ\) R:MLb.9,wlO~P +2ThtjEM+!=xXb)7,ZV{*ci3"8@_l-HS69L>]\AUF/Q%:qD?1~m(yvO0e'<#o$p4dnIzKP|`NrkaGg.ufCRB[; sJYwW}5& +vB\5/zl-9y:Pj|=(R'7QJI *&CTX"p0]_3.idcuOefVU#omwNZ`$Fs?L+1Sk<,b)hM4A6[Y%aDrg@~KqEW8t>H};n!2xG{ +sFz0Bo@_HfnK>LR}qWXV+D6`Y28=4Cm~G/7-5A\b9!a#rP.l&M$hc3ijQk;),TvUd<[:I"u1'NZSOw]*gxtE{eJp|y (?% +M@,D}|LJyGO8`$*ZqH .j>c~hanG +xVa1']_GU#zm+:5b@06O3Ap8=*7ZFY!H-uEQk; .q)i&rhd +I]Jz7AG@QX."%3Lq>METUo{Pp_ |a6<0dYVSv8:b)~W9NK`(r'4fs&wim\kReC2hg=HOj$1B*/nxt,;c#y+![?lFuZ-5D} +Rr(Ge6F Hx>q$m&C%M~Tn,:"o'tX/*yP.{lZ!YkiVhuw_y|m};d)-7DZ"Fe/Y9 WidFN,1KsmwQ)GJM{I4:C%}#Ep(?HB/r;t.&U8o|l['Lg"2hRDyZ5`nbf]qjc0!zS-TkYO<_=76a\X@$Pe3+xVvu +yYgjf"5VdHc#uA,W1i+v'6|@pr{n;DJ!8(btPGaQM.LT3oe?NB/&9>Z`-}02*%x<7lsqz4OS ~E$\R]KI[:UwC_=h)kXmF +5:iar.{YU7mBZR@-K|2 "+~`M%8sq4JhPo<_X\Sg3WC;Tuxz,fvEQ1p9=w}FAI&j/keD0c?)LN6OHV]lGy'$*>nd[(tb!# diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetException.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetException.cs new file mode 100644 index 0000000..abd9b09 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetException.cs @@ -0,0 +1,33 @@ +using System; +using System.Runtime.Serialization; + +namespace IndianHealthService.BMXNet +{ + /// + /// Custom exception class for BMXNet + /// + [Serializable] + public class BMXNetException : System.ApplicationException + { + public BMXNetException() + { + + } + public BMXNetException(string message) : base(message) + { + + } + public BMXNetException(string message, Exception inner) : base(message, inner) + { + + } + // deserialization constructor + public BMXNetException(SerializationInfo info, + StreamingContext context): + base(info, context) + { + + } + + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetLibcs.copy b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetLibcs.copy new file mode 100644 index 0000000..b044ccb --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetLibcs.copy @@ -0,0 +1,852 @@ +using System; +using System.Diagnostics; +using System.Text; +using System.IO; +using System.Net.Sockets; +using System.Net; + + +namespace IndianHealthService.BMXNet +{ + /// + /// BMXNetLib implements low-level socket connectivity to RPMS databases. + /// The VA RPC Broker must be running on the RPMS server in order for + /// BMXNetLib to connect. + /// + public class BMXNetLib + { + public BMXNetLib() + { + m_sWKID = "XWB"; + m_sWINH = ""; + m_sPRCH = ""; + m_sWISH = ""; + m_cHDR = ADEBHDR(m_sWKID,m_sWINH,m_sPRCH,m_sWISH); + + } + + #region Piece Functions + + /// + /// Corresponds to M's $L(STRING,DELIMITER) + /// + /// + /// + /// + public static int PieceLength(string sInput, string sDelim) + { + char[] cDelim = sDelim.ToCharArray(); + string [] cSplit = sInput.Split(cDelim); + return cSplit.GetLength(0); + } + + /// + /// Corresponds to M's $$Piece function + /// + /// + /// + /// + /// + public static string Piece(string sInput, string sDelim, int nNumber) + { + char[] cDelim = sDelim.ToCharArray(); + string [] cSplit = sInput.Split(cDelim); + int nLength = cSplit.GetLength(0); + if ((nLength < nNumber)||(nNumber < 1)) + return ""; + return cSplit[nNumber-1]; + + } + +// public static string Piece(string[] sInput, string sDelim, int nNumber) +// { +// char[] cDelim = sDelim.ToCharArray(); +// int nLength = sInput.GetLength(0); +// if ((nLength < nNumber)||(nNumber < 1)) +// return ""; +// +// return sInput[nNumber-1]; +// +// } + + public static string Piece(string sInput, string sDelim, int nNumber, int nEnd) + { + try + { + if (nNumber < 0) + nNumber = 1; + + if (nEnd < nNumber) + return ""; + + if (nEnd == nNumber) + return Piece(sInput, sDelim, nNumber); + + char[] cDelim = sDelim.ToCharArray(); + string [] cSplit = sInput.Split(cDelim); + int nLength = cSplit.GetLength(0); + if ((nLength < nNumber)||(nNumber < 1)) + return ""; + + //nNumber = 1-based index of the starting element to return + //nLength = count of elements + //nEnd = 1-based index of last element to return + //nCount = number of elements past nNumber to return + + //convert nNumber to 0-based index: + nNumber--; + + //convert nEnd to 0-based index; + nEnd--; + + //Calculate nCount; + int nCount = nEnd - nNumber + 1; + + //Adjust nCount for number of elements + if (nCount + nNumber >= nLength) + { + nCount = nLength - nNumber; + } + + string sRet = string.Join(sDelim, cSplit, nNumber, nCount ); + return sRet; + } + catch (Exception bmxEx) + { + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + } + } + +// public static string Piece(string[] sInput, string sDelim, int nNumber, int nEnd) +// { +// if (nEnd < nNumber) +// return ""; +// +// +// if (nEnd == nNumber) +// return Piece(sInput, sDelim, nNumber); +// +// char[] cDelim = sDelim.ToCharArray(); +// int nLength = sInput.GetLength(0); +// +// if ((nLength < nNumber)||(nNumber < 1)) +// return ""; +// +// if (nEnd > nLength) +// nEnd = nLength; +// +// return string.Join(sDelim, sInput, nNumber - 1, nEnd - 1); +// } + + #endregion Piece Functions + + #region RPX Fields + + private string m_sWKID; + private string m_sWISH; + private string m_sPRCH; + private string m_sWINH; + private string m_cHDR; + private string m_cVerify; + private string m_cAccess; + private string m_cDUZ; + private string m_cAuthentication; + private string m_cAppContext; + private bool m_bConnected; + private int m_nMServerPort; + private string m_cServerAddress; + private string m_cDUZ2; + private string m_cLoginFacility; + + #endregion RPX Fields + + #region Encryption Keys + private string[] m_sKey = new string[] + { + @"wkEo-ZJt!dG)49K{nX1BS$vH<&:Myf*>Ae0jQW=;|#PsO`'%+rmb[gpqN,l6/hFC@DcUa ]z~R}""V\iIxu?872.(TYL5_3", + @"rKv`R;M/9BqAF%&tSs#Vh)dO1DZP> *fX'u[.4lY=-mg_ci802N7LTG<]!CWo:3?{+,5Q}(@jaExn$~p\IyHwzU""|k6Jeb", + @"\pV(ZJk""WQmCn!Y,y@1d+~8s?[lNMxgHEt=uw|X:qSLjAI*}6zoF{T3#;ca)/h5%`P4$r]G'9e2if_>UDKb7H=CT8S!", + @"NZW:1}K$byP;jk)7'`x90B|cq@iSsEnu,(l-hf.&Y_?J#R]+voQXU8mrV[!p4tg~OMez CAaGFD6H53%L/dT2<*>""{\wI=", + @"vCiJ[D_0xR32c*4.P""G{r7}E8wUgyudF+6-:B=$(sY,LkbHa#'@Q", + @"hvMX,'4Ty;[a8/{6l~F_V""}qLI\!@x(D7bRmUH]W15J%N0BYPkrs&9:$)Zj>u|zwQ=ieC-oGA.#?tfdcO3gp`S+En K2*<", + @"jd!W5[];4'?ghBzIFN}fAK""#`p_TqtD*1E37XGVs@0nmSe+Y6Qyo-aUu%i8c=H2vJ\) R:MLb.9,wlO~P", + @"2ThtjEM+!=xXb)7,ZV{*ci3""8@_l-HS69L>]\AUF/Q%:qD?1~m(yvO0e'<#o$p4dnIzKP|`NrkaGg.ufCRB[; sJYwW}5&", + @"vB\5/zl-9y:Pj|=(R'7QJI *&CTX""p0]_3.idcuOefVU#omwNZ`$Fs?L+1Sk<,b)hM4A6[Y%aDrg@~KqEW8t>H};n!2xG{", + @"sFz0Bo@_HfnK>LR}qWXV+D6`Y28=4Cm~G/7-5A\b9!a#rP.l&M$hc3ijQk;),TvUd<[:I""u1'NZSOw]*gxtE{eJp|y (?%", + @"M@,D}|LJyGO8`$*ZqH .j>c~hanG", + @"xVa1']_GU#zm+:5b@06O3Ap8=*7ZFY!H-uEQk; .q)i&rhd", + @"I]Jz7AG@QX.""%3Lq>METUo{Pp_ |a6<0dYVSv8:b)~W9NK`(r'4fs&wim\kReC2hg=HOj$1B*/nxt,;c#y+![?lFuZ-5D}", + @"Rr(Ge6F Hx>q$m&C%M~Tn,:""o'tX/*yP.{lZ!YkiVhuw_y|m};d)-7DZ""Fe/Y9 WidFN,1KsmwQ)GJM{I4:C%}#Ep(?HB/r;t.&U8o|l['Lg""2hRDyZ5`nbf]qjc0!zS-TkYO<_=76a\X@$Pe3+xVvu", + @"yYgjf""5VdHc#uA,W1i+v'6|@pr{n;DJ!8(btPGaQM.LT3oe?NB/&9>Z`-}02*%x<7lsqz4OS ~E$\R]KI[:UwC_=h)kXmF", + @"5:iar.{YU7mBZR@-K|2 ""+~`M%8sq4JhPo<_X\Sg3WC;Tuxz,fvEQ1p9=w}FAI&j/keD0c?)LN6OHV]lGy'$*>nd[(tb!#", + }; + #endregion Encryption Keys + + + #region RPX Functions + + /// + /// Given strInput = "13" builds "013" if nLength = 3. Default for nLength is 3. + /// + /// + /// + private string ADEBLDPadString(string strInput) + { + return ADEBLDPadString(strInput, 3); + } + + /// + /// Given strInput = "13" builds "013" if nLength = 3 Default for nLength is 3. + /// + /// + /// Default = 3 + /// + private string ADEBLDPadString(string strInput, int nLength /*=3*/) + { + return strInput.PadLeft(nLength, '0'); + } + + /// + /// Concatenates zero-padded length of sInput to sInput + /// Given "Hello" returns "004Hello" + /// If nSize = 5, returns "00004Hello" + /// Default for nSize is 3. + /// + /// + /// + /// + private string ADEBLDB(string sInput) + { + return ADEBLDB(sInput, 3); + } + + /// + /// Concatenates zero-padded length of sInput to sInput + /// Given "Hello" returns "004Hello" + /// If nSize = 5, returns "00004Hello" + /// Default for nSize is 3. + /// + /// + /// + /// + private string ADEBLDB(string sInput, int nSize /*=3*/) + { + int nLen = sInput.Length; + string sLen = this.ADEBLDPadString(nLen.ToString(), nSize); + return sLen + sInput; + } + + /// + /// Build protocol header + /// + /// + /// + /// + /// + /// + private string ADEBHDR(string sWKID, string sWINH, string sPRCH, string sWISH) + { + string strResult; + strResult = sWKID+";"+sWINH+";"+sPRCH+";"+sWISH+";"; + strResult = ADEBLDB(strResult); + return strResult; + } + + private string ADEBLDMsg(string cHDR, string cRPC, string cParam, string cMult) + { + //Builds RPC message + //Automatically splits parameters longer than 200 into subscripted array + string cMSG; + string sBuild = ""; + string sPiece = ""; + string sBig = ""; + int l; + int nLength; + + if (cParam == "") + { + cMSG = "0" + cRPC ; + } + else + { + l = PieceLength(cParam, "^"); + for (int j=1; j <= l; j++) + { + sPiece = Piece(cParam, "^", j); + if ((j == l) && (sPiece.Length > 200)) + { + //Split up long param into array pieces + sBig = sPiece; + sPiece = ".x"; + nLength = sPiece.Length + 1; + sPiece = ADEBLDPadString(nLength.ToString()) + "2" + sPiece; + sBuild = sBuild + sPiece; + int nSubscript = 1; + string sSubscript =""; + int nSubLen = 0; + string sSubLen =""; + int nBigLen = sBig.Length; + string sHunk =""; + int nHunkLen = 0; + string sHunkLen =""; + do + { + sHunk = sBig.Substring(0,200); + sBig = sBig.Substring(201, sBig.Length + 1); + nBigLen = sBig.Length; + sSubscript = nSubscript.ToString(); + nSubLen = sSubscript.Length; + sSubLen = nSubLen.ToString(); + sSubLen = ADEBLDPadString(sSubLen); + nHunkLen = sHunk.Length; + sHunkLen = nHunkLen.ToString(); + sHunkLen = ADEBLDPadString(sHunkLen); + cMult = cMult + sSubLen + sSubscript + sHunkLen + sHunk; + nSubscript++; + } while (nBigLen > 0); + } + else + { + nLength = sPiece.Length +1; + sPiece = ADEBLDPadString(nLength.ToString()) + "0" + sPiece; + sBuild = sBuild + sPiece; + } + } + nLength = sBuild.Length; + string sTotLen = ADEBLDPadString(nLength.ToString(),5); + if (cMult.Length > 0) + { + cMSG = "1"+ cRPC + "^" +sTotLen + sBuild; + } + else + { + cMSG = "0"+ cRPC + "^" +sTotLen + sBuild; + } + } + cMSG = ADEBLDB(cMSG, 5); + cMSG = cHDR + cMSG; + return cMSG; + } + + private string ADEEncryp(string sInput) + { + //Encrypt a string + string strResult; + string strPercent; + string strAssoc; + string strIdix; + int nPercent; + int nAssocix; + int nIdix; + Debug.Assert(sInput != ""); + System.Random rRand = new Random(DateTime.Now.Second); + + nPercent = rRand.Next(0,10000); + nPercent += 72439; + nAssocix = nPercent % 20; + nAssocix++; + Debug.Assert(nAssocix < 21); + strPercent = nPercent.ToString(); + strPercent = strPercent.Substring(1,2); + nIdix = Convert.ToInt32(strPercent); + nIdix = nIdix % 20; + nIdix++; + Debug.Assert(nIdix < 21); + + const int nEncryptBase = 101; + strAssoc = LoadKey(nEncryptBase + nAssocix); + Debug.Assert(strAssoc.Length == 94); + strIdix = LoadKey(nEncryptBase + nIdix); + Debug.Assert(strIdix.Length == 94); + string sEncrypted = ""; + + foreach (char c in sInput) + { + string d = c.ToString(); + int nFindChar = FindChar(strIdix, c); + if (nFindChar > -1) + { + d = strAssoc.Substring(nFindChar,1); + } + sEncrypted += d; + } + + strResult = (char) (nIdix + 31) + sEncrypted + (char) (nAssocix + 31); + + return strResult; + } + + private int FindChar(byte[] c, char y) + { + int n = 0; + int nRet = -1; + for (n=0; n < c.Length; n++) + { + if (y == (char) c[n]) + { + nRet = n; + break; + } + } + + return nRet; + } + + private int FindChar(string s, char y) + { + int n = 0; + int nRet = -1; + foreach (char c in s) + { + if (y == c) + { + nRet = n; + break; + } + n++; + } + return nRet; + } + + private string LoadKey(int nID) + { + nID -= 102; + Debug.Assert( nID < 20); + return m_sKey[nID]; + } + + // private string GetLocalAddress() + // { + // return ""; + // } + + public bool OpenConnection(string sServerAddress, string sAccess, string sVerify) + { + try + { + m_cServerAddress = sServerAddress; + m_cAccess = sAccess; + m_cVerify = sVerify; + + //Get the local host address and available port; + IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); + if (ipHostInfo.AddressList.Length < 1) + { + throw new BMXNetException("BMXNetLib.OpenConnection unable to find IP Address."); + } + + //Start the listener + IPAddress ipAddress = ipHostInfo.AddressList[0]; + IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 0); + TcpListener listener = new TcpListener(localEndPoint); + listener.Start(); + IPEndPoint ipEp = (IPEndPoint) listener.LocalEndpoint; + int nLocalPort = ipEp.Port; + string sLocalAddress = ipAddress.ToString(); + + //Connect with the server + TcpClient connector = new TcpClient(); + try + { + connector.Connect(m_cServerAddress, m_nMServerPort); + } + catch (SocketException exSocket) + { + string s = exSocket.Message + exSocket.StackTrace; + throw new BMXNetException(s); + } + + //Prepare & send the connect message + string cSend = "TCPconnect^" + sLocalAddress + "^" + nLocalPort.ToString() + "^"; + int nLen = cSend.Length; + string sLen = nLen.ToString(); + sLen = sLen.PadLeft(5, '0'); + cSend = "{XWB}" + sLen + cSend; + + NetworkStream ns = connector.GetStream(); + byte[] sendBytes = Encoding.ASCII.GetBytes(cSend); + ns.Write(sendBytes,0,sendBytes.Length); + + //Accept connection from server + DateTime dStartTime = DateTime.Now; + DateTime dEndTime; + bool bPending = false; + while (bPending == false) + { + if (listener.Pending() == true) + { + m_pCommSocket = listener.AcceptTcpClient(); + bPending = true; + this.m_bConnected = true; + break; + } + dEndTime = DateTime.Now; + TimeSpan ds = dEndTime - dStartTime; + if (ds.TotalSeconds > 10) //TODO: Parameterize this timeout value + { + throw new Exception("AcceptTcpClient failed."); + } + + } + + try + { + bool bSecurity = SendSecurityRequest(); + } + catch (Exception ex) + { + //Close the connection + SendString(m_pCommSocket, "#BYE#"); + m_pCommSocket.Close(); + m_bConnected = false; + m_cServerAddress = ""; + throw ex; + } + + m_bConnected = true; + +// if ( bSecurity != true) +// { +// //Close the connection +// SendString(m_pCommSocket, "#BYE#"); +// m_pCommSocket.Close(); +// m_bConnected = false; +// m_cServerAddress = ""; +// } +// else +// { +// m_bConnected = true; +// } + return m_bConnected; + } + catch (BMXNetException bmxEx) + { + throw bmxEx; + } + catch (Exception ex) + { + string s = ex.Message + ex.StackTrace; + throw new BMXNetException(s); + } + + } + + private void SendString(TcpClient tcpClient, string cSendString) + { + string sMult = ""; + SendString(tcpClient, cSendString, sMult); + } + + private void SendString(TcpClient tcpClient, string cSendString, string cMult) + { + int nLen = cSendString.Length; + string sLen = nLen.ToString(); + sLen = sLen.PadLeft(5, '0'); + cSendString = sLen + cSendString; + + nLen += 15; + sLen = nLen.ToString(); + sLen = sLen.PadLeft(5, '0'); + + cSendString = "{XWB}" + sLen + cSendString; + cSendString = cSendString + cMult; + + NetworkStream ns = tcpClient.GetStream(); + byte[] sendBytes = Encoding.ASCII.GetBytes(cSendString); + ns.Write(sendBytes,0,sendBytes.Length); + + return; + } + + private string ReceiveString(TcpClient tcpClient) + { + NetworkStream ns = tcpClient.GetStream(); + do + { + + }while (ns.DataAvailable == false); + + byte[] bReadBuffer = new byte[1024]; + string sReadBuffer = ""; + StringBuilder sbAll = new StringBuilder("", 1024); + int numberOfBytesRead = 0; + + // Incoming message may be larger than the buffer size. + + numberOfBytesRead = ns.Read(bReadBuffer, 0, 2); //first two bytes are 0 + bool bFinished = false; + int nFind = -1; + do + { + numberOfBytesRead = ns.Read(bReadBuffer, 0, bReadBuffer.Length); + nFind = FindChar(bReadBuffer, (char) 4); + if (nFind > -1) + bFinished = true; + + sReadBuffer = Encoding.ASCII.GetString(bReadBuffer, 0, numberOfBytesRead); + if (nFind > -1) + { + sbAll.Append(sReadBuffer, 0, numberOfBytesRead -1); + } + else + { + sbAll.Append(sReadBuffer); + } + } + while(bFinished == false); + return sbAll.ToString(); + + } + + private bool SendSecurityRequest() + { + string strReceive = ""; + string cAccess; + string cVerify; + + //Setup Signon Environment + string cMSG = this.ADEBLDB("0XUS SIGNON SETUP^00000", 5); + cMSG = m_cHDR + cMSG; + SendString(m_pCommSocket, cMSG); + strReceive = ReceiveString(m_pCommSocket); + + cAccess = m_cAccess.ToUpper(); + cVerify = m_cVerify.ToUpper(); + + //Build AV Call + string strAV = cAccess + ";" + cVerify; + strAV = ADEEncryp(strAV); + cMSG = ADEBLDMsg(m_cHDR, "XUS AV CODE", strAV,""); + SendString(m_pCommSocket, cMSG); + + strReceive = ReceiveString(m_pCommSocket); + + char[] cDelim = {(char) 13,(char) 10,(char) 0}; + m_cAuthentication = strReceive; + string sDelim = new string(cDelim); + int nPiece = 1; + m_cDUZ = Piece(m_cAuthentication, sDelim , nPiece); + if ((m_cDUZ == "0")||(m_cDUZ == "")) + { + m_cAccess = ""; + m_cVerify = ""; + string sReason = Piece(m_cAuthentication, sDelim, 7); + throw new Exception(sReason); + } + m_cAccess = cAccess; + m_cVerify = cVerify; + + //Set up context + if (m_cAppContext == null) + m_cAppContext = "XUS SIGNON"; + + SendString(m_pCommSocket, ADEBLDMsg(m_cHDR, "XWB CREATE CONTEXT", ADEEncryp(m_cAppContext), "")); + m_cAuthentication = ReceiveString(m_pCommSocket); + + return true; + } + + public void CloseConnection() + { + if (!m_bConnected) + { + return; + } + SendString(m_pCommSocket, "#BYE#"); + m_pCommSocket.Close(); + m_bConnected = false; + m_cServerAddress = ""; + m_cAuthentication = ""; + m_cDUZ2 = ""; + m_cAccess = ""; + m_cVerify = ""; + m_cDUZ = ""; + } + + public string TransmitRPC(string sRPC, string sParam) + { + if (m_bConnected == false) + { + //Raise Exception + throw new BMXNetException("BMXNetLib.TransmitRPC failed because BMXNetLib is not connected to RPMS."); + } + Debug.Assert(m_cDUZ != ""); + Debug.Assert(m_pCommSocket != null); + + string sMult = ""; + string sSend = ADEBLDMsg(m_cHDR, sRPC, sParam, sMult); + SendString(m_pCommSocket, sSend, sMult); + string strResult = ReceiveString(m_pCommSocket); + return strResult; + } + + public string GetLoginFacility() + { + try + { + if (m_bConnected == false) + { + throw new BMXNetException("BMXNetLib is not connected to RPMS"); + } + + if (m_cLoginFacility != "") + { + return m_cLoginFacility; + } + + Debug.Assert(m_pCommSocket != null); + Debug.Assert(m_cDUZ != ""); + SendString(m_pCommSocket, ADEBLDMsg(m_cHDR, "BMXGetFac", m_cDUZ, "")); + string sFac = ReceiveString(m_pCommSocket); + m_cLoginFacility = sFac; + return sFac; + } + catch (BMXNetException bmxEx) + { + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + } + catch (Exception ex) + { + throw ex; + } + } + + TcpClient m_pCommSocket; + + #endregion RPX Functions + + #region RPX Properties + + public string WKID + { + get + { + return m_sWKID; + } + set + { + m_sWKID = value; + } + } + + public string PRCH + { + get + { + return m_sPRCH; + } + set + { + m_sPRCH = value; + } + } + + public string WINH + { + get + { + return m_sWINH; + } + set + { + m_sWINH = value; + } + } + + public string WISH + { + get + { + return m_sWISH; + } + set + { + m_sWISH = value; + } + } + + public string AppContext + { + get + { + return m_cAppContext; + } + set + { + m_cAppContext = value; + //TODO: send the changed context to RPMS + } + } + + public bool Connected + { + get + { + return m_bConnected; + } + } + + public string DUZ + { + get + { + return m_cDUZ; + } + } + +// public string Error +// { +// get +// { +// return ""; +// } +// } + + public string DUZ2 + { + get + { + return m_cDUZ2; + } + set + { + m_cDUZ2 = value; + //TODO: send the changed context to RPMS + } + } + + public string MServerAddress + { + get + { + return m_cServerAddress; + } + } + + public int MServerPort + { + get + { + return m_nMServerPort; + } + set + { + m_nMServerPort = value; + } + } + + #endregion RPX Properties + + + + + + + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameter.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameter.cs new file mode 100644 index 0000000..5a34e03 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameter.cs @@ -0,0 +1,149 @@ +using System; +using System.Data; + +namespace IndianHealthService.BMXNet +{ + public class BMXNetParameter : IDataParameter + { + DbType m_dbType = DbType.Object; + ParameterDirection m_direction = ParameterDirection.Input; + bool m_fNullable = false; + bool m_fIsKey = false; + string m_sParamName; + string m_sSourceColumn; + DataRowVersion m_sourceVersion = DataRowVersion.Current; + object m_value; + + public BMXNetParameter() + { + } + + public BMXNetParameter(string parameterName, DbType type) + { + m_sParamName = parameterName; + m_dbType = type; + } + + public BMXNetParameter(string parameterName, object value) + { + m_sParamName = parameterName; + this.Value = value; + // Setting the value also infers the type. + } + + public BMXNetParameter( string parameterName, DbType dbType, string sourceColumn ) + { + m_sParamName = parameterName; + m_dbType = dbType; + m_sSourceColumn = sourceColumn; + } + + public DbType DbType + { + get { return m_dbType; } + set { m_dbType = value; } + } + + public ParameterDirection Direction + { + get { return m_direction; } + set { m_direction = value; } + } + + public Boolean IsKey + { + get { return m_fIsKey; } + set {m_fIsKey = value; } + } + + public Boolean IsNullable + { + get { return m_fNullable; } + } + + public String ParameterName + { + get { return m_sParamName; } + set { m_sParamName = value; } + } + + public String SourceColumn + { + get { return m_sSourceColumn; } + set { m_sSourceColumn = value; } + } + + public DataRowVersion SourceVersion + { + get { return m_sourceVersion; } + set { m_sourceVersion = value; } + } + + public object Value + { + get + { + return m_value; + } + set + { + m_value = value; + m_dbType = _inferType(value); + } + } + + private DbType _inferType(Object value) + { + switch (Type.GetTypeCode(value.GetType())) + { + case TypeCode.Empty: + throw new SystemException("Invalid data type"); + + case TypeCode.Object: + return DbType.Object; + + case TypeCode.DBNull: + case TypeCode.Char: + case TypeCode.SByte: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + // Throw a SystemException for unsupported data types. + throw new SystemException("Invalid data type"); + + case TypeCode.Boolean: + return DbType.Boolean; + + case TypeCode.Byte: + return DbType.Byte; + + case TypeCode.Int16: + return DbType.Int16; + + case TypeCode.Int32: + return DbType.Int32; + + case TypeCode.Int64: + return DbType.Int64; + + case TypeCode.Single: + return DbType.Single; + + case TypeCode.Double: + return DbType.Double; + + case TypeCode.Decimal: + return DbType.Decimal; + + case TypeCode.DateTime: + return DbType.DateTime; + + case TypeCode.String: + return DbType.String; + + default: + throw new SystemException("Value is of unknown data type"); + } + } + } +} \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameterCollection.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameterCollection.cs new file mode 100644 index 0000000..06fcc61 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameterCollection.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +using System.Collections; +using System.Globalization; + +namespace IndianHealthService.BMXNet +{ + /* + * Because IDataParameterCollection is primarily an IList, + * the sample can use an existing class for most of the implementation. + */ + public class BMXNetParameterCollection : ArrayList, IDataParameterCollection + { + public object this[string index] + { + get + { + return this[IndexOf(index)]; + } + set + { + this[IndexOf(index)] = value; + } + } + + public bool Contains(string parameterName) + { + return(-1 != IndexOf(parameterName)); + } + + public int IndexOf(string parameterName) + { + int index = 0; + foreach(BMXNetParameter item in this) + { + if (0 == _cultureAwareCompare(item.ParameterName, parameterName)) + { + return index; + } + index++; + } + return -1; + } + + public void RemoveAt(string parameterName) + { + RemoveAt(IndexOf(parameterName)); + } + + public override int Add(object value) + { + return Add((BMXNetParameter)value); + } + + public int Add(BMXNetParameter value) + { + if (((BMXNetParameter)value).ParameterName != null) + { + return base.Add(value); + } + else + throw new ArgumentException("parameter must be named"); + } + + public int Add(string parameterName, DbType type) + { + return Add(new BMXNetParameter(parameterName, type)); + } + + public int Add(string parameterName, object value) + { + return Add(new BMXNetParameter(parameterName, value)); + } + + public int Add(string parameterName, DbType dbType, string sourceColumn) + { + return Add(new BMXNetParameter(parameterName, dbType, sourceColumn)); + } + + private int _cultureAwareCompare(string strA, string strB) + { + return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase); + } + } +} \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/BMXNetTransaction.cs b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetTransaction.cs new file mode 100644 index 0000000..0a8fc44 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/BMXNetTransaction.cs @@ -0,0 +1,64 @@ +using System; +using System.Data; + +namespace IndianHealthService.BMXNet +{ + public class BMXNetTransaction : IDbTransaction + { + public IsolationLevel IsolationLevel + { + /* + * Should return the current transaction isolation + * level. For the BMXNet, assume the default + * which is ReadCommitted. + */ + get { return IsolationLevel.ReadCommitted; } + } + + public void Commit() + { + /* + * Implement Commit here. Although the BMXNet does + * not provide an implementation, it should never be + * a no-op because data corruption could result. + */ + } + + public void Rollback() + { + /* + * Implement Rollback here. Although the BMXNet does + * not provide an implementation, it should never be + * a no-op because data corruption could result. + */ + } + + public IDbConnection Connection + { + /* + * Return the connection for the current transaction. + */ + + get { return this.Connection; } + } + + public void Dispose() + { + this.Dispose(true); + System.GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposing) + { + if (null != this.Connection) + { + // implicitly rollback if transaction still valid + this.Rollback(); + } + } + } + + } +} \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/DLoginInfo.cs b/cs/bmx_0200scr/BMX2/BMXNet/DLoginInfo.cs new file mode 100644 index 0000000..4bf3d17 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/DLoginInfo.cs @@ -0,0 +1,269 @@ +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; + +namespace IndianHealthService.BMXNet +{ + /// + /// Summary description for DLoginInfo. + /// + public class DLoginInfo : System.Windows.Forms.Form + { + private System.Windows.Forms.Panel pnlPageBottom; + private System.Windows.Forms.Button cmdCancel; + private System.Windows.Forms.Button cmdOK; + private System.Windows.Forms.Panel pnlDescription; + private System.Windows.Forms.GroupBox grpDescriptionResourceGroup; + private System.Windows.Forms.Label lblDescriptionResourceGroup; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtVerify; + private System.Windows.Forms.TextBox txtAccess; + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public DLoginInfo() + { + InitializeComponent(); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pnlPageBottom = new System.Windows.Forms.Panel(); + this.cmdCancel = new System.Windows.Forms.Button(); + this.cmdOK = new System.Windows.Forms.Button(); + this.pnlDescription = new System.Windows.Forms.Panel(); + this.grpDescriptionResourceGroup = new System.Windows.Forms.GroupBox(); + this.lblDescriptionResourceGroup = new System.Windows.Forms.Label(); + this.txtVerify = new System.Windows.Forms.TextBox(); + this.txtAccess = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.pnlPageBottom.SuspendLayout(); + this.pnlDescription.SuspendLayout(); + this.grpDescriptionResourceGroup.SuspendLayout(); + this.SuspendLayout(); + // + // pnlPageBottom + // + this.pnlPageBottom.Controls.Add(this.cmdCancel); + this.pnlPageBottom.Controls.Add(this.cmdOK); + this.pnlPageBottom.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlPageBottom.Location = new System.Drawing.Point(0, 174); + this.pnlPageBottom.Name = "pnlPageBottom"; + this.pnlPageBottom.Size = new System.Drawing.Size(448, 40); + this.pnlPageBottom.TabIndex = 6; + // + // cmdCancel + // + this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cmdCancel.Location = new System.Drawing.Point(376, 8); + this.cmdCancel.Name = "cmdCancel"; + this.cmdCancel.Size = new System.Drawing.Size(56, 24); + this.cmdCancel.TabIndex = 4; + this.cmdCancel.Text = "Cancel"; + // + // cmdOK + // + this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK; + this.cmdOK.Location = new System.Drawing.Point(296, 8); + this.cmdOK.Name = "cmdOK"; + this.cmdOK.Size = new System.Drawing.Size(64, 24); + this.cmdOK.TabIndex = 3; + this.cmdOK.Text = "OK"; + this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click); + // + // pnlDescription + // + this.pnlDescription.Controls.Add(this.grpDescriptionResourceGroup); + this.pnlDescription.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlDescription.Location = new System.Drawing.Point(0, 102); + this.pnlDescription.Name = "pnlDescription"; + this.pnlDescription.Size = new System.Drawing.Size(448, 72); + this.pnlDescription.TabIndex = 7; + // + // grpDescriptionResourceGroup + // + this.grpDescriptionResourceGroup.Controls.Add(this.lblDescriptionResourceGroup); + this.grpDescriptionResourceGroup.Dock = System.Windows.Forms.DockStyle.Fill; + this.grpDescriptionResourceGroup.Location = new System.Drawing.Point(0, 0); + this.grpDescriptionResourceGroup.Name = "grpDescriptionResourceGroup"; + this.grpDescriptionResourceGroup.Size = new System.Drawing.Size(448, 72); + this.grpDescriptionResourceGroup.TabIndex = 1; + this.grpDescriptionResourceGroup.TabStop = false; + this.grpDescriptionResourceGroup.Text = "Description"; + // + // lblDescriptionResourceGroup + // + this.lblDescriptionResourceGroup.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblDescriptionResourceGroup.Location = new System.Drawing.Point(3, 16); + this.lblDescriptionResourceGroup.Name = "lblDescriptionResourceGroup"; + this.lblDescriptionResourceGroup.Size = new System.Drawing.Size(442, 53); + this.lblDescriptionResourceGroup.TabIndex = 0; + this.lblDescriptionResourceGroup.Text = "Use this panel to enter the Access and Verify codes that you use to log in to the" + + " RPMS server. "; + // + // txtVerify + // + this.txtVerify.Location = new System.Drawing.Point(160, 56); + this.txtVerify.Name = "txtVerify"; + this.txtVerify.PasswordChar = '*'; + this.txtVerify.Size = new System.Drawing.Size(160, 20); + this.txtVerify.TabIndex = 2; + this.txtVerify.Text = ""; + // + // txtAccess + // + this.txtAccess.Location = new System.Drawing.Point(160, 24); + this.txtAccess.Name = "txtAccess"; + this.txtAccess.PasswordChar = '*'; + this.txtAccess.Size = new System.Drawing.Size(160, 20); + this.txtAccess.TabIndex = 1; + this.txtAccess.Text = ""; + // + // label2 + // + this.label2.Location = new System.Drawing.Point(24, 56); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(128, 16); + this.label2.TabIndex = 12; + this.label2.Text = "RPMS Verify Code:"; + // + // label1 + // + this.label1.Location = new System.Drawing.Point(24, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(128, 16); + this.label1.TabIndex = 11; + this.label1.Text = "RPMS Access Code:"; + // + // DLoginInfo + // + this.AcceptButton = this.cmdOK; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(448, 214); + this.Controls.Add(this.txtVerify); + this.Controls.Add(this.txtAccess); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.pnlDescription); + this.Controls.Add(this.pnlPageBottom); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "DLoginInfo"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "RPMS Login"; + this.Load += new System.EventHandler(this.DLoginInfo_Load); + this.Activated += new System.EventHandler(this.DLoginInfo_Activated); + this.pnlPageBottom.ResumeLayout(false); + this.pnlDescription.ResumeLayout(false); + this.grpDescriptionResourceGroup.ResumeLayout(false); + this.ResumeLayout(false); + + } + #endregion + + #region Fields + string m_sAccess; + string m_sVerify; + #endregion Fields + + #region Methods + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(components != null) + { + components.Dispose(); + } + } + base.Dispose( disposing ); + } + + public void InitializePage(string sAccess, string sVerify) + { + m_sAccess = sAccess; + m_sVerify = sVerify; + UpdateDialogData(true); + } + + /// + /// If b is true, moves member vars into control data + /// otherwise, moves control data into member vars + /// + /// + private void UpdateDialogData(bool b) + { + if (b == true) //move member vars into controls + { + txtAccess.Text = m_sAccess; + txtVerify.Text = m_sVerify; + + } + else //move control data into member vars + { + m_sVerify = txtVerify.Text; + m_sAccess = txtAccess.Text; + } + } + + private void cmdOK_Click(object sender, System.EventArgs e) + { + this.UpdateDialogData(false); + return; + } + + #endregion Methods + + private void DLoginInfo_Activated(object sender, System.EventArgs e) + { + txtAccess.Focus(); + } + + private void DLoginInfo_Load(object sender, System.EventArgs e) + { + this.Activate(); + } + + + #region Properties + + /// + /// Gets the access code entered by the user. + /// + public string AccessCode + { + get + { + return m_sAccess; + } + } + + /// + /// Gets the verify code entered by the user. + /// + public string VerifyCode + { + get + { + return m_sVerify; + } + } + #endregion Properties + + + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/DLoginInfo.resx b/cs/bmx_0200scr/BMX2/BMXNet/DLoginInfo.resx new file mode 100644 index 0000000..faa4503 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/DLoginInfo.resx @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + True + + + Private + + + 8, 8 + + + False + + + Private + + + False + + + Private + + + Private + + + False + + + Private + + + Private + + + False + + + True + + + Private + + + 8, 8 + + + True + + + Private + + + Private + + + 8, 8 + + + True + + + False + + + True + + + Private + + + False + + + Private + + + Private + + + Private + + + False + + + Private + + + Private + + + False + + + Private + + + False + + + Private + + + Private + + + False + + + Private + + + Private + + + False + + + (Default) + + + False + + + False + + + 8, 8 + + + DLoginInfo + + + True + + + 80 + + + True + + + Private + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/DSelectDivision.cs b/cs/bmx_0200scr/BMX2/BMXNet/DSelectDivision.cs new file mode 100644 index 0000000..5aa162e --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/DSelectDivision.cs @@ -0,0 +1,223 @@ +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using System.Data; + +namespace IndianHealthService.BMXNet +{ + /// + /// Summary description for DSelectDivision. + /// + public partial class DSelectDivision : System.Windows.Forms.Form + { + private System.Windows.Forms.Panel pnlPageBottom; + private System.Windows.Forms.Button cmdCancel; + private System.Windows.Forms.Button cmdOK; + private System.Windows.Forms.Panel pnlDescription; + private System.Windows.Forms.GroupBox grpDescriptionResourceGroup; + private System.Windows.Forms.Label lblDescriptionResourceGroup; + private System.Windows.Forms.ListBox lstDivision; + private System.Windows.Forms.Label label1; + private System.ComponentModel.Container components = null; + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pnlPageBottom = new System.Windows.Forms.Panel(); + this.cmdCancel = new System.Windows.Forms.Button(); + this.cmdOK = new System.Windows.Forms.Button(); + this.pnlDescription = new System.Windows.Forms.Panel(); + this.grpDescriptionResourceGroup = new System.Windows.Forms.GroupBox(); + this.lblDescriptionResourceGroup = new System.Windows.Forms.Label(); + this.lstDivision = new System.Windows.Forms.ListBox(); + this.label1 = new System.Windows.Forms.Label(); + this.pnlPageBottom.SuspendLayout(); + this.pnlDescription.SuspendLayout(); + this.grpDescriptionResourceGroup.SuspendLayout(); + this.SuspendLayout(); + // + // pnlPageBottom + // + this.pnlPageBottom.Controls.Add(this.cmdCancel); + this.pnlPageBottom.Controls.Add(this.cmdOK); + this.pnlPageBottom.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlPageBottom.Location = new System.Drawing.Point(0, 262); + this.pnlPageBottom.Name = "pnlPageBottom"; + this.pnlPageBottom.Size = new System.Drawing.Size(456, 40); + this.pnlPageBottom.TabIndex = 7; + // + // cmdCancel + // + this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cmdCancel.Location = new System.Drawing.Point(376, 8); + this.cmdCancel.Name = "cmdCancel"; + this.cmdCancel.Size = new System.Drawing.Size(56, 24); + this.cmdCancel.TabIndex = 4; + this.cmdCancel.Text = "Cancel"; + // + // cmdOK + // + this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK; + this.cmdOK.Location = new System.Drawing.Point(296, 8); + this.cmdOK.Name = "cmdOK"; + this.cmdOK.Size = new System.Drawing.Size(64, 24); + this.cmdOK.TabIndex = 3; + this.cmdOK.Text = "OK"; + this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click); + // + // pnlDescription + // + this.pnlDescription.Controls.Add(this.grpDescriptionResourceGroup); + this.pnlDescription.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlDescription.Location = new System.Drawing.Point(0, 190); + this.pnlDescription.Name = "pnlDescription"; + this.pnlDescription.Size = new System.Drawing.Size(456, 72); + this.pnlDescription.TabIndex = 8; + // + // grpDescriptionResourceGroup + // + this.grpDescriptionResourceGroup.Controls.Add(this.lblDescriptionResourceGroup); + this.grpDescriptionResourceGroup.Dock = System.Windows.Forms.DockStyle.Fill; + this.grpDescriptionResourceGroup.Location = new System.Drawing.Point(0, 0); + this.grpDescriptionResourceGroup.Name = "grpDescriptionResourceGroup"; + this.grpDescriptionResourceGroup.Size = new System.Drawing.Size(456, 72); + this.grpDescriptionResourceGroup.TabIndex = 1; + this.grpDescriptionResourceGroup.TabStop = false; + this.grpDescriptionResourceGroup.Text = "Description"; + // + // lblDescriptionResourceGroup + // + this.lblDescriptionResourceGroup.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblDescriptionResourceGroup.Location = new System.Drawing.Point(3, 16); + this.lblDescriptionResourceGroup.Name = "lblDescriptionResourceGroup"; + this.lblDescriptionResourceGroup.Size = new System.Drawing.Size(450, 53); + this.lblDescriptionResourceGroup.TabIndex = 0; + this.lblDescriptionResourceGroup.Text = "Use this panel to select the Division."; + // + // lstDivision + // + this.lstDivision.Location = new System.Drawing.Point(40, 48); + this.lstDivision.Name = "lstDivision"; + this.lstDivision.Size = new System.Drawing.Size(384, 121); + this.lstDivision.TabIndex = 9; + // + // label1 + // + this.label1.Location = new System.Drawing.Point(40, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(240, 16); + this.label1.TabIndex = 10; + this.label1.Text = "Select Division:"; + // + // DSelectDivision + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(456, 302); + this.Controls.Add(this.label1); + this.Controls.Add(this.lstDivision); + this.Controls.Add(this.pnlDescription); + this.Controls.Add(this.pnlPageBottom); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "DSelectDivision"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Select Division"; + this.pnlPageBottom.ResumeLayout(false); + this.pnlDescription.ResumeLayout(false); + this.grpDescriptionResourceGroup.ResumeLayout(false); + this.ResumeLayout(false); + + } + #endregion + + #region Fields + + private DataTable m_dtDivisions; + private string m_sDUZ2; + private string m_sDivisionName; + + #endregion Fields + + #region Properties + + public string DivisionName + { + get + { + return this.m_sDivisionName; + } + } + + public string DUZ2 + { + get + { + return this.m_sDUZ2; + } + } + #endregion Properties + + #region Methods + + public void InitializePage(DataTable dtDivisions, string sDUZ2) + { + m_dtDivisions = dtDivisions; + m_sDUZ2 = sDUZ2; + UpdateDialogData(true); + } + + /// + /// If b is true, moves member vars into control data + /// otherwise, moves control data into member vars + /// + /// + private void UpdateDialogData(bool b) + { + if (b == true) //move member vars into controls + { + this.lstDivision.DataSource = m_dtDivisions; + lstDivision.DisplayMember = "FACILITY_NAME"; + lstDivision.ValueMember = "FACILITY_IEN"; + lstDivision.SelectedValue = m_sDUZ2; + } + else //move control data into member vars + { + this.m_sDUZ2 = lstDivision.SelectedValue.ToString(); + this.m_sDivisionName = lstDivision.Text; + } + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(components != null) + { + components.Dispose(); + } + } + base.Dispose( disposing ); + } + + public DSelectDivision() + { + InitializeComponent(); + } + + #endregion Methods + + private void cmdOK_Click(object sender, System.EventArgs e) + { + this.UpdateDialogData(false); + return; + } + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/DSelectDivision.resx b/cs/bmx_0200scr/BMX2/BMXNet/DSelectDivision.resx new file mode 100644 index 0000000..afac8ac --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/DSelectDivision.resx @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + True + + + Private + + + 8, 8 + + + False + + + Private + + + False + + + Private + + + Private + + + False + + + Private + + + Private + + + False + + + True + + + Private + + + 8, 8 + + + True + + + Private + + + Private + + + 8, 8 + + + True + + + False + + + True + + + Private + + + False + + + Private + + + Private + + + Private + + + False + + + Private + + + False + + + Private + + + Private + + + False + + + (Default) + + + False + + + False + + + 8, 8 + + + True + + + 80 + + + True + + + Private + + + DSelectDivision + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/DServerInfo.cs b/cs/bmx_0200scr/BMX2/BMXNet/DServerInfo.cs new file mode 100644 index 0000000..007c576 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/DServerInfo.cs @@ -0,0 +1,326 @@ +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using System.Diagnostics; + +namespace IndianHealthService.BMXNet +{ + /// + /// Prompts for RPMS Server address and port + /// Obtains current values, if any, from isolated storage + /// and uses them as defaults. + /// If OK, then writes values to isolated storage and returns + /// Address and Port as properties. + /// + /// + public partial class DServerInfo : System.Windows.Forms.Form + { + + private System.Windows.Forms.Panel pnlPageBottom; + private System.Windows.Forms.Button cmdCancel; + private System.Windows.Forms.Button cmdOK; + private System.Windows.Forms.Panel pnlDescription; + private System.Windows.Forms.GroupBox grpDescriptionResourceGroup; + private System.Windows.Forms.Label lblDescriptionResourceGroup; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtAddress; + private System.Windows.Forms.TextBox txtPort; + private TextBox txtNamespace; + private Label label3; + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public DServerInfo() + { + InitializeComponent(); + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(components != null) + { + components.Dispose(); + } + } + base.Dispose( disposing ); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DServerInfo)); + this.pnlPageBottom = new System.Windows.Forms.Panel(); + this.cmdCancel = new System.Windows.Forms.Button(); + this.cmdOK = new System.Windows.Forms.Button(); + this.pnlDescription = new System.Windows.Forms.Panel(); + this.grpDescriptionResourceGroup = new System.Windows.Forms.GroupBox(); + this.lblDescriptionResourceGroup = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtAddress = new System.Windows.Forms.TextBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtNamespace = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.pnlPageBottom.SuspendLayout(); + this.pnlDescription.SuspendLayout(); + this.grpDescriptionResourceGroup.SuspendLayout(); + this.SuspendLayout(); + // + // pnlPageBottom + // + this.pnlPageBottom.Controls.Add(this.cmdCancel); + this.pnlPageBottom.Controls.Add(this.cmdOK); + this.pnlPageBottom.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlPageBottom.Location = new System.Drawing.Point(0, 203); + this.pnlPageBottom.Name = "pnlPageBottom"; + this.pnlPageBottom.Size = new System.Drawing.Size(488, 40); + this.pnlPageBottom.TabIndex = 5; + // + // cmdCancel + // + this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cmdCancel.Location = new System.Drawing.Point(376, 8); + this.cmdCancel.Name = "cmdCancel"; + this.cmdCancel.Size = new System.Drawing.Size(56, 24); + this.cmdCancel.TabIndex = 2; + this.cmdCancel.Text = "Cancel"; + this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click); + // + // cmdOK + // + this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK; + this.cmdOK.Location = new System.Drawing.Point(296, 8); + this.cmdOK.Name = "cmdOK"; + this.cmdOK.Size = new System.Drawing.Size(64, 24); + this.cmdOK.TabIndex = 1; + this.cmdOK.Text = "OK"; + this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click); + // + // pnlDescription + // + this.pnlDescription.Controls.Add(this.grpDescriptionResourceGroup); + this.pnlDescription.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlDescription.Location = new System.Drawing.Point(0, 131); + this.pnlDescription.Name = "pnlDescription"; + this.pnlDescription.Size = new System.Drawing.Size(488, 72); + this.pnlDescription.TabIndex = 6; + // + // grpDescriptionResourceGroup + // + this.grpDescriptionResourceGroup.Controls.Add(this.lblDescriptionResourceGroup); + this.grpDescriptionResourceGroup.Dock = System.Windows.Forms.DockStyle.Fill; + this.grpDescriptionResourceGroup.Location = new System.Drawing.Point(0, 0); + this.grpDescriptionResourceGroup.Name = "grpDescriptionResourceGroup"; + this.grpDescriptionResourceGroup.Size = new System.Drawing.Size(488, 72); + this.grpDescriptionResourceGroup.TabIndex = 1; + this.grpDescriptionResourceGroup.TabStop = false; + this.grpDescriptionResourceGroup.Text = "Description"; + // + // lblDescriptionResourceGroup + // + this.lblDescriptionResourceGroup.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblDescriptionResourceGroup.Location = new System.Drawing.Point(3, 16); + this.lblDescriptionResourceGroup.Name = "lblDescriptionResourceGroup"; + this.lblDescriptionResourceGroup.Size = new System.Drawing.Size(482, 53); + this.lblDescriptionResourceGroup.TabIndex = 0; + this.lblDescriptionResourceGroup.Text = resources.GetString("lblDescriptionResourceGroup.Text"); + // + // label1 + // + this.label1.Location = new System.Drawing.Point(24, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(128, 16); + this.label1.TabIndex = 7; + this.label1.Text = "RPMS Server Address:"; + // + // label2 + // + this.label2.Location = new System.Drawing.Point(24, 56); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(128, 16); + this.label2.TabIndex = 8; + this.label2.Text = "Server Port:"; + // + // txtAddress + // + this.txtAddress.Location = new System.Drawing.Point(160, 24); + this.txtAddress.Name = "txtAddress"; + this.txtAddress.Size = new System.Drawing.Size(280, 20); + this.txtAddress.TabIndex = 9; + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(160, 56); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(72, 20); + this.txtPort.TabIndex = 10; + // + // txtNamespace + // + this.txtNamespace.Location = new System.Drawing.Point(160, 89); + this.txtNamespace.Name = "txtNamespace"; + this.txtNamespace.Size = new System.Drawing.Size(72, 20); + this.txtNamespace.TabIndex = 12; + // + // label3 + // + this.label3.Location = new System.Drawing.Point(24, 89); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(128, 16); + this.label3.TabIndex = 11; + this.label3.Text = "Server Namespace:"; + // + // DServerInfo + // + this.AcceptButton = this.cmdOK; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(488, 243); + this.Controls.Add(this.txtNamespace); + this.Controls.Add(this.label3); + this.Controls.Add(this.txtPort); + this.Controls.Add(this.txtAddress); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.pnlDescription); + this.Controls.Add(this.pnlPageBottom); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "DServerInfo"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "RPMS Server Address"; + this.Load += new System.EventHandler(this.DServerInfo_Load); + this.pnlPageBottom.ResumeLayout(false); + this.pnlDescription.ResumeLayout(false); + this.grpDescriptionResourceGroup.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + #endregion + + #region Fields + string m_sAddress; + int m_nPort; + string m_sNamespace; + #endregion Fields + + #region Methods + + public void InitializePage(string sAddress, int nPort, string sNamespace) + { + m_sAddress = sAddress; + m_nPort = nPort; + m_sNamespace = sNamespace; + UpdateDialogData(true); + } + + /// + /// If b is true, moves member vars into control data + /// otherwise, moves control data into member vars + /// + /// + private void UpdateDialogData(bool b) + { + if (b == true) //move member vars into controls + { + txtAddress.Text = m_sAddress; + txtPort.Text = m_nPort.ToString(); + txtNamespace.Text = m_sNamespace; + + } + else //move control data into member vars + { + try + { + m_nPort = Convert.ToInt16(txtPort.Text); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + m_nPort = 0; + } + m_sAddress = txtAddress.Text; + m_sNamespace = txtNamespace.Text; + + } + } + + private void cmdOK_Click(object sender, System.EventArgs e) + { + this.UpdateDialogData(false); + return; + } + + private void cmdCancel_Click(object sender, System.EventArgs e) + { + return; + } + + private void DServerInfo_Load(object sender, System.EventArgs e) + { + this.Activate(); + } + #endregion Methods + + #region Properties + + /// + /// Gets/sets the internet address of the RPMS Server + /// + public string MServerAddress + { + get + { + return m_sAddress; + } + set + { + m_sAddress = value; + } + } + + /// + /// Gets/sets the namespace of the RPMS Server + /// + public string MServerNamespace + { + get + { + return m_sNamespace; + } + set + { + m_sNamespace = value; + } + } + + /// + /// Gets/sets the TCP/IP Port of the RPMS Server + /// + public int MServerPort + { + get + { + return m_nPort; + } + set + { + m_nPort = value; + } + } + #endregion Properties + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNet/DServerInfo.resx b/cs/bmx_0200scr/BMX2/BMXNet/DServerInfo.resx new file mode 100644 index 0000000..9f96311 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/DServerInfo.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Use this panel to specify the internet address and port of the RPMS server. The RPMS Server Port refers to the IP Port to which the VA RPC Broker is assigned on the RPMS Server. You may optionally specify the namespace (UCI) in which the applicaiton will run. + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/IHSPrivateKey.pfx b/cs/bmx_0200scr/BMX2/BMXNet/IHSPrivateKey.pfx new file mode 100644 index 0000000..3b77e90 Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNet/IHSPrivateKey.pfx differ diff --git a/cs/bmx_0200scr/BMX2/BMXNet/RPMSDb.cs b/cs/bmx_0200scr/BMX2/BMXNet/RPMSDb.cs new file mode 100644 index 0000000..d07d7cb --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/RPMSDb.cs @@ -0,0 +1,504 @@ +using System; +using System.Data; +using System.Text; +using System.Diagnostics; + +namespace IndianHealthService.BMXNet +{ + /* + * This class executes a query or RPC against the connected + * RPMS database and formats the return value as a RPMSDbResultSet + */ + public class RPMSDb + { + private string m_sSelectCmd = "SELECT "; + private string m_sUpdateCmd = "UPDATE "; + private string m_sCmd = ""; + private BMXNetLib m_rpx; + + private string m_sQueryType = ""; + private RPMSDbResultSet[] m_aResultSets = null; + private int m_nCurrentSet = 0; + + public class RPMSDbResultSet + { + public struct MetaData + { + public string name; + public Type type; + public int maxSize; + + public string fmFieldID; + public bool fmReadOnly; + public bool fmKeyField; + } + + public int recordsAffected; + public MetaData[] metaData; + public object[,] data; + + public string fmKeyField; + public string fmFileID; + public string fmForeignKey = ""; + public int fmSeed = 0; + } + + //Constructor + public RPMSDb(BMXNetLib rpx) + { + m_rpx = rpx; + } + + public void Execute(string sCmd, out RPMSDbResultSet resultset) + { + /* + * SELECT, UPDATE and RPC operations. + */ + if (0 == String.Compare(sCmd, 0, m_sSelectCmd, 0, m_sSelectCmd.Length, true)) + { + m_sCmd = sCmd; + m_sQueryType = "SELECT"; + _executeSelect(out resultset); + } + else if (0 == String.Compare(sCmd, 0, m_sUpdateCmd, 0, m_sUpdateCmd.Length, true)) + { + m_sCmd = sCmd; + m_sQueryType = "UPDATE"; + _executeUpdate(out resultset); + } + else //RPC Call + { + m_sQueryType = "RPC"; + m_sCmd = sCmd; + _executeSelect(out resultset); + } + } + + private void _executeSelect(out RPMSDbResultSet resultset) + { + if (m_nCurrentSet == 0) + _resultsetCreate(); + + // Return the current resultset. + resultset = m_aResultSets[m_nCurrentSet]; + } + + private void _executeUpdate(out RPMSDbResultSet resultset) + { + string sRPC; + string sOldContext = m_rpx.AppContext; + + if (m_rpx.AppContext != "BMXRPC") + { + m_rpx.AppContext = "BMXRPC"; + } + + sRPC = "BMX UPDATE"; + int nStart = 7; + m_sCmd = m_sCmd.Substring(nStart); + string sResult = m_rpx.TransmitRPC( sRPC, m_sCmd); + + if (sOldContext != m_rpx.AppContext) + { + m_rpx.AppContext = sOldContext; + } + + resultset = new RPMSDbResultSet(); + resultset.recordsAffected = 1; //Make this the return value of the call + } + + private string CallRPX() + { + //Make rpx call + string sRPC; + string sParam; + string sOldContext = m_rpx.AppContext; + if (m_sQueryType == "SELECT") + { + if (m_rpx.AppContext != "BMXRPC") + { + m_rpx.AppContext = "BMXRPC"; + } + sRPC = "BMX SQL"; + sParam = m_sCmd; + } + else //it's an RPC (stored procedure) + { + sRPC = BMXNetLib.Piece(m_sCmd, "^", 1); + sParam = BMXNetLib.Piece(m_sCmd, "^", 2 , 99); + } + + string sResult = m_rpx.TransmitRPC( sRPC, sParam); + + if (sOldContext != m_rpx.AppContext) + { + m_rpx.AppContext = sOldContext; + } + + return sResult; + } + + private void ProcessHeader(string sHeader, int nSet, out int numCols) + { + //Modifies m_aResultSet[nSet] + string sFldDelim = "^"; + char[] cFldDelim = sFldDelim.ToCharArray(); + string sZero = "0"; + char[] cZero = sZero.ToCharArray(); + string sBar = "|"; + char[] cBar = sBar.ToCharArray(); + + int j; + if (sHeader.StartsWith("@@@meta@@@") == true) + { + //New style -- ColumnHeaderInfo in [1] + //Parse out data location or update logic here + //RecordInfo ^ Column1 info ^ column2 info ^ ... ^ column n info + string sType; + string sMaxSize; + string sFieldName; + string sReadOnly; + string sKeyField; + string sFileID; + string sSeed = ""; + int nMaxSize; + Type tType; + + int nTemp = 10; + sHeader = sHeader.Substring(10,(sHeader.Length - nTemp)); + string[] sRecordSetInfo = sHeader.Split(cFldDelim); + + numCols = sRecordSetInfo.GetLength(0)-1; + m_aResultSets[nSet].metaData = new RPMSDbResultSet.MetaData[numCols]; + + //First ^-Piece is recordset-level info: RecordIdentifier|File# + string[] sRecordInfo = sRecordSetInfo[0].Split(cBar); + m_aResultSets[nSet].fmFileID = sRecordInfo[1]; + if (sRecordInfo.GetLength(0) > 2) + { + sSeed = sRecordInfo[2]; + sSeed = (sSeed == "")?"0":sSeed; + try + { + m_aResultSets[nSet].fmSeed = Convert.ToInt32(sSeed); + } + catch (Exception ex) + { + Debug.Assert(false, "BMXNet.RMSPDb: 'Seed' value failed to convert to integer."); + Debug.Write(ex.Message + "\n"); + } + } + + if (sRecordInfo.GetLength(0) > 3) + { + m_aResultSets[nSet].fmForeignKey = sRecordInfo[4]; + + } + + m_aResultSets[nSet].fmKeyField = ""; + //2nd through nth ^-Pieces are Column info: Fileman File#FileMan Field#|DataType|Field Length|Column Name|IsReadOnly|IsKeyField + for (j=1; j < sRecordSetInfo.GetLength(0); j++) + { + string[] sColumnInfo = sRecordSetInfo[j].Split(cBar); + //Field 0 = FileID + //Field 1 = FieldID + //Field 2 = DataType + //Field 3 = Length + //Field 4 = ColumnName + //Field 5 = IsReadOnly + //Field 6 = IsKeyField + sFileID = sColumnInfo[0]; + string sFieldID = sColumnInfo[1]; + + + switch (sFieldID) + { + case ".001": + m_aResultSets[nSet].fmKeyField += "," + sColumnInfo[4]; + break; + case ".0001": + m_aResultSets[nSet].fmKeyField = sColumnInfo[4]; + break; + default: + break; + } + + sType = sColumnInfo[2]; + switch (sType) + { + case "D": + tType = typeof(DateTime); + break; + case "I": + tType = typeof(Int32); + break; + case "N": + tType = typeof(System.Double); + break; + default: + tType = typeof(String); + break; + } + sMaxSize = sColumnInfo[3]; + nMaxSize = Convert.ToInt16(sMaxSize); + sFieldName = sColumnInfo[4]; + + if (m_aResultSets[nSet].fmForeignKey == sFieldID) + { + m_aResultSets[nSet].fmForeignKey = sFieldName; + } + + sReadOnly = sColumnInfo[5]; + sKeyField = sColumnInfo[6]; + _resultsetFillColumn(nSet, j-1, sFieldName, tType, nMaxSize, sFieldID, sReadOnly, sKeyField); + } + } + else + { + //Old style column header info + + string sField; + string sType; + string sMaxSize; + string sFieldName; + int nMaxSize; + Type tType; + + string[] saHeader = sHeader.Split(cFldDelim); + numCols = saHeader.GetLength(0); + m_aResultSets[nSet].metaData = new RPMSDbResultSet.MetaData[numCols]; + for (j=0; j < numCols; j++) + { + sField = saHeader[j]; + sType = sField.Substring(0,1); + if (sType == "D") + { + tType = typeof(DateTime); + } + else if(sType == "I") + { + tType = typeof(Int32); + } + else if(sType == "N") + { + tType = typeof(System.Double); + } + else + { + tType = typeof(String); + } + sMaxSize = sField.Substring(1,5); + sMaxSize = sMaxSize.TrimStart(cZero); + nMaxSize = Convert.ToInt16(sMaxSize); + sFieldName = sField.Substring(6, sField.Length - 6); + _resultsetFillColumn(nSet, j, sFieldName, tType, nMaxSize); + } + } + } + + private void ProcessRecords(string[] sResultArray, int nRecords, int nSet, int numCols, int nStartIndex) + { + + string sFldDelim = "^"; + char[] cFldDelim = sFldDelim.ToCharArray(); + m_aResultSets[nSet].data = new object[nRecords-1, numCols]; + string[] saRecord; + int j; + for (j = nStartIndex; j < nRecords + nStartIndex -1; j++) + { + saRecord = sResultArray[j].Split(cFldDelim); + for (int k = 0; k< saRecord.GetLength(0); k++) + { + if (m_aResultSets[nSet].metaData[k].type == typeof(DateTime)) + { + if (saRecord[k] == "") + { + m_aResultSets[nSet].data[j-nStartIndex, k] = null; + } + else + { + try + { + m_aResultSets[nSet].data[j-nStartIndex, k] = Convert.ToDateTime(saRecord[k]); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + m_aResultSets[nSet].data[j-nStartIndex, k] = null; + } + } + } + else if (m_aResultSets[nSet].metaData[k].type == typeof(Int32)) + { + if (saRecord[k] == "") + { + m_aResultSets[nSet].data[j-nStartIndex, k] = null; + } + else + { + try + { + m_aResultSets[nSet].data[j-nStartIndex, k] = Convert.ToInt32(saRecord[k]); + } + catch (Exception ex) + { + Debug.Write(ex.Message); + m_aResultSets[nSet].data[j-nStartIndex, k] = null; + } + } + } + //TODO: Double datatype here + else //it's a string + { + m_aResultSets[nSet].data[j-nStartIndex, k] = saRecord[k]; + } + } + } + } + + + + private void _resultsetCreate() + { + m_nCurrentSet = 0; + char[] cRecDelim = new char[1]; + cRecDelim[0] = (char) 30; + + char cEof = (char) 31; + string sEof = cEof.ToString(); + + string sFldDelim = "^"; + char[] cFldDelim = sFldDelim.ToCharArray(); + string sZero = "0"; + char[] cZero = sZero.ToCharArray(); + string sBar = "|"; + char[] cBar = sBar.ToCharArray(); + + string sResult = this.CallRPX(); + + string[] sResultArray = sResult.Split(cRecDelim); + int nTotalRecords = sResultArray.GetLength(0); + + //Get set count and record count + int[] naRecords; //Count of records for each set + int[] naHeaderIndex; //Location (index) of header records in sResultArray + int nRecordSetCount; //Count of recordsets + + IndexRecords(sResultArray, out naRecords, out naHeaderIndex, out nRecordSetCount); + m_aResultSets = new RPMSDbResultSet[nRecordSetCount]; + + for (int nSet = 0; nSet < nRecordSetCount; nSet++) + { + int nHeaderIndex = naHeaderIndex[nSet]; + int nRecords = naRecords[nSet]; + int numCols = 0; + m_aResultSets[nSet] = new RPMSDbResultSet(); + m_aResultSets[nSet].recordsAffected = 0; + + //process header + string sHeader = sResultArray[nHeaderIndex]; + ProcessHeader(sHeader, nSet, out numCols); + + //process records + this.ProcessRecords(sResultArray, nRecords, nSet, numCols, nHeaderIndex+1); + + } + } + + private void IndexRecords(string[] sResultArray, + out int[] naRecordsOut, + out int[] naHeaderIndexOut, + out int nSets) + { + + int[] naHeaderIndex = new int[999]; + int nTotalRecords = sResultArray.GetLength(0); + nSets = 0; + int[] naRecords = new int[999]; + + if (sResultArray[0].StartsWith("@@@meta@@@") == false) + { + //this is an old-style header with only one record + nSets = 1; + naHeaderIndex[0] = 0; + naRecords[0]=nTotalRecords - 1; + } + else + { + + //Count the number of record sets and record the index of each header record + for (int k = 0; k < nTotalRecords; k++) + { + if (sResultArray[k].StartsWith("@@@meta@@@") == true) + { + naHeaderIndex[nSets] = k; + nSets++; + } + } + //Calculate record count for each set + for (int k = 0; k < nSets - 1; k++) + { + naRecords[k] = naHeaderIndex[k+1] - naHeaderIndex[k] ;// - 1; + } + naRecords[nSets-1] = nTotalRecords - naHeaderIndex[nSets - 1] - 1; + } + + naRecordsOut = new int[nSets]; + naHeaderIndexOut = new int[nSets]; + for (int k = 0; k < nSets; k++) + { + naRecordsOut[k] = naRecords[k]; + naHeaderIndexOut[k] = naHeaderIndex[k]; + } + } + + private void _resultsetFillColumn(int nSet, int nIdx, string name, Type type, int maxSize) + { + m_aResultSets[nSet].metaData[nIdx].name = name; + m_aResultSets[nSet].metaData[nIdx].type = type; + m_aResultSets[nSet].metaData[nIdx].maxSize = maxSize; + } + + private void _resultsetFillColumn(int nSet, int nIdx, string name, Type type, int maxSize, + string sFieldID, string sReadOnly, string sKeyField) + { + m_aResultSets[nSet].metaData[nIdx].name = name; + m_aResultSets[nSet].metaData[nIdx].type = type; + m_aResultSets[nSet].metaData[nIdx].maxSize = maxSize; + + m_aResultSets[nSet].metaData[nIdx].fmFieldID = sFieldID; + m_aResultSets[nSet].metaData[nIdx].fmReadOnly = (sReadOnly == "FALSE")?false:true; + m_aResultSets[nSet].metaData[nIdx].fmKeyField = (sKeyField == "TRUE")?true:false; + + } + + + /// + /// Returns the array of RMPSResultSets retrieved from RPMS + /// + public RPMSDbResultSet[] ResultSets + { + get + { + return m_aResultSets; + } + } + + /// + /// Sets and Returns the current recordset + /// + public int CurrentRecordSet + { + get + { + return m_nCurrentSet; + } + set + { + m_nCurrentSet = value; + } + } + + + } +} \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNet/bin/Release/BMXNet20.dll b/cs/bmx_0200scr/BMX2/BMXNet/bin/Release/BMXNet20.dll new file mode 100644 index 0000000..830c3e5 Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNet/bin/Release/BMXNet20.dll differ diff --git a/cs/bmx_0200scr/BMX2/BMXNet/bin/Release/bmxnet.xml b/cs/bmx_0200scr/BMX2/BMXNet/bin/Release/bmxnet.xml new file mode 100644 index 0000000..d4bf490 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/bin/Release/bmxnet.xml @@ -0,0 +1,418 @@ + + + + BMXNet20 + + + + + Summary description for DLoginInfo. + + + + + Required designer variable. + + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + + Clean up any resources being used. + + + + + If b is true, moves member vars into control data + otherwise, moves control data into member vars + + + + + + Gets the access code entered by the user. + + + + + Gets the verify code entered by the user. + + + + + Contains methods and properties to support RPMS Login for .NET applications + + + + + Register interest in an RPMS event. + + + + + + + Unregister an RPMS event + + + + + + + Raise an RPMS event + + The name of the event to raise + Parameters associated with the event + True if the event should be raised back to the caller + + + + + For backwards compatibility. Internally calls LoadConnectInfo() + + + + + Change the internet address and port of the RPMS server + Throws a BMXNetException if user cancels + + + + + Called to connect to an M server + Server address, port, Access and Verify codes will be + prompted for depending on whether these values are + cached. + + + + + Called to connect to the M server specified by + server address and listener port. The default namespace on the server will be used. + Access and Verify codes will be prompted if + valid values for the current Windows Identity are + not cached on the server. + + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + + + + Called to connect to the M server specified by + server address, listener port and namespace. + Access and Verify codes will be prompted if + valid values for the current Windows Identity are + not cached on the server. + + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + The namespace in which the BMXNet application will run + + + + Called to connect to an M server + using specific Access and Verify codes. + Server address and port will be prompted if they + are not cached in local storage. + + The user's access code + The user's verify code + + + + Called to connect to a specific M server + using specific Access and Verify codes. + + The user's access code + The user's verify code + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + + + + Called to connect to a specific namespace on the M server + using specific Access and Verify codes. + + The user's access code + The user's verify code + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + The namespace in which the BMXNet application will run + + + + Creates and names a DataTable using the command in CommandString + and the name in TableName. + + The SQL or RPC call + The name of the resulting table + + Returns the resulting DataTable. + + + + + Creates and names a DataTable using the command in CommandString + and the name in TableName then adds it to DataSet. + + The SQL or RPC call + The name of the resulting table + The dataset in which to place the table + + Returns the resulting DataTable. + + + + + Enables and disables event polling for the RPMS connection + + + + + Sets and retrieves the interval in milliseconds for RPMS event polling + + + + + Sets and retrieves the number of times that the Event Timer will generage a BMXNet AutoFire event. + For example, if AutoFire == 3, then every 3rd time the Event Timer fires, it will generate an AutoFire event. + + + + + Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. + If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. + The default is 30 seconds. + + + + + Returns a string representation of DUZ + + + + + Sets and Returns DUZ(2) + + + + + Gets the address of the RPMS Server + + + + + Gets the port on which the MServer is connected + + + + + Serializes RPMS server address and port + + + + + BMXNetLib implements low-level socket connectivity to RPMS databases. + The VA RPC Broker must be running on the RPMS server in order for + BMXNetLib to connect. + + + + + Corresponds to M's $L(STRING,DELIMITER) + + + + + + + + Corresponds to M's $$Piece function + + + + + + + + + Given strInput = "13" builds "013" if nLength = 3. Default for nLength is 3. + + + + + + + Given strInput = "13" builds "013" if nLength = 3 Default for nLength is 3. + + + Default = 3 + + + + + Concatenates zero-padded length of sInput to sInput + Given "Hello" returns "004Hello" + If nSize = 5, returns "00004Hello" + Default for nSize is 3. + + + + + + + Concatenates zero-padded length of sInput to sInput + Given "Hello" returns "004Hello" + If nSize = 5, returns "00004Hello" + Default for nSize is 3. + + + + + + + + Build protocol header + + + + + + + + + + Returns index of first instance of sSubString in sString. + If sSubString not found, returns -1. + + + + + + + + Lock a local or global M variable + Returns true if lock is obtained during TimeOut seconds + Use + to increment, - to decrement lock. + + + + + + + + + Returns a reference to the internal ReaderWriterLock member. + + + + + Sets and returns the timeout in milliseconds for locking the transmit port. + If the transmit port is unavailable an ApplicationException will be thrown. + + + + + Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. + If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. + The default is 30 seconds. + + + + + Gets/sets the Kernel Application context + Throws an exception if unable to set the context. + + + + + Returns the array of RMPSResultSets retrieved from RPMS + + + + + Sets and Returns the current recordset + + + + + Summary description for DSelectDivision. + + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + + If b is true, moves member vars into control data + otherwise, moves control data into member vars + + + + + + Clean up any resources being used. + + + + + Prompts for RPMS Server address and port + Obtains current values, if any, from isolated storage + and uses them as defaults. + If OK, then writes values to isolated storage and returns + Address and Port as properties. + + + + + + Required designer variable. + + + + + Clean up any resources being used. + + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + + If b is true, moves member vars into control data + otherwise, moves control data into member vars + + + + + + Gets/sets the internet address of the RPMS Server + + + + + Gets/sets the namespace of the RPMS Server + + + + + Gets/sets the TCP/IP Port of the RPMS Server + + + + + Custom exception class for BMXNet + + + + diff --git a/cs/bmx_0200scr/BMX2/BMXNet/bmxnet.xml b/cs/bmx_0200scr/BMX2/BMXNet/bmxnet.xml new file mode 100644 index 0000000..d4bf490 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNet/bmxnet.xml @@ -0,0 +1,418 @@ + + + + BMXNet20 + + + + + Summary description for DLoginInfo. + + + + + Required designer variable. + + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + + Clean up any resources being used. + + + + + If b is true, moves member vars into control data + otherwise, moves control data into member vars + + + + + + Gets the access code entered by the user. + + + + + Gets the verify code entered by the user. + + + + + Contains methods and properties to support RPMS Login for .NET applications + + + + + Register interest in an RPMS event. + + + + + + + Unregister an RPMS event + + + + + + + Raise an RPMS event + + The name of the event to raise + Parameters associated with the event + True if the event should be raised back to the caller + + + + + For backwards compatibility. Internally calls LoadConnectInfo() + + + + + Change the internet address and port of the RPMS server + Throws a BMXNetException if user cancels + + + + + Called to connect to an M server + Server address, port, Access and Verify codes will be + prompted for depending on whether these values are + cached. + + + + + Called to connect to the M server specified by + server address and listener port. The default namespace on the server will be used. + Access and Verify codes will be prompted if + valid values for the current Windows Identity are + not cached on the server. + + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + + + + Called to connect to the M server specified by + server address, listener port and namespace. + Access and Verify codes will be prompted if + valid values for the current Windows Identity are + not cached on the server. + + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + The namespace in which the BMXNet application will run + + + + Called to connect to an M server + using specific Access and Verify codes. + Server address and port will be prompted if they + are not cached in local storage. + + The user's access code + The user's verify code + + + + Called to connect to a specific M server + using specific Access and Verify codes. + + The user's access code + The user's verify code + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + + + + Called to connect to a specific namespace on the M server + using specific Access and Verify codes. + + The user's access code + The user's verify code + The IP address or name of the MServer + The port on which the BMXNet Monitor is listening + The namespace in which the BMXNet application will run + + + + Creates and names a DataTable using the command in CommandString + and the name in TableName. + + The SQL or RPC call + The name of the resulting table + + Returns the resulting DataTable. + + + + + Creates and names a DataTable using the command in CommandString + and the name in TableName then adds it to DataSet. + + The SQL or RPC call + The name of the resulting table + The dataset in which to place the table + + Returns the resulting DataTable. + + + + + Enables and disables event polling for the RPMS connection + + + + + Sets and retrieves the interval in milliseconds for RPMS event polling + + + + + Sets and retrieves the number of times that the Event Timer will generage a BMXNet AutoFire event. + For example, if AutoFire == 3, then every 3rd time the Event Timer fires, it will generate an AutoFire event. + + + + + Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. + If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. + The default is 30 seconds. + + + + + Returns a string representation of DUZ + + + + + Sets and Returns DUZ(2) + + + + + Gets the address of the RPMS Server + + + + + Gets the port on which the MServer is connected + + + + + Serializes RPMS server address and port + + + + + BMXNetLib implements low-level socket connectivity to RPMS databases. + The VA RPC Broker must be running on the RPMS server in order for + BMXNetLib to connect. + + + + + Corresponds to M's $L(STRING,DELIMITER) + + + + + + + + Corresponds to M's $$Piece function + + + + + + + + + Given strInput = "13" builds "013" if nLength = 3. Default for nLength is 3. + + + + + + + Given strInput = "13" builds "013" if nLength = 3 Default for nLength is 3. + + + Default = 3 + + + + + Concatenates zero-padded length of sInput to sInput + Given "Hello" returns "004Hello" + If nSize = 5, returns "00004Hello" + Default for nSize is 3. + + + + + + + Concatenates zero-padded length of sInput to sInput + Given "Hello" returns "004Hello" + If nSize = 5, returns "00004Hello" + Default for nSize is 3. + + + + + + + + Build protocol header + + + + + + + + + + Returns index of first instance of sSubString in sString. + If sSubString not found, returns -1. + + + + + + + + Lock a local or global M variable + Returns true if lock is obtained during TimeOut seconds + Use + to increment, - to decrement lock. + + + + + + + + + Returns a reference to the internal ReaderWriterLock member. + + + + + Sets and returns the timeout in milliseconds for locking the transmit port. + If the transmit port is unavailable an ApplicationException will be thrown. + + + + + Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. + If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. + The default is 30 seconds. + + + + + Gets/sets the Kernel Application context + Throws an exception if unable to set the context. + + + + + Returns the array of RMPSResultSets retrieved from RPMS + + + + + Sets and Returns the current recordset + + + + + Summary description for DSelectDivision. + + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + + If b is true, moves member vars into control data + otherwise, moves control data into member vars + + + + + + Clean up any resources being used. + + + + + Prompts for RPMS Server address and port + Obtains current values, if any, from isolated storage + and uses them as defaults. + If OK, then writes values to isolated storage and returns + Address and Port as properties. + + + + + + Required designer variable. + + + + + Clean up any resources being used. + + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + + If b is true, moves member vars into control data + otherwise, moves control data into member vars + + + + + + Gets/sets the internet address of the RPMS Server + + + + + Gets/sets the namespace of the RPMS Server + + + + + Gets/sets the TCP/IP Port of the RPMS Server + + + + + Custom exception class for BMXNet + + + + diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/App.ico b/cs/bmx_0200scr/BMX2/BMXNetTest/App.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/App.ico differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/AssemblyInfo.cs b/cs/bmx_0200scr/BMX2/BMXNetTest/AssemblyInfo.cs new file mode 100644 index 0000000..6f99f80 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/AssemblyInfo.cs @@ -0,0 +1,59 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("BMXNetTest")] +[assembly: AssemblyDescription("BMXNet test application")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Indian Health Service")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("2.0.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyKeyName("")] +[assembly: AssemblyFileVersionAttribute("2.0.0.0")] diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNet.dll b/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNet.dll new file mode 100644 index 0000000..ecdbead Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNet.dll differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNetTest.csproj b/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNetTest.csproj new file mode 100644 index 0000000..2050dad --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNetTest.csproj @@ -0,0 +1,126 @@ + + + Local + 8.0.50727 + 2.0 + {A3A19C51-73D2-4EEE-A190-F1EFBF477BCB} + Debug + AnyCPU + App.ico + + + BMXNetTest + IHSPrivateKey.pfx + JScript + Grid + IE50 + true + WinExe + BMXNetTest + OnBuildSuccess + + + + + + + false + + + bin\Debug\ + false + 285212672 + false + + + DEBUG;TRACE + + + true + 4096 + false + + + false + false + false + false + 4 + full + prompt + + + bin\Release\ + false + 285212672 + false + + + TRACE + + + false + 4096 + false + + + true + false + false + false + 4 + none + prompt + + + + False + ..\Dotfuscator\Dotfuscated\BMXNet20.dll + + + System + + + System.Data + + + System.Drawing + + + System.Windows.Forms + + + System.XML + + + + + + Code + + + Form + + + Form + + + frmBMXNetTest.cs + Designer + + + frmVisitDemo.cs + Designer + + + + + + + + + + + + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNetTest.csproj.user b/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNetTest.csproj.user new file mode 100644 index 0000000..2d3315c --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/BMXNetTest.csproj.user @@ -0,0 +1,57 @@ + + + 7.10.3077 + Debug + AnyCPU + C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BMXNet\BMXNetTest\;C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BMXNet\BMXNet\bin\Release\;C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BMXNet\BMXNet\bin\Debug\;C:\Documents and Settings\Horace\My Documents\Visual Studio Projects\BMXNet\BMXNet\bin\Debug\;C:\Documents and Settings\Horace\My Documents\Visual Studio Projects\BMXNet\BMXNet\bin\Release\;C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BMXNet20040610C\BMXNet\bin\Debug\ + + + + + 0 + ProjectFiles + 0 + + + false + false + false + false + false + + + Project + + + + + + + + + + + true + + + false + false + false + false + false + + + Project + + + + + + + + + + + true + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/IHSPrivateKey.pfx b/cs/bmx_0200scr/BMX2/BMXNetTest/IHSPrivateKey.pfx new file mode 100644 index 0000000..3b77e90 Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/IHSPrivateKey.pfx differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNet20.dll b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNet20.dll new file mode 100644 index 0000000..5f4c0c2 Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNet20.dll differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNetTest.exe b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNetTest.exe new file mode 100644 index 0000000..9caf47a Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNetTest.exe differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNetTest.vshost.exe b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNetTest.vshost.exe new file mode 100644 index 0000000..ce3f102 Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/BMXNetTest.vshost.exe differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/IHSPrivateKey.pfx b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/IHSPrivateKey.pfx new file mode 100644 index 0000000..3b77e90 Binary files /dev/null and b/cs/bmx_0200scr/BMX2/BMXNetTest/bin/Release/IHSPrivateKey.pfx differ diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/frmBMXNetTest.cs b/cs/bmx_0200scr/BMX2/BMXNetTest/frmBMXNetTest.cs new file mode 100644 index 0000000..4cf8c54 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/frmBMXNetTest.cs @@ -0,0 +1,1932 @@ +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using System.Data; +using IndianHealthService.BMXNet; +using System.Security.Principal; +using System.Diagnostics; +using System.Xml.Xsl; +using System.Xml; + +namespace IndianHealthService.BMXNet +{ + /// + /// BMXNet demo form. + /// + public partial class frmBMXNetTest : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public frmBMXNetTest() + { + InitializeComponent(); + m_ci = new BMXNetConnectInfo(); + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if (m_ci != null) + m_ci.CloseConnection(); + if (components != null) + { + components.Dispose(); + } + } + base.Dispose( disposing ); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tpaQuery = new System.Windows.Forms.TabPage(); + this.panGrid = new System.Windows.Forms.Panel(); + this.dataGrid2 = new System.Windows.Forms.DataGrid(); + this.panQuery = new System.Windows.Forms.Panel(); + this.cmdAddAll = new System.Windows.Forms.Button(); + this.cmdXML = new System.Windows.Forms.Button(); + this.cmdTest3 = new System.Windows.Forms.Button(); + this.cmdTest4 = new System.Windows.Forms.Button(); + this.cmdCancelChanges = new System.Windows.Forms.Button(); + this.cmdAcceptChanges = new System.Windows.Forms.Button(); + this.cmdExecuteQuery = new System.Windows.Forms.Button(); + this.txtCommand = new System.Windows.Forms.TextBox(); + this.tpaControls = new System.Windows.Forms.TabPage(); + this.grpControls = new System.Windows.Forms.GroupBox(); + this.label13 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.lstCDSex = new System.Windows.Forms.ListBox(); + this.dtpCDDOB = new System.Windows.Forms.DateTimePicker(); + this.calCDDOB = new System.Windows.Forms.MonthCalendar(); + this.cboCDSelect = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.txtCDName = new System.Windows.Forms.TextBox(); + this.lblCDIntro = new System.Windows.Forms.Label(); + this.cmdCDLoad = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.txtCDSex = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtCDDOB = new System.Windows.Forms.TextBox(); + this.txtCDSSN = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.tpaConnection = new System.Windows.Forms.TabPage(); + this.cmdStopLogging = new System.Windows.Forms.Button(); + this.cmdStartLogging = new System.Windows.Forms.Button(); + this.cmdTestReceiveTimeout = new System.Windows.Forms.Button(); + this.cmdTestSilent = new System.Windows.Forms.Button(); + this.txtServer = new System.Windows.Forms.TextBox(); + this.txtUser = new System.Windows.Forms.TextBox(); + this.txtDivision = new System.Windows.Forms.TextBox(); + this.cmdChangeDivision = new System.Windows.Forms.Button(); + this.cmdChangeContext = new System.Windows.Forms.Button(); + this.txtContext = new System.Windows.Forms.TextBox(); + this.cmdChangeUser = new System.Windows.Forms.Button(); + this.cmdChangeServer = new System.Windows.Forms.Button(); + this.tpaOther = new System.Windows.Forms.TabPage(); + this.label19 = new System.Windows.Forms.Label(); + this.grdAsyncResult = new System.Windows.Forms.DataGrid(); + this.label18 = new System.Windows.Forms.Label(); + this.txtAsyncCommand = new System.Windows.Forms.TextBox(); + this.cmdAsyncCall = new System.Windows.Forms.Button(); + this.label17 = new System.Windows.Forms.Label(); + this.txtEventMessages = new System.Windows.Forms.TextBox(); + this.label16 = new System.Windows.Forms.Label(); + this.chkEnableEvents = new System.Windows.Forms.CheckBox(); + this.nudEventPollingInterval = new System.Windows.Forms.NumericUpDown(); + this.chkEventRaiseBack = new System.Windows.Forms.CheckBox(); + this.label15 = new System.Windows.Forms.Label(); + this.txtEventParam = new System.Windows.Forms.TextBox(); + this.label14 = new System.Windows.Forms.Label(); + this.cmdUnregisterEvent = new System.Windows.Forms.Button(); + this.txtUnregisterEvent = new System.Windows.Forms.TextBox(); + this.cmdRaiseEvent = new System.Windows.Forms.Button(); + this.txtRaiseEvent = new System.Windows.Forms.TextBox(); + this.cmdRegisterEvent = new System.Windows.Forms.Button(); + this.txtRegisterEvent = new System.Windows.Forms.TextBox(); + this.grpPiece = new System.Windows.Forms.GroupBox(); + this.txtDelim = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.txtEnd = new System.Windows.Forms.TextBox(); + this.txtResult = new System.Windows.Forms.TextBox(); + this.txtNumber = new System.Windows.Forms.TextBox(); + this.txtInput = new System.Windows.Forms.TextBox(); + this.cmdTestPiece = new System.Windows.Forms.Button(); + this.cmdAcquireLock = new System.Windows.Forms.Button(); + this.cmdReleaseLock = new System.Windows.Forms.Button(); + this.cmdEventPollingInterval = new System.Windows.Forms.Button(); + this.tabControl1.SuspendLayout(); + this.tpaQuery.SuspendLayout(); + this.panGrid.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit(); + this.panQuery.SuspendLayout(); + this.tpaControls.SuspendLayout(); + this.grpControls.SuspendLayout(); + this.tpaConnection.SuspendLayout(); + this.tpaOther.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.grdAsyncResult)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudEventPollingInterval)).BeginInit(); + this.grpPiece.SuspendLayout(); + this.SuspendLayout(); + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tpaQuery); + this.tabControl1.Controls.Add(this.tpaControls); + this.tabControl1.Controls.Add(this.tpaConnection); + this.tabControl1.Controls.Add(this.tpaOther); + this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabControl1.Location = new System.Drawing.Point(0, 0); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(736, 566); + this.tabControl1.TabIndex = 0; + // + // tpaQuery + // + this.tpaQuery.Controls.Add(this.panGrid); + this.tpaQuery.Controls.Add(this.panQuery); + this.tpaQuery.Location = new System.Drawing.Point(4, 22); + this.tpaQuery.Name = "tpaQuery"; + this.tpaQuery.Size = new System.Drawing.Size(728, 540); + this.tpaQuery.TabIndex = 0; + this.tpaQuery.Text = "RPC and Query Testing"; + // + // panGrid + // + this.panGrid.Controls.Add(this.dataGrid2); + this.panGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.panGrid.Location = new System.Drawing.Point(0, 216); + this.panGrid.Name = "panGrid"; + this.panGrid.Size = new System.Drawing.Size(728, 324); + this.panGrid.TabIndex = 43; + // + // dataGrid2 + // + this.dataGrid2.AccessibleName = "DataGrid"; + this.dataGrid2.AccessibleRole = System.Windows.Forms.AccessibleRole.Table; + this.dataGrid2.DataMember = ""; + this.dataGrid2.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText; + this.dataGrid2.Location = new System.Drawing.Point(0, 0); + this.dataGrid2.Name = "dataGrid2"; + this.dataGrid2.Size = new System.Drawing.Size(728, 324); + this.dataGrid2.TabIndex = 40; + this.dataGrid2.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid2_Navigate); + // + // panQuery + // + this.panQuery.Controls.Add(this.cmdAddAll); + this.panQuery.Controls.Add(this.cmdXML); + this.panQuery.Controls.Add(this.cmdTest3); + this.panQuery.Controls.Add(this.cmdTest4); + this.panQuery.Controls.Add(this.cmdCancelChanges); + this.panQuery.Controls.Add(this.cmdAcceptChanges); + this.panQuery.Controls.Add(this.cmdExecuteQuery); + this.panQuery.Controls.Add(this.txtCommand); + this.panQuery.Dock = System.Windows.Forms.DockStyle.Top; + this.panQuery.Location = new System.Drawing.Point(0, 0); + this.panQuery.Name = "panQuery"; + this.panQuery.Size = new System.Drawing.Size(728, 216); + this.panQuery.TabIndex = 42; + // + // cmdAddAll + // + this.cmdAddAll.Location = new System.Drawing.Point(344, 160); + this.cmdAddAll.Name = "cmdAddAll"; + this.cmdAddAll.Size = new System.Drawing.Size(56, 32); + this.cmdAddAll.TabIndex = 78; + this.cmdAddAll.Text = "Add All"; + this.cmdAddAll.Click += new System.EventHandler(this.cmdAddAll_Click); + // + // cmdXML + // + this.cmdXML.Location = new System.Drawing.Point(448, 160); + this.cmdXML.Name = "cmdXML"; + this.cmdXML.Size = new System.Drawing.Size(56, 32); + this.cmdXML.TabIndex = 77; + this.cmdXML.Text = "XML"; + this.cmdXML.Click += new System.EventHandler(this.cmdXML_Click); + // + // cmdTest3 + // + this.cmdTest3.Location = new System.Drawing.Point(648, 160); + this.cmdTest3.Name = "cmdTest3"; + this.cmdTest3.Size = new System.Drawing.Size(72, 32); + this.cmdTest3.TabIndex = 76; + this.cmdTest3.Text = "Low-Level TransmitRPC Demo"; + this.cmdTest3.Click += new System.EventHandler(this.cmdTest3_Click); + // + // cmdTest4 + // + this.cmdTest4.Location = new System.Drawing.Point(560, 160); + this.cmdTest4.Name = "cmdTest4"; + this.cmdTest4.Size = new System.Drawing.Size(80, 32); + this.cmdTest4.TabIndex = 75; + this.cmdTest4.Text = "Table Relations Demo"; + this.cmdTest4.Click += new System.EventHandler(this.cmdTest4_Click); + // + // cmdCancelChanges + // + this.cmdCancelChanges.Location = new System.Drawing.Point(232, 160); + this.cmdCancelChanges.Name = "cmdCancelChanges"; + this.cmdCancelChanges.Size = new System.Drawing.Size(96, 32); + this.cmdCancelChanges.TabIndex = 74; + this.cmdCancelChanges.Text = "Cancel Changes"; + this.cmdCancelChanges.Click += new System.EventHandler(this.cmdCancelChanges_Click); + // + // cmdAcceptChanges + // + this.cmdAcceptChanges.Location = new System.Drawing.Point(120, 160); + this.cmdAcceptChanges.Name = "cmdAcceptChanges"; + this.cmdAcceptChanges.Size = new System.Drawing.Size(96, 32); + this.cmdAcceptChanges.TabIndex = 73; + this.cmdAcceptChanges.Text = "Accept Changes"; + this.cmdAcceptChanges.Click += new System.EventHandler(this.cmdAcceptChanges_Click); + // + // cmdExecuteQuery + // + this.cmdExecuteQuery.Location = new System.Drawing.Point(16, 160); + this.cmdExecuteQuery.Name = "cmdExecuteQuery"; + this.cmdExecuteQuery.Size = new System.Drawing.Size(96, 32); + this.cmdExecuteQuery.TabIndex = 71; + this.cmdExecuteQuery.Text = "Execute Query"; + this.cmdExecuteQuery.Click += new System.EventHandler(this.cmdExecuteQuery_Click); + // + // txtCommand + // + this.txtCommand.Dock = System.Windows.Forms.DockStyle.Top; + this.txtCommand.Location = new System.Drawing.Point(0, 0); + this.txtCommand.Multiline = true; + this.txtCommand.Name = "txtCommand"; + this.txtCommand.Size = new System.Drawing.Size(728, 152); + this.txtCommand.TabIndex = 72; + this.txtCommand.Text = "SELECT NAME, AGE, DOB FROM VA_PATIENT WHERE NAME LIKE \'END%\'"; + // + // tpaControls + // + this.tpaControls.Controls.Add(this.grpControls); + this.tpaControls.Location = new System.Drawing.Point(4, 22); + this.tpaControls.Name = "tpaControls"; + this.tpaControls.Size = new System.Drawing.Size(728, 540); + this.tpaControls.TabIndex = 3; + this.tpaControls.Text = "Controls Demo"; + // + // grpControls + // + this.grpControls.Controls.Add(this.label13); + this.grpControls.Controls.Add(this.label9); + this.grpControls.Controls.Add(this.lstCDSex); + this.grpControls.Controls.Add(this.dtpCDDOB); + this.grpControls.Controls.Add(this.calCDDOB); + this.grpControls.Controls.Add(this.cboCDSelect); + this.grpControls.Controls.Add(this.label1); + this.grpControls.Controls.Add(this.txtCDName); + this.grpControls.Controls.Add(this.lblCDIntro); + this.grpControls.Controls.Add(this.cmdCDLoad); + this.grpControls.Controls.Add(this.label2); + this.grpControls.Controls.Add(this.txtCDSex); + this.grpControls.Controls.Add(this.label3); + this.grpControls.Controls.Add(this.txtCDDOB); + this.grpControls.Controls.Add(this.txtCDSSN); + this.grpControls.Controls.Add(this.label8); + this.grpControls.Controls.Add(this.label10); + this.grpControls.Controls.Add(this.label11); + this.grpControls.Controls.Add(this.label12); + this.grpControls.Controls.Add(this.label4); + this.grpControls.Location = new System.Drawing.Point(0, 8); + this.grpControls.Name = "grpControls"; + this.grpControls.Size = new System.Drawing.Size(704, 520); + this.grpControls.TabIndex = 72; + this.grpControls.TabStop = false; + this.grpControls.Text = "Control demo"; + // + // label13 + // + this.label13.Location = new System.Drawing.Point(368, 128); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(176, 24); + this.label13.TabIndex = 9; + this.label13.Text = "<-- Select a patient after loading the dataset"; + // + // label9 + // + this.label9.Location = new System.Drawing.Point(144, 80); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(312, 24); + this.label9.TabIndex = 8; + this.label9.Text = "<---Press this button to load first 50 patients from VA Patient file into a datas" + + "et."; + // + // lstCDSex + // + this.lstCDSex.Items.AddRange(new object[] { + "MALE", + "FEMALE"}); + this.lstCDSex.Location = new System.Drawing.Point(224, 264); + this.lstCDSex.Name = "lstCDSex"; + this.lstCDSex.Size = new System.Drawing.Size(112, 17); + this.lstCDSex.TabIndex = 7; + // + // dtpCDDOB + // + this.dtpCDDOB.CustomFormat = "MMMM dd, yyyy"; + this.dtpCDDOB.Location = new System.Drawing.Point(72, 392); + this.dtpCDDOB.Name = "dtpCDDOB"; + this.dtpCDDOB.Size = new System.Drawing.Size(264, 20); + this.dtpCDDOB.TabIndex = 6; + // + // calCDDOB + // + this.calCDDOB.Location = new System.Drawing.Point(360, 344); + this.calCDDOB.Name = "calCDDOB"; + this.calCDDOB.TabIndex = 5; + // + // cboCDSelect + // + this.cboCDSelect.Location = new System.Drawing.Point(96, 128); + this.cboCDSelect.Name = "cboCDSelect"; + this.cboCDSelect.Size = new System.Drawing.Size(256, 21); + this.cboCDSelect.TabIndex = 4; + // + // label1 + // + this.label1.Location = new System.Drawing.Point(16, 168); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(40, 16); + this.label1.TabIndex = 3; + this.label1.Text = "Name:"; + // + // txtCDName + // + this.txtCDName.Location = new System.Drawing.Point(72, 168); + this.txtCDName.Name = "txtCDName"; + this.txtCDName.Size = new System.Drawing.Size(280, 20); + this.txtCDName.TabIndex = 2; + // + // lblCDIntro + // + this.lblCDIntro.Location = new System.Drawing.Point(24, 24); + this.lblCDIntro.Name = "lblCDIntro"; + this.lblCDIntro.Size = new System.Drawing.Size(376, 32); + this.lblCDIntro.TabIndex = 1; + this.lblCDIntro.Text = "This panel demonstrates how to load data into various kinds of controls from a da" + + "taset."; + // + // cmdCDLoad + // + this.cmdCDLoad.Location = new System.Drawing.Point(32, 72); + this.cmdCDLoad.Name = "cmdCDLoad"; + this.cmdCDLoad.Size = new System.Drawing.Size(96, 32); + this.cmdCDLoad.TabIndex = 0; + this.cmdCDLoad.Text = "Load Dataset"; + this.cmdCDLoad.Click += new System.EventHandler(this.cmdCDLoad_Click); + // + // label2 + // + this.label2.Location = new System.Drawing.Point(8, 128); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(80, 16); + this.label2.TabIndex = 3; + this.label2.Text = "Select Patient:"; + // + // txtCDSex + // + this.txtCDSex.Location = new System.Drawing.Point(72, 264); + this.txtCDSex.Name = "txtCDSex"; + this.txtCDSex.Size = new System.Drawing.Size(72, 20); + this.txtCDSex.TabIndex = 2; + // + // label3 + // + this.label3.Location = new System.Drawing.Point(72, 240); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(128, 16); + this.label3.TabIndex = 3; + this.label3.Text = "Sex (Text Control):"; + // + // txtCDDOB + // + this.txtCDDOB.Location = new System.Drawing.Point(72, 344); + this.txtCDDOB.Name = "txtCDDOB"; + this.txtCDDOB.Size = new System.Drawing.Size(144, 20); + this.txtCDDOB.TabIndex = 2; + // + // txtCDSSN + // + this.txtCDSSN.Location = new System.Drawing.Point(72, 200); + this.txtCDSSN.Name = "txtCDSSN"; + this.txtCDSSN.Size = new System.Drawing.Size(280, 20); + this.txtCDSSN.TabIndex = 2; + // + // label8 + // + this.label8.Location = new System.Drawing.Point(16, 200); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(40, 16); + this.label8.TabIndex = 3; + this.label8.Text = "SSN:"; + // + // label10 + // + this.label10.Location = new System.Drawing.Point(72, 368); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(136, 16); + this.label10.TabIndex = 3; + this.label10.Text = "DOB (DateTime Picker):"; + // + // label11 + // + this.label11.Location = new System.Drawing.Point(72, 320); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(128, 16); + this.label11.TabIndex = 3; + this.label11.Text = "DOB (Text Control):"; + // + // label12 + // + this.label12.Location = new System.Drawing.Point(360, 320); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(200, 16); + this.label12.TabIndex = 3; + this.label12.Text = "DOB (Calendar Control):"; + // + // label4 + // + this.label4.Location = new System.Drawing.Point(224, 240); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(128, 16); + this.label4.TabIndex = 3; + this.label4.Text = "Sex (ListBox Control):"; + // + // tpaConnection + // + this.tpaConnection.Controls.Add(this.cmdStopLogging); + this.tpaConnection.Controls.Add(this.cmdStartLogging); + this.tpaConnection.Controls.Add(this.cmdTestReceiveTimeout); + this.tpaConnection.Controls.Add(this.cmdTestSilent); + this.tpaConnection.Controls.Add(this.txtServer); + this.tpaConnection.Controls.Add(this.txtUser); + this.tpaConnection.Controls.Add(this.txtDivision); + this.tpaConnection.Controls.Add(this.cmdChangeDivision); + this.tpaConnection.Controls.Add(this.cmdChangeContext); + this.tpaConnection.Controls.Add(this.txtContext); + this.tpaConnection.Controls.Add(this.cmdChangeUser); + this.tpaConnection.Controls.Add(this.cmdChangeServer); + this.tpaConnection.Location = new System.Drawing.Point(4, 22); + this.tpaConnection.Name = "tpaConnection"; + this.tpaConnection.Size = new System.Drawing.Size(605, 465); + this.tpaConnection.TabIndex = 1; + this.tpaConnection.Text = "Connection"; + // + // cmdStopLogging + // + this.cmdStopLogging.Location = new System.Drawing.Point(16, 393); + this.cmdStopLogging.Name = "cmdStopLogging"; + this.cmdStopLogging.Size = new System.Drawing.Size(152, 28); + this.cmdStopLogging.TabIndex = 85; + this.cmdStopLogging.Text = "Stop Logging"; + this.cmdStopLogging.UseVisualStyleBackColor = true; + this.cmdStopLogging.Click += new System.EventHandler(this.cmdStopLogging_Click); + // + // cmdStartLogging + // + this.cmdStartLogging.Location = new System.Drawing.Point(16, 346); + this.cmdStartLogging.Name = "cmdStartLogging"; + this.cmdStartLogging.Size = new System.Drawing.Size(152, 28); + this.cmdStartLogging.TabIndex = 84; + this.cmdStartLogging.Text = "Start Logging"; + this.cmdStartLogging.UseVisualStyleBackColor = true; + this.cmdStartLogging.Click += new System.EventHandler(this.cmdStartLogging_Click); + // + // cmdTestReceiveTimeout + // + this.cmdTestReceiveTimeout.Location = new System.Drawing.Point(16, 294); + this.cmdTestReceiveTimeout.Name = "cmdTestReceiveTimeout"; + this.cmdTestReceiveTimeout.Size = new System.Drawing.Size(152, 28); + this.cmdTestReceiveTimeout.TabIndex = 83; + this.cmdTestReceiveTimeout.Text = "Test Receive Timeout"; + this.cmdTestReceiveTimeout.UseVisualStyleBackColor = true; + this.cmdTestReceiveTimeout.Visible = false; + this.cmdTestReceiveTimeout.Click += new System.EventHandler(this.cmdTestReceiveTimeout_Click); + // + // cmdTestSilent + // + this.cmdTestSilent.Location = new System.Drawing.Point(16, 248); + this.cmdTestSilent.Name = "cmdTestSilent"; + this.cmdTestSilent.Size = new System.Drawing.Size(152, 28); + this.cmdTestSilent.TabIndex = 82; + this.cmdTestSilent.Text = "Test Silent Login"; + this.cmdTestSilent.UseVisualStyleBackColor = true; + this.cmdTestSilent.Visible = false; + this.cmdTestSilent.Click += new System.EventHandler(this.cmdTestSilent_Click); + // + // txtServer + // + this.txtServer.Location = new System.Drawing.Point(176, 24); + this.txtServer.Name = "txtServer"; + this.txtServer.ReadOnly = true; + this.txtServer.Size = new System.Drawing.Size(200, 20); + this.txtServer.TabIndex = 81; + // + // txtUser + // + this.txtUser.Location = new System.Drawing.Point(176, 64); + this.txtUser.Name = "txtUser"; + this.txtUser.ReadOnly = true; + this.txtUser.Size = new System.Drawing.Size(200, 20); + this.txtUser.TabIndex = 80; + // + // txtDivision + // + this.txtDivision.Location = new System.Drawing.Point(176, 104); + this.txtDivision.Name = "txtDivision"; + this.txtDivision.Size = new System.Drawing.Size(200, 20); + this.txtDivision.TabIndex = 79; + // + // cmdChangeDivision + // + this.cmdChangeDivision.Location = new System.Drawing.Point(16, 96); + this.cmdChangeDivision.Name = "cmdChangeDivision"; + this.cmdChangeDivision.Size = new System.Drawing.Size(152, 32); + this.cmdChangeDivision.TabIndex = 78; + this.cmdChangeDivision.Text = "Change Division"; + this.cmdChangeDivision.Click += new System.EventHandler(this.cmdChangeDivision_Click); + // + // cmdChangeContext + // + this.cmdChangeContext.Location = new System.Drawing.Point(16, 136); + this.cmdChangeContext.Name = "cmdChangeContext"; + this.cmdChangeContext.Size = new System.Drawing.Size(152, 32); + this.cmdChangeContext.TabIndex = 77; + this.cmdChangeContext.Text = "Change Application Context"; + this.cmdChangeContext.Click += new System.EventHandler(this.cmdChangeContext_Click); + // + // txtContext + // + this.txtContext.Location = new System.Drawing.Point(176, 144); + this.txtContext.Name = "txtContext"; + this.txtContext.Size = new System.Drawing.Size(200, 20); + this.txtContext.TabIndex = 76; + // + // cmdChangeUser + // + this.cmdChangeUser.Location = new System.Drawing.Point(16, 56); + this.cmdChangeUser.Name = "cmdChangeUser"; + this.cmdChangeUser.Size = new System.Drawing.Size(152, 32); + this.cmdChangeUser.TabIndex = 74; + this.cmdChangeUser.Text = "Change RPMS User Login"; + this.cmdChangeUser.Click += new System.EventHandler(this.cmdChangeUser_Click); + // + // cmdChangeServer + // + this.cmdChangeServer.Location = new System.Drawing.Point(16, 16); + this.cmdChangeServer.Name = "cmdChangeServer"; + this.cmdChangeServer.Size = new System.Drawing.Size(152, 32); + this.cmdChangeServer.TabIndex = 73; + this.cmdChangeServer.Text = "Change RPMS Server"; + this.cmdChangeServer.Click += new System.EventHandler(this.cmdChangeServer_Click); + // + // tpaOther + // + this.tpaOther.Controls.Add(this.label19); + this.tpaOther.Controls.Add(this.grdAsyncResult); + this.tpaOther.Controls.Add(this.label18); + this.tpaOther.Controls.Add(this.txtAsyncCommand); + this.tpaOther.Controls.Add(this.cmdAsyncCall); + this.tpaOther.Controls.Add(this.label17); + this.tpaOther.Controls.Add(this.txtEventMessages); + this.tpaOther.Controls.Add(this.label16); + this.tpaOther.Controls.Add(this.chkEnableEvents); + this.tpaOther.Controls.Add(this.nudEventPollingInterval); + this.tpaOther.Controls.Add(this.chkEventRaiseBack); + this.tpaOther.Controls.Add(this.label15); + this.tpaOther.Controls.Add(this.txtEventParam); + this.tpaOther.Controls.Add(this.label14); + this.tpaOther.Controls.Add(this.cmdUnregisterEvent); + this.tpaOther.Controls.Add(this.txtUnregisterEvent); + this.tpaOther.Controls.Add(this.cmdRaiseEvent); + this.tpaOther.Controls.Add(this.txtRaiseEvent); + this.tpaOther.Controls.Add(this.cmdRegisterEvent); + this.tpaOther.Controls.Add(this.txtRegisterEvent); + this.tpaOther.Controls.Add(this.grpPiece); + this.tpaOther.Controls.Add(this.cmdAcquireLock); + this.tpaOther.Controls.Add(this.cmdReleaseLock); + this.tpaOther.Controls.Add(this.cmdEventPollingInterval); + this.tpaOther.Location = new System.Drawing.Point(4, 22); + this.tpaOther.Name = "tpaOther"; + this.tpaOther.Size = new System.Drawing.Size(605, 465); + this.tpaOther.TabIndex = 2; + this.tpaOther.Text = "Events"; + // + // label19 + // + this.label19.Location = new System.Drawing.Point(416, 176); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(160, 16); + this.label19.TabIndex = 107; + this.label19.Text = "Asyncronous Result Set"; + // + // grdAsyncResult + // + this.grdAsyncResult.DataMember = ""; + this.grdAsyncResult.HeaderForeColor = System.Drawing.SystemColors.ControlText; + this.grdAsyncResult.Location = new System.Drawing.Point(416, 192); + this.grdAsyncResult.Name = "grdAsyncResult"; + this.grdAsyncResult.Size = new System.Drawing.Size(296, 304); + this.grdAsyncResult.TabIndex = 106; + // + // label18 + // + this.label18.Location = new System.Drawing.Point(416, 40); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(160, 16); + this.label18.TabIndex = 105; + this.label18.Text = "Command String:"; + // + // txtAsyncCommand + // + this.txtAsyncCommand.Location = new System.Drawing.Point(416, 56); + this.txtAsyncCommand.Multiline = true; + this.txtAsyncCommand.Name = "txtAsyncCommand"; + this.txtAsyncCommand.Size = new System.Drawing.Size(288, 48); + this.txtAsyncCommand.TabIndex = 104; + this.txtAsyncCommand.Text = "BMX DEMO^W^15"; + // + // cmdAsyncCall + // + this.cmdAsyncCall.Location = new System.Drawing.Point(416, 120); + this.cmdAsyncCall.Name = "cmdAsyncCall"; + this.cmdAsyncCall.Size = new System.Drawing.Size(144, 32); + this.cmdAsyncCall.TabIndex = 103; + this.cmdAsyncCall.Text = "Make Asynchronous Call"; + this.cmdAsyncCall.Click += new System.EventHandler(this.cmdAsyncCall_Click); + // + // label17 + // + this.label17.Location = new System.Drawing.Point(24, 288); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(160, 16); + this.label17.TabIndex = 102; + this.label17.Text = "Event Messages"; + // + // txtEventMessages + // + this.txtEventMessages.Location = new System.Drawing.Point(24, 304); + this.txtEventMessages.Multiline = true; + this.txtEventMessages.Name = "txtEventMessages"; + this.txtEventMessages.Size = new System.Drawing.Size(360, 40); + this.txtEventMessages.TabIndex = 101; + // + // label16 + // + this.label16.Location = new System.Drawing.Point(272, 232); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(96, 16); + this.label16.TabIndex = 100; + this.label16.Text = "(milliseconds)"; + // + // chkEnableEvents + // + this.chkEnableEvents.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; + this.chkEnableEvents.Location = new System.Drawing.Point(184, 16); + this.chkEnableEvents.Name = "chkEnableEvents"; + this.chkEnableEvents.Size = new System.Drawing.Size(104, 16); + this.chkEnableEvents.TabIndex = 99; + this.chkEnableEvents.Text = "Enable Events"; + this.chkEnableEvents.CheckedChanged += new System.EventHandler(this.chkEnableEvents_CheckedChanged); + // + // nudEventPollingInterval + // + this.nudEventPollingInterval.Increment = new decimal(new int[] { + 500, + 0, + 0, + 0}); + this.nudEventPollingInterval.Location = new System.Drawing.Point(192, 232); + this.nudEventPollingInterval.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.nudEventPollingInterval.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nudEventPollingInterval.Name = "nudEventPollingInterval"; + this.nudEventPollingInterval.Size = new System.Drawing.Size(64, 20); + this.nudEventPollingInterval.TabIndex = 98; + this.nudEventPollingInterval.Value = new decimal(new int[] { + 3000, + 0, + 0, + 0}); + this.nudEventPollingInterval.ValueChanged += new System.EventHandler(this.nudEventPollingInterval_ValueChanged); + // + // chkEventRaiseBack + // + this.chkEventRaiseBack.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; + this.chkEventRaiseBack.Checked = true; + this.chkEventRaiseBack.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkEventRaiseBack.Location = new System.Drawing.Point(192, 160); + this.chkEventRaiseBack.Name = "chkEventRaiseBack"; + this.chkEventRaiseBack.Size = new System.Drawing.Size(96, 16); + this.chkEventRaiseBack.TabIndex = 97; + this.chkEventRaiseBack.Text = "Raise Back"; + // + // label15 + // + this.label15.Location = new System.Drawing.Point(192, 128); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(48, 16); + this.label15.TabIndex = 96; + this.label15.Text = "Param"; + // + // txtEventParam + // + this.txtEventParam.Location = new System.Drawing.Point(240, 128); + this.txtEventParam.Name = "txtEventParam"; + this.txtEventParam.Size = new System.Drawing.Size(144, 20); + this.txtEventParam.TabIndex = 95; + // + // label14 + // + this.label14.Location = new System.Drawing.Point(192, 98); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(48, 16); + this.label14.TabIndex = 94; + this.label14.Text = "Event"; + // + // cmdUnregisterEvent + // + this.cmdUnregisterEvent.Location = new System.Drawing.Point(24, 184); + this.cmdUnregisterEvent.Name = "cmdUnregisterEvent"; + this.cmdUnregisterEvent.Size = new System.Drawing.Size(152, 32); + this.cmdUnregisterEvent.TabIndex = 93; + this.cmdUnregisterEvent.Text = "UnSubscribe Event"; + this.cmdUnregisterEvent.Click += new System.EventHandler(this.cmdUnregisterEvent_Click); + // + // txtUnregisterEvent + // + this.txtUnregisterEvent.Location = new System.Drawing.Point(184, 192); + this.txtUnregisterEvent.Name = "txtUnregisterEvent"; + this.txtUnregisterEvent.Size = new System.Drawing.Size(200, 20); + this.txtUnregisterEvent.TabIndex = 92; + // + // cmdRaiseEvent + // + this.cmdRaiseEvent.Location = new System.Drawing.Point(24, 88); + this.cmdRaiseEvent.Name = "cmdRaiseEvent"; + this.cmdRaiseEvent.Size = new System.Drawing.Size(152, 32); + this.cmdRaiseEvent.TabIndex = 91; + this.cmdRaiseEvent.Text = "Raise Event"; + this.cmdRaiseEvent.Click += new System.EventHandler(this.cmdRaiseEvent_Click); + // + // txtRaiseEvent + // + this.txtRaiseEvent.Location = new System.Drawing.Point(240, 96); + this.txtRaiseEvent.Name = "txtRaiseEvent"; + this.txtRaiseEvent.Size = new System.Drawing.Size(144, 20); + this.txtRaiseEvent.TabIndex = 90; + // + // cmdRegisterEvent + // + this.cmdRegisterEvent.Location = new System.Drawing.Point(24, 48); + this.cmdRegisterEvent.Name = "cmdRegisterEvent"; + this.cmdRegisterEvent.Size = new System.Drawing.Size(152, 32); + this.cmdRegisterEvent.TabIndex = 89; + this.cmdRegisterEvent.Text = "Subscribe Event"; + this.cmdRegisterEvent.Click += new System.EventHandler(this.cmdRegisterEvent_Click); + // + // txtRegisterEvent + // + this.txtRegisterEvent.Location = new System.Drawing.Point(184, 56); + this.txtRegisterEvent.Name = "txtRegisterEvent"; + this.txtRegisterEvent.Size = new System.Drawing.Size(200, 20); + this.txtRegisterEvent.TabIndex = 88; + // + // grpPiece + // + this.grpPiece.Controls.Add(this.txtDelim); + this.grpPiece.Controls.Add(this.label7); + this.grpPiece.Controls.Add(this.label6); + this.grpPiece.Controls.Add(this.label5); + this.grpPiece.Controls.Add(this.txtEnd); + this.grpPiece.Controls.Add(this.txtResult); + this.grpPiece.Controls.Add(this.txtNumber); + this.grpPiece.Controls.Add(this.txtInput); + this.grpPiece.Controls.Add(this.cmdTestPiece); + this.grpPiece.Enabled = false; + this.grpPiece.Location = new System.Drawing.Point(24, 408); + this.grpPiece.Name = "grpPiece"; + this.grpPiece.Size = new System.Drawing.Size(264, 120); + this.grpPiece.TabIndex = 71; + this.grpPiece.TabStop = false; + this.grpPiece.Text = "Piece Function Testing"; + this.grpPiece.Visible = false; + // + // txtDelim + // + this.txtDelim.Location = new System.Drawing.Point(24, 56); + this.txtDelim.Name = "txtDelim"; + this.txtDelim.Size = new System.Drawing.Size(16, 20); + this.txtDelim.TabIndex = 55; + this.txtDelim.Text = "^"; + // + // label7 + // + this.label7.Location = new System.Drawing.Point(96, 40); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(48, 16); + this.label7.TabIndex = 54; + this.label7.Text = "End:"; + this.label7.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // label6 + // + this.label6.Location = new System.Drawing.Point(48, 40); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(48, 16); + this.label6.TabIndex = 53; + this.label6.Text = "Start:"; + this.label6.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // label5 + // + this.label5.Location = new System.Drawing.Point(8, 40); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(48, 16); + this.label5.TabIndex = 52; + this.label5.Text = "Delim:"; + this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // txtEnd + // + this.txtEnd.Location = new System.Drawing.Point(112, 56); + this.txtEnd.Name = "txtEnd"; + this.txtEnd.Size = new System.Drawing.Size(32, 20); + this.txtEnd.TabIndex = 45; + this.txtEnd.Text = "3"; + // + // txtResult + // + this.txtResult.Location = new System.Drawing.Point(16, 88); + this.txtResult.Name = "txtResult"; + this.txtResult.Size = new System.Drawing.Size(208, 20); + this.txtResult.TabIndex = 44; + // + // txtNumber + // + this.txtNumber.Location = new System.Drawing.Point(64, 56); + this.txtNumber.Name = "txtNumber"; + this.txtNumber.Size = new System.Drawing.Size(32, 20); + this.txtNumber.TabIndex = 43; + this.txtNumber.Text = "2"; + // + // txtInput + // + this.txtInput.Location = new System.Drawing.Point(16, 16); + this.txtInput.Name = "txtInput"; + this.txtInput.Size = new System.Drawing.Size(200, 20); + this.txtInput.TabIndex = 42; + this.txtInput.Text = "1^2^3^4"; + // + // cmdTestPiece + // + this.cmdTestPiece.Location = new System.Drawing.Point(152, 56); + this.cmdTestPiece.Name = "cmdTestPiece"; + this.cmdTestPiece.Size = new System.Drawing.Size(72, 24); + this.cmdTestPiece.TabIndex = 41; + this.cmdTestPiece.Text = "Test Piece"; + this.cmdTestPiece.Click += new System.EventHandler(this.cmdTestPiece_Click_1); + // + // cmdAcquireLock + // + this.cmdAcquireLock.Location = new System.Drawing.Point(24, 360); + this.cmdAcquireLock.Name = "cmdAcquireLock"; + this.cmdAcquireLock.Size = new System.Drawing.Size(104, 32); + this.cmdAcquireLock.TabIndex = 89; + this.cmdAcquireLock.Text = "Acquire Lock"; + this.cmdAcquireLock.Click += new System.EventHandler(this.cmdAcquireLock_Click); + // + // cmdReleaseLock + // + this.cmdReleaseLock.Location = new System.Drawing.Point(136, 360); + this.cmdReleaseLock.Name = "cmdReleaseLock"; + this.cmdReleaseLock.Size = new System.Drawing.Size(88, 32); + this.cmdReleaseLock.TabIndex = 89; + this.cmdReleaseLock.Text = "Release Lock"; + this.cmdReleaseLock.Click += new System.EventHandler(this.cmdReleaseLock_Click); + // + // cmdEventPollingInterval + // + this.cmdEventPollingInterval.Location = new System.Drawing.Point(24, 226); + this.cmdEventPollingInterval.Name = "cmdEventPollingInterval"; + this.cmdEventPollingInterval.Size = new System.Drawing.Size(152, 32); + this.cmdEventPollingInterval.TabIndex = 93; + this.cmdEventPollingInterval.Text = "Event Polling Interval"; + // + // frmBMXNetTest + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(736, 566); + this.Controls.Add(this.tabControl1); + this.Name = "frmBMXNetTest"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "BMXNet Test Application"; + this.Load += new System.EventHandler(this.frmBMXNetTest_Load); + this.tabControl1.ResumeLayout(false); + this.tpaQuery.ResumeLayout(false); + this.panGrid.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit(); + this.panQuery.ResumeLayout(false); + this.panQuery.PerformLayout(); + this.tpaControls.ResumeLayout(false); + this.grpControls.ResumeLayout(false); + this.grpControls.PerformLayout(); + this.tpaConnection.ResumeLayout(false); + this.tpaConnection.PerformLayout(); + this.tpaOther.ResumeLayout(false); + this.tpaOther.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.grdAsyncResult)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudEventPollingInterval)).EndInit(); + this.grpPiece.ResumeLayout(false); + this.grpPiece.PerformLayout(); + this.ResumeLayout(false); + + } + #endregion + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + try + { + Application.Run(new frmBMXNetTest()); + return; + } + catch (Exception ex) + { + MessageBox.Show("BMXNetTest Error: " + ex.Message, "BMXNetTest", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + } + + private BMXNetConnectInfo m_ci; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.DataGrid dataGrid2; + private System.Windows.Forms.Button cmdCancelChanges; + private System.Windows.Forms.TextBox txtCommand; + private System.Windows.Forms.TextBox txtContext; + private System.Windows.Forms.Button cmdChangeUser; + private System.Windows.Forms.Button cmdChangeServer; + private System.Windows.Forms.Button cmdChangeContext; + private System.Windows.Forms.Button cmdChangeDivision; + private System.Windows.Forms.TextBox txtDivision; + private System.Windows.Forms.TextBox txtUser; + private System.Windows.Forms.TextBox txtServer; + private System.Windows.Forms.TabPage tpaQuery; + private System.Windows.Forms.Panel panGrid; + private System.Windows.Forms.Panel panQuery; + private System.Windows.Forms.TabPage tpaConnection; + private System.Windows.Forms.TabPage tpaOther; + private System.Windows.Forms.GroupBox grpPiece; + private System.Windows.Forms.TextBox txtDelim; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtEnd; + private System.Windows.Forms.TextBox txtResult; + private System.Windows.Forms.TextBox txtNumber; + private System.Windows.Forms.TextBox txtInput; + private System.Windows.Forms.Button cmdTestPiece; + private System.Windows.Forms.Button cmdTest4; + private System.Windows.Forms.Button cmdTest3; + private System.Windows.Forms.Button cmdExecuteQuery; + private System.Windows.Forms.Button cmdAcceptChanges; + private System.Windows.Forms.Button cmdXML; + private System.Windows.Forms.GroupBox grpControls; + private System.Windows.Forms.Button cmdCDLoad; + private System.Windows.Forms.Label lblCDIntro; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtCDName; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TextBox txtCDSex; + private System.Windows.Forms.TextBox txtCDDOB; + private System.Windows.Forms.TextBox txtCDSSN; + private System.Windows.Forms.ComboBox cboCDSelect; + private System.Windows.Forms.MonthCalendar calCDDOB; + private System.Windows.Forms.TabPage tpaControls; + private System.Windows.Forms.DateTimePicker dtpCDDOB; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.ListBox lstCDSex; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.Button cmdAddAll; + private System.Windows.Forms.Button cmdUnregisterEvent; + private System.Windows.Forms.TextBox txtUnregisterEvent; + private System.Windows.Forms.Button cmdRaiseEvent; + private System.Windows.Forms.TextBox txtRaiseEvent; + private System.Windows.Forms.Button cmdRegisterEvent; + private System.Windows.Forms.TextBox txtRegisterEvent; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.TextBox txtEventParam; + private System.Windows.Forms.CheckBox chkEventRaiseBack; + private System.Windows.Forms.Button cmdAcquireLock; + private System.Windows.Forms.Button cmdReleaseLock; + private System.Windows.Forms.Button cmdEventPollingInterval; + private System.Windows.Forms.NumericUpDown nudEventPollingInterval; + private System.Windows.Forms.CheckBox chkEnableEvents; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.TextBox txtEventMessages; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Button cmdAsyncCall; + private System.Windows.Forms.TextBox txtAsyncCommand; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.DataGrid grdAsyncResult; + private System.Windows.Forms.Label label19; + private Button cmdTestSilent; + private Button cmdTestReceiveTimeout; + private Button cmdStopLogging; + private Button cmdStartLogging; + BMXNetDataAdapter m_da = new BMXNetDataAdapter(); + + + + private void frmBMXNetTest_Load(object sender, System.EventArgs e) + { + //Basic steps to establish a BMXNet connection. + //The first time a user connects, he will be prompted for + //server info and passwords. + //Subsequent connect requests will use cached information. + //Note that LoadConnectInfo maintain's an internal copy + //of a BMXNetLib object which is accessible from the + //bmxNetLib property + // + //Use the ADO.NET provider methods or the BMXNetLib TransmitRPC + //method to create a connection and exchange data. + if (m_ci == null) + m_ci = new BMXNetConnectInfo(); + + m_ci.EventPollingEnabled = false; + m_ci.BMXNetEvent += new BMXNetConnectInfo.BMXNetEventDelegate(BMXNetEventHandler); + try + { + //Use this overload to connect to the last M server + //using Windows NT integrated security + m_ci.LoadConnectInfo(); + + //Use the following overload to force prompt for AV codes. + //You can also use this overload if + // you want to create your own dialog to collect + // AV codes. You may then pass + // the values you collected to LoadConnectInfo(access,verify) + // + //m_ci.LoadConnectInfo("",""); + + m_ci.AppContext = "BMXRPC"; + txtContext.Text = m_ci.AppContext; + this.txtServer.Text = m_ci.MServerAddress; + this.txtUser.Text = m_ci.UserName; + this.txtDivision.Text = m_ci.DivisionName; + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest"); + } + txtCommand.Text = "BMX ADO SS^HW TEST^^~1~20~5"; + //txtCommand.Text = "SELECT NAME, AGE, DOB FROM PATIENT WHERE (NAME LIKE 'E%') AND (AGE BETWEEN 20 AND 60) MAXRECORDS:50"; +// this.txtCommand.Text= "BMXGetFacRS^408"; +// this.txtCommand.Text = "SELECT BMXIEN, NAME, AGE, DOB FROM VA_PATIENT WHERE (NAME LIKE 'E%') AND (AGE BETWEEN 20 AND 60) MAXRECORDS:50"; +// txtCommand.Text = "BMX TEST^S|30"; +// txtCommand.Text = "BMX ADO SS^IHS PATIENT^^~1~20~5"; +// txtCommand.Text = "BMX ADO SS^17^^~4~4~5~~~~~18,SUB"; +// //SIEN1,"","AA~3/21/1965~6/4/2004~5~~~~235|WT|C~11,.02" +// txtCommand.Text = "BMX ADO SS^23^^AA~3/21/1965~6/4/2004~5~~~~235|WT|C~11,.02"; +// txtCommand.Text = "BMX ADO SS^17^^~4~9~~~~~~18,SUB"; +// txtCommand.Text = "BMX ADO SS^11^^~1~5~~~~~~25,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C"; +// txtCommand.Text = "BMX ADO SS^18^1,^~~~"; +// txtCommand.Text = "BMX ADO SS^PATIENT DEMOGRAPHICS^^~1~5~"; +// txtCommand.Text = @"BMX ADO SS^53^^~~~~~VMEAS~BMXADOFD~100002.1A||PU\60|WT\175|HT\70"; +// txtCommand.Text = "BMX ADO SS^3^^~1658~1658^11,.05IEN,.001"; +// BMX ADO SS^HW SD DEVICE1^^~~~ + } + + private void cmdTestPiece_Click_1(object sender, System.EventArgs e) + { + //Demo of BMXNet Piece function. Note that only single-character + //delimiters are supported. + try + { + string sInput = txtInput.Text; + string sDelim = txtDelim.Text; + if (sDelim.Length > 1) + throw new BMXNetException("BMXNet.Piece() supports only single-character delimiters."); + int nNumber = Convert.ToInt16(txtNumber.Text); + int nEnd = 0; + string sOutput = ""; + if (txtEnd.Text != "") + { + nEnd = Convert.ToInt16(txtEnd.Text); + sOutput = BMXNetLib.Piece(sInput, sDelim, nNumber, nEnd); + } + else + { + sOutput = BMXNetLib.Piece(sInput, sDelim, nNumber); + } + + txtResult.Text = sOutput; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest Error"); + } + } + + private void cmdTest3_Click(object sender, System.EventArgs e) + { + //How to create a low-level socket connection using + //BMXNetLib and transmit a simple RPC. + + //Always use try-catch blocks. BMXNet uses exceptions to report + //errors and connection failures. + try + { + BMXNetLib bnLib; + bnLib = new BMXNetLib(); + + //Either collect your own connection information + //or use the Windows Identity map to RPMS + //and manually open a connection like this: + //bnLib.MServerPort = nPort; + //bnLib.OpenConnection(sIP, sAccess, sVerify); + // -or- + //bnLib.OpenConnection(sIP, WindowsIdentity.GetCurrent()); + //bnLib.AppContext = "BMXRPC"; + //If no exception thrown by OpenConnection, then connection + //to rpms succeeded. If OpenConnection fails, then an exception + //is thrown. + + // -OR- Use BMXNetConnectInfo to establish connection + //LoadConnectInfo will prompt for server and user info as needed + + bnLib.MServerPort = m_ci.MServerPort; + bnLib.OpenConnection("127.0.0.1",WindowsIdentity.GetCurrent()); +// bnLib.OpenConnection("127.0.0.1","",""); + bnLib.AppContext = "BMXRPC"; + + string sDUZ = bnLib.DUZ; + string sUser = bnLib.TransmitRPC("BMX USER", sDUZ); + if (sUser.StartsWith("M ERROR=") == true) + { + Exception ex = new Exception(sUser); + throw ex; + } + MessageBox.Show("Connection to RPMS succeeded. User name = " + sUser, "BMXNetLib Test"); + bnLib.CloseConnection(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest Error"); + } + + } + + private void cmdTest4_Click(object sender, System.EventArgs e) + { + /*Demo of retrieving multiple related tables, + * joining them, + * and attaching them to a grid that can + * drill-down through the relations + */ + try + { + if (m_ci.Connected == false) + { + throw new BMXNetException("Not connected to RPMS."); + } + frmVisitDemo frmVD = new frmVisitDemo(); + frmVD.InitializePage(m_ci); + frmVD.ShowDialog(this); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest Error"); + } + + } + + private void cmdChangeServer_Click(object sender, System.EventArgs e) + { + //How to change the RPMS server in BMXNetConnectInfo + try + { + m_ci.ChangeServerInfo(); + m_ci.LoadConnectInfo(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest"); + } + + } + + private void cmdChangeUser_Click(object sender, System.EventArgs e) + { + //How to change the RPMS user + try + { + m_ci.LoadConnectInfo("",""); + m_ci.AppContext = "BMXRPC"; + MessageBox.Show("User changed to " + m_ci.UserName + " on Server " + m_ci.MServerAddress + ", on Port " + m_ci.MServerPort); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest"); + } + } + + private void cmdCancelChanges_Click(object sender, System.EventArgs e) + { + DataTable dt = (DataTable) dataGrid2.DataSource; + dt.RejectChanges(); + } + + private void cmdChangeContext_Click(object sender, System.EventArgs e) + { + try + { + m_ci.AppContext = txtContext.Text; + MessageBox.Show("Context changed to " + m_ci.AppContext); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void cmdChangeDivision_Click(object sender, System.EventArgs e) + { + + /*How to change user division: + * You can either create your own dialog, populate + * it with using the UserDivisions datatable and DUZ2 string + * from ConnectInfo + * and then manually reset ConnectInfo's DUZ2 property, + * -OR- + * you can invoke ConnectInfo's ChangeDivision method + * which will display its own dialog for you. The + * commented code below shows the 'manual' way (you will have to + * first create a 'DSelectDivision' dialog class) + */ + + if (m_ci.Connected == false) + { + throw new BMXNetException("Not connected to RPMS."); + } + +// DSelectDivision dsd = new DSelectDivision(); +// dsd.InitializePage(m_ci.UserDivisions, m_ci.DUZ2); +// if (dsd.ShowDialog(this) == DialogResult.Cancel) +// return; +// m_ci.DUZ2 = dsd.DUZ2; + + m_ci.ChangeDivision(this); + this.txtDivision.Text = m_ci.DivisionName; + } + + private void cmdExecuteQuery_Click(object sender, System.EventArgs e) + { + //This is the 'Execute' button on the form and demonstrates + //how to use the BMXNet ADO.NET Data Provider to + //retrieve an RPMS ADO.NET datatable. + MessageBox.Show("TEST"); + try + { + if (m_ci.Connected == false) + { + throw new Exception("Not connected to RPMS."); + } + //m_ci.bmxNetLib.StartLog("TestLog.txt"); + //m_ci.bmxNetLib.StartLog(); + m_ci.bmxNetLib.BMXRWL.AcquireWriterLock(5); + dataGrid2.DataSource = m_ci.RPMSDataTable(txtCommand.Text, "SampleTable"); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return; + } + finally + { + if (m_ci.bmxNetLib.BMXRWL.IsWriterLockHeld == true) + { + m_ci.bmxNetLib.BMXRWL.ReleaseWriterLock(); + } + //m_ci.bmxNetLib.StopLog(); + + } + } + + /// + /// How to Accept Updates to an updateable recordset + /// using the BMXNetDataAdapter's Update method + /// + /// + /// + private void cmdAcceptChanges_Click(object sender, System.EventArgs e) + { + int nTimeOut = m_ci.ReceiveTimeout; + try + { + m_ci.ReceiveTimeout = (90 * 1000); + DataTable dtPrimary = (DataTable)dataGrid2.DataSource; + DataSet ds = dtPrimary.DataSet; + if ((dtPrimary.DataSet is DataSet) == false) + { + ds = new DataSet(); + ds.Tables.Add(dtPrimary); + } + foreach (DataTable dt in ds.Tables) + { + BMXNetConnection conn = new BMXNetConnection(m_ci.bmxNetLib); + DataTable dtc = dt.GetChanges(); + if (dtc != null) + { + + BMXNetCommand bmxSelectCmd = (BMXNetCommand)conn.CreateCommand(); + bmxSelectCmd.CommandText = txtCommand.Text; + m_da.SelectCommand = bmxSelectCmd; + + DataTable dtSchema = m_da.FillSchema(dtc, SchemaType.Source); + + //Build UPDATE command based on info stored in table's extended property set + BMXNetCommand bmxUpdateCmd = new BMXNetCommand(); + bmxUpdateCmd.Connection = conn; + + //Call BMXBuildUpdateCommand(dtSchema) to set up parameters + bmxUpdateCmd.BMXBuildUpdateCommand(dtSchema); + + //Link command to data adapeter + m_da.UpdateCommand = bmxUpdateCmd; + + //Call adapter's Update method + m_da.Update(dtc); + + //Accept the changes to the datagrid's datatable + dt.AcceptChanges(); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + finally + { + m_ci.ReceiveTimeout = nTimeOut; + } + } + + private void dataGrid2_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne) + { + string sDirection = (ne.Forward == true)?"forward":"backward"; + string myString = "Navigate event raised, moved " + sDirection; + Debug.Write(myString + "\n"); + + } + + private void cmdXML_Click(object sender, System.EventArgs e) + { + //Writes contents of the datagrid's current dataset to XML file + //Also writes dataset structure to XSD schema file + //Transforms the datetime data in the XML file to a format acceptable to + // MS Excel by removing the UTC time conversion info from the end of the datetime string + try + { + DataTable dtPrimary = (DataTable)dataGrid2.DataSource; + DataSet ds = dtPrimary.DataSet; + + if ((dtPrimary.DataSet is DataSet) == false) + { + ds = new DataSet(); + ds.Tables.Add(dtPrimary); + } + + SaveFileDialog saveFileDialog1 = new SaveFileDialog(); + saveFileDialog1.Filter = "XML Files (*.xml)|*.xml|All files (*.*)|*.*"; + saveFileDialog1.FilterIndex = 0; + saveFileDialog1.RestoreDirectory = true; + saveFileDialog1.AddExtension = true; + saveFileDialog1.DefaultExt = "xml"; + + if (saveFileDialog1.ShowDialog() != DialogResult.OK) + { + return; + } + + //create file names based on user input. + //sFile = the name of the XML file created by the dataset export + //sSchemaFile = the schema generated by the dataset + //xXSL file = the transform file applied to sFile + //sFileOut = the final transformed XML file + string sFile = saveFileDialog1.FileName; + string sSchemaFile = sFile.Remove(sFile.Length - 4, 4); + sSchemaFile = sSchemaFile + "Schema.xsd"; + string sFileOut = sFile; + sFile = sFile.Remove(sFile.Length - 4, 4); + sFile = sFile + "Input.xml"; + string sXSLFile = sSchemaFile.Remove(sSchemaFile.Length - 10, 10); + sXSLFile = sXSLFile + "Transform.xslt"; + + // Open file to which to write schema + System.IO.FileStream fsSchema = new System.IO.FileStream + (sSchemaFile, System.IO.FileMode.Create); + System.Xml.XmlTextWriter schemaWriter = + new System.Xml.XmlTextWriter(fsSchema, System.Text.Encoding.ASCII); + ds.WriteXmlSchema(schemaWriter); + schemaWriter.Close(); + + // Write out the dataset to xml + System.IO.FileStream myFileStream = new System.IO.FileStream + (sFile, System.IO.FileMode.Create); + System.Xml.XmlTextWriter myXmlWriter = + new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.ASCII); + ds.WriteXml(myXmlWriter); + myXmlWriter.Close(); + + //Create and apply an xslt file to reformat dates to be Excel compatible + //First create the xslt transform + this.CreateXSL(sSchemaFile, sXSLFile); + //Apply the transform + System.Xml.XmlResolver xmlr = null; + XslTransform xslt = new XslTransform(); + //System.Xml.Xsl.XslCompiledTransform xslt = new XslCompiledTransform(); + try + { + xslt.Load(sXSLFile, xmlr); + //xslt.Load(sXSLFile, null , xmlr); + + xslt.Transform(sFile, sFileOut, xmlr); + //xslt.Transform( + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void CreateXSL(string sXsdFile, string sXsltFile) + { + //Given an xsd file, create an xsl transform to apply to xlm file + //that will transform xml date format to Excel dates by removing UTC information + //from the xml datetime value. + + //Open the xsd input file and xsl output file + //and associate with XML reader and writer + + string sFileIn = sXsdFile; + string sFileOut = sXsltFile; + + //Open XMLTextWriter + System.IO.FileStream fsOut = new System.IO.FileStream + (sFileOut, System.IO.FileMode.Create); + System.Xml.XmlTextWriter xwOut = + new System.Xml.XmlTextWriter(fsOut, System.Text.Encoding.ASCII); + + //Write to the output file + xwOut.Formatting=Formatting.Indented; + + xwOut.WriteStartElement("xsl", "stylesheet", "http://www.w3.org/1999/XSL/Transform"); + xwOut.WriteAttributeString("xmlns","msxsl",null, "urn:schemas-microsoft-com:xslt"); + xwOut.WriteAttributeString("xmlns","bmx",null, "http://bmx.ihs.gov"); + xwOut.WriteAttributeString("version", "1.0"); + + xwOut.WriteStartElement( "msxsl", "script", null); + xwOut.WriteAttributeString("implements-prefix", "bmx"); + xwOut.WriteAttributeString("language", "C#"); + + string sCode = "\npublic string ExcelDate(string sXMLDate) {\n"; + sCode += "string sConverted;\n"; + sCode += "sConverted = sXMLDate.Remove(sXMLDate.Length - 15,15);\n"; + sCode += "return sConverted;\n"; + sCode += "}\n"; + xwOut.WriteCData(sCode); + xwOut.WriteFullEndElement(); //msxsl script + + xwOut.WriteStartElement("xsl", "output", null); + xwOut.WriteAttributeString("method", "xml"); + xwOut.WriteAttributeString("indent", "yes"); + xwOut.WriteEndElement(); + + xwOut.WriteStartElement("xsl", "template", null); + xwOut.WriteAttributeString("match", "@*|node()"); + xwOut.WriteStartElement("xsl", "copy", null); + xwOut.WriteStartElement("xsl", "apply-templates", null); + xwOut.WriteAttributeString("select", "@*|node()"); + xwOut.WriteEndElement(); //apply templates + xwOut.WriteFullEndElement(); //copy + xwOut.WriteFullEndElement(); //template + + ArrayList alFieldNames = new ArrayList(); + + //read from schema file + //Open XMLTextReader + System.IO.FileStream fsIn = new System.IO.FileStream + (sFileIn, System.IO.FileMode.Open); + System.Xml.XmlTextReader xrIn = + new System.Xml.XmlTextReader(fsIn); + + string sFieldName = ""; + while (xrIn.Read()) + { + if (xrIn.NodeType == XmlNodeType.Element) + { + switch (xrIn.LocalName) + { + case "element": + if (xrIn.MoveToAttribute("name")) + { + sFieldName = xrIn.Value; + if (xrIn.MoveToAttribute("type")) + { + if (xrIn.Value == "xs:dateTime") + { + alFieldNames.Add(sFieldName); + } + } + } + else + { + xrIn.Skip(); + } + break; + }//switch + }//if + }//while + + //build conversion templates + for (int j=0; j < alFieldNames.Count; j++) + { + sFieldName = alFieldNames[j].ToString(); + xwOut.WriteStartElement("xsl", "template", null); + xwOut.WriteAttributeString("match", sFieldName); + + xwOut.WriteStartElement("xsl", "element", null); + xwOut.WriteAttributeString("name", sFieldName); + + xwOut.WriteStartElement("xsl", "value-of", null); + xwOut.WriteAttributeString("select", "bmx:ExcelDate(.)"); + + xwOut.WriteEndElement(); //value-of + xwOut.WriteFullEndElement(); //element + xwOut.WriteFullEndElement(); //template + } + + xwOut.WriteFullEndElement(); //stylesheet + xwOut.Close(); + } + + /* + * Controls Demo + * Demonstrates how to populate controls from a datatable + */ + private void cmdCDLoad_Click(object sender, System.EventArgs e) + { + try + { + if (m_ci.Connected == false) + { + throw new BMXNetException("Not connected to RPMS."); + } + + string sCommandText = "BMX ADO SS^PATIENT DEMOGRAPHICS^^~1~50~"; + DataTable dt = m_ci.RPMSDataTable(sCommandText, "ControlsDemo"); + + txtCDName.DataBindings.Clear(); + txtCDSex.DataBindings.Clear(); + txtCDDOB.DataBindings.Clear(); + txtCDSSN.DataBindings.Clear(); + calCDDOB.DataBindings.Clear(); + dtpCDDOB.DataBindings.Clear(); + lstCDSex.DataBindings.Clear(); + + DataView dvCDPat = new DataView(dt); + dvCDPat.Sort = "NAME ASC"; + + cboCDSelect.DataSource = dvCDPat; + cboCDSelect.DisplayMember = "NAME"; + cboCDSelect.ValueMember = "BMXIEN"; + + txtCDName.DataBindings.Add("Text", dvCDPat, "NAME"); + txtCDSex.DataBindings.Add("Text", dvCDPat, "SEX"); + txtCDDOB.DataBindings.Add("Text", dvCDPat, "DOB"); + txtCDSSN.DataBindings.Add("Text", dvCDPat, "SSN"); + + calCDDOB.DataBindings.Add("SelectionStart", dvCDPat, "DOB"); + calCDDOB.DataBindings.Add("SelectionEnd", dvCDPat, "DOB"); + + dtpCDDOB.DataBindings.Add("Value", dvCDPat, "DOB"); + + lstCDSex.DataBindings.Add("SelectedItem", dvCDPat, "SEX"); + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return; + } + } + + private void cmdAddAll_Click(object sender, System.EventArgs e) + { + /* + * How to Accept Updates to an updateable recordset + * using the new schema format and the data adapter's Update method + */ + + try + { + DataTable dtPrimary = (DataTable) dataGrid2.DataSource; + DataSet ds = dtPrimary.DataSet; + + + + foreach (DataTable dt in ds.Tables) + { + + BMXNetConnection conn = new BMXNetConnection(m_ci.bmxNetLib); + + object[] oVal = new object[dt.Columns.Count]; + //Call adapter's Update method + int nRowCount = dt.Rows.Count; + for (int j=0; j < nRowCount; j++ ) + { + DataRow r = dt.Rows[j]; + for (int k = 0; k < dt.Columns.Count; k++) + { + oVal[k] = r[dt.Columns[k].ColumnName]; + } + DataRow rAdd = dt.Rows.Add(oVal); + } + + DataTable dtc = dt.GetChanges(); + if (dtc != null) + { + DataTable dtSchema = m_da.FillSchema(dtc, SchemaType.Source); + + //Build UPDATE command based on info stored in table's extended property set + BMXNetCommand bmxUpdateCmd = new BMXNetCommand(); + bmxUpdateCmd.Connection = conn; + + //Call BMXBuildUpdateCommand(dtSchema) to set up parameters + bmxUpdateCmd.BMXBuildUpdateCommand(dtSchema); + + //Link command to data adapter + m_da.UpdateCommand = bmxUpdateCmd; + + //Call adapter's Update method + m_da.Update(dtc); + + //Accept the changes to the datagrid's datatable + dt.RejectChanges(); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + #region Event Handling and Asynchronous Calls + + private string m_sTask; + private void cmdAsyncCall_Click(object sender, System.EventArgs e) + { + try + { + //Use the windows handle to create a unique event name + Process pCurrent = Process.GetCurrentProcess(); + string sID = Environment.MachineName + "-"; + sID += pCurrent.Id.ToString(); + m_ci.SubscribeEvent("BMX ASYNC RESULT READY" + sID ); // this.Handle.ToString()); + //nTask corresponds to TaskMan's ZTSK + int nTask = m_ci.RPMSDataTableAsyncQue(this.txtAsyncCommand.Text, "BMX ASYNC RESULT READY" + sID) ;//this.Handle.ToString()); + //Save ZTSK for later comparison + m_sTask = nTask.ToString(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void BMXNetEventHandler(Object obj, BMXNet.BMXNetEventArgs e) + { + try + { + //BMXNet events arrive on a separate thread from the UI thread, + //thus UI methods should be called using BeginInvoke or Invoke + UpdateEventMessageTextDelegate dlgUEMT = new UpdateEventMessageTextDelegate(UpdateEventMessageText); + this.Invoke(dlgUEMT, new object[] {e.BMXEvent, e.BMXParam}); + + Process pCurrent = Process.GetCurrentProcess(); + string sID = Environment.MachineName + "-"; + sID += pCurrent.Id.ToString(); + if (e.BMXEvent == "BMX ASYNC RESULT READY" + sID) + { + string sTask = BMXNetLib.Piece(e.BMXParam, "~", 1); + string sAsyncInfo = BMXNetLib.Piece(e.BMXParam,"~",2); + DataTable dtAsyncGrid = m_ci.RPMSDataTableAsyncGet(sAsyncInfo, "AsyncData"); + UpdateAsyncGridDelegate uagd = new UpdateAsyncGridDelegate(UpdateAsyncGrid); + this.BeginInvoke(uagd, new object[] {sTask, dtAsyncGrid}); + } + } + catch (Exception ex) + { + Debug.Write("BMXNetEventHandler exception: " + ex.Message + "\n"); + } + } + + delegate void UpdateAsyncGridDelegate(string sTask, DataTable dt); + private void UpdateAsyncGrid(string sTask, DataTable dt) + { + try + { + //Assert that invoke is not required in any UI method that may be called + //by a worker thread (e.g. from an event) + Debug.Assert(this.InvokeRequired == false); + + //Check that this is the same job that we tasked + if (m_sTask != sTask) + return; + + grdAsyncResult.DataSource = dt; + m_ci.UnSubscribeEvent("BMX ASYNC RESULT READY" + this.Handle.ToString()); + } + catch (Exception ex) + { + Debug.Write("UpdateAsyncGrid exception: " + ex.Message + "\n"); + } + } + + delegate void UpdateEventMessageTextDelegate(string EventName, string Param); + + private void UpdateEventMessageText(string EventName, string Param) + { + Debug.Assert(this.InvokeRequired == false); + txtEventMessages.Text = "BMXNet event " + EventName + " fired with parameter " + Param; + if (txtEventMessages.BackColor == System.Drawing.Color.LightGreen) + { + txtEventMessages.BackColor = System.Drawing.Color.LightCoral; + } + else + { + txtEventMessages.BackColor = System.Drawing.Color.LightGreen; + } + } + + private void cmdRegisterEvent_Click(object sender, System.EventArgs e) + { + m_ci.SubscribeEvent(this.txtRegisterEvent.Text); + } + + private void cmdUnregisterEvent_Click(object sender, System.EventArgs e) + { + m_ci.UnSubscribeEvent(this.txtUnregisterEvent.Text); + } + + private void cmdRaiseEvent_Click(object sender, System.EventArgs e) + { + m_ci.RaiseEvent(this.txtRaiseEvent.Text, txtEventParam.Text, chkEventRaiseBack.Checked); + } + + private void cmdAcquireLock_Click(object sender, System.EventArgs e) + { + try + { + m_ci.bmxNetLib.BMXRWL.AcquireWriterLock(5); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void cmdReleaseLock_Click(object sender, System.EventArgs e) + { + try + { + m_ci.bmxNetLib.BMXRWL.ReleaseWriterLock(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void chkEnableEvents_CheckedChanged(object sender, System.EventArgs e) + { + m_ci.EventPollingInterval = Convert.ToInt16(nudEventPollingInterval.Value); + m_ci.EventPollingEnabled = chkEnableEvents.Checked; + } + + private void nudEventPollingInterval_ValueChanged(object sender, System.EventArgs e) + { + m_ci.EventPollingInterval = Convert.ToInt16(nudEventPollingInterval.Value); + } + + #endregion Event Handling + + private void cmdTestSilent_Click(object sender, EventArgs e) + { + try + { + this.m_ci.CloseConnection(); + + string sA = ""; + string sV = ""; + string sAddress = ""; + int nPort = 10501; + string sN = ""; + + m_ci.LoadConnectInfo(sAddress, nPort, sA, sV, sN); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + + } + + private void cmdTestReceiveTimeout_Click(object sender, EventArgs e) + { + int nTest = 5000; + this.m_ci.ReceiveTimeout = nTest; + } + + private void cmdStartLogging_Click(object sender, EventArgs e) + { + try + { + m_ci.bmxNetLib.StartLog(); + } + catch (Exception ex) + { + MessageBox.Show("Unable to start logging: " + ex.Message); + } + } + + private void cmdStopLogging_Click(object sender, EventArgs e) + { + try + { + m_ci.bmxNetLib.StopLog(); + } + catch (Exception ex) + { + MessageBox.Show("Unable to stop logging: " + ex.Message); + } + } + + + + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/frmBMXNetTest.resx b/cs/bmx_0200scr/BMX2/BMXNetTest/frmBMXNetTest.resx new file mode 100644 index 0000000..ff31a6d --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/frmBMXNetTest.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/frmVisitDemo.cs b/cs/bmx_0200scr/BMX2/BMXNetTest/frmVisitDemo.cs new file mode 100644 index 0000000..f598096 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/frmVisitDemo.cs @@ -0,0 +1,269 @@ +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using System.Data; + +namespace IndianHealthService.BMXNet +{ + /// + /// Summary description for frmVisitDemo. + /// + public class frmVisitDemo : System.Windows.Forms.Form + { + private System.Windows.Forms.TextBox txtPatName; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button cmdViewVisitInfo; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.DataGrid dataGrid1; + + private System.ComponentModel.Container components = null; + + public frmVisitDemo() + { + InitializeComponent(); + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(components != null) + { + components.Dispose(); + } + } + base.Dispose( disposing ); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.txtPatName = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.cmdViewVisitInfo = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.dataGrid1 = new System.Windows.Forms.DataGrid(); + this.panel1.SuspendLayout(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); + this.SuspendLayout(); + // + // txtPatName + // + this.txtPatName.Location = new System.Drawing.Point(120, 24); + this.txtPatName.Name = "txtPatName"; + this.txtPatName.Size = new System.Drawing.Size(152, 20); + this.txtPatName.TabIndex = 0; + this.txtPatName.Text = "W"; + // + // label1 + // + this.label1.Location = new System.Drawing.Point(16, 16); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(104, 24); + this.label1.TabIndex = 1; + this.label1.Text = "First few characters of patient name:"; + // + // cmdViewVisitInfo + // + this.cmdViewVisitInfo.Location = new System.Drawing.Point(304, 24); + this.cmdViewVisitInfo.Name = "cmdViewVisitInfo"; + this.cmdViewVisitInfo.Size = new System.Drawing.Size(112, 24); + this.cmdViewVisitInfo.TabIndex = 2; + this.cmdViewVisitInfo.Text = "View Patient Visits"; + this.cmdViewVisitInfo.Click += new System.EventHandler(this.cmdViewVisitInfo_Click); + // + // panel1 + // + this.panel1.Controls.Add(this.cmdViewVisitInfo); + this.panel1.Controls.Add(this.txtPatName); + this.panel1.Controls.Add(this.label1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(584, 72); + this.panel1.TabIndex = 3; + // + // panel2 + // + this.panel2.Controls.Add(this.dataGrid1); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 72); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(584, 246); + this.panel2.TabIndex = 4; + // + // dataGrid1 + // + this.dataGrid1.AccessibleName = "DataGrid"; + this.dataGrid1.AccessibleRole = System.Windows.Forms.AccessibleRole.Table; + this.dataGrid1.DataMember = ""; + this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; + this.dataGrid1.Location = new System.Drawing.Point(0, 0); + this.dataGrid1.Name = "dataGrid1"; + this.dataGrid1.Size = new System.Drawing.Size(584, 246); + this.dataGrid1.TabIndex = 0; + // + // frmVisitDemo + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(584, 318); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.Name = "frmVisitDemo"; + this.Text = "frmVisitDemo"; + this.panel1.ResumeLayout(false); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + + #region Fields + BMXNetConnectInfo m_ci; + #endregion Fields + + + public void InitializePage(BMXNetConnectInfo ci) + { + m_ci = ci; + CreateGridStyles(); + } + + private void cmdViewVisitInfo_Click(object sender, System.EventArgs e) + { + if (m_ci.Connected == false) + { + MessageBox.Show("Must connect to RPMS first"); + return; + } + try + { + //Declare new dataset and connection variables + DataSet m_dsGlobal = new DataSet("Global"); + + //Retrieve RPMS Records from PATIENT file + string sCmd = "SELECT BMXIEN DFN, NAME, AGE, SEX, DOB FROM PATIENT WHERE NAME LIKE '" + txtPatName.Text + "%'"; + m_ci.RPMSDataTable(sCmd, "Patient", m_dsGlobal); + + //Build Primary Key for Patient table + DataTable dtGroups = m_dsGlobal.Tables["Patient"]; + DataColumn dcKey = dtGroups.Columns["DFN"]; + DataColumn[] dcKeys = new DataColumn[1]; + dcKeys[0] = dcKey; + dtGroups.PrimaryKey = dcKeys; + + //Retrieve RPMS Records from VISIT file + sCmd = @"SELECT INTERNAL[PATIENT_NAME] PDFN, BMXIEN VDFN, VISIT/ADMIT_DATE&TIME, CLINIC, LOC._OF_ENCOUNTER FROM VISIT WHERE PATIENT_NAME LIKE '" + txtPatName.Text + "%'"; + m_ci.RPMSDataTable(sCmd, "Visit", m_dsGlobal); + + //Build Primary Key for Visit table + DataTable dtAGTypes = m_dsGlobal.Tables["Visit"]; + DataColumn dcGTKey = dtAGTypes.Columns["VDFN"]; + DataColumn[] dcGTKeys = new DataColumn[1]; + dcGTKeys[0] = dcGTKey; + dtAGTypes.PrimaryKey = dcGTKeys; + + //Build Data Relationship between Patient and Visit tables + DataRelation dr = new DataRelation("PatientVisit", //Relation Name + m_dsGlobal.Tables["Patient"].Columns["DFN"], //Parent + m_dsGlobal.Tables["Visit"].Columns["PDFN"]); //Child + m_dsGlobal.Relations.Add(dr); + + this.dataGrid1.DataSource = m_dsGlobal.Tables["Patient"]; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "BMXNetTest Error"); + } + } + + private void CreateGridStyles() + { + //Create DataGridTableStyle for Patient table + DataGridTableStyle tsRU = new DataGridTableStyle(); + tsRU.MappingName = "Patient"; + tsRU.ReadOnly = true; + + // Add DFN column style. + DataGridColumnStyle colDFN = new DataGridTextBoxColumn(); + colDFN.MappingName = "DFN"; + colDFN.HeaderText = "DFN"; + colDFN.Width = 0; + tsRU.GridColumnStyles.Add(colDFN); + + // Add NAME column style. + DataGridColumnStyle colRUID = new DataGridTextBoxColumn(); + colRUID.MappingName = "NAME"; + colRUID.HeaderText = "Patient Name"; + colRUID.Width = 250; + tsRU.GridColumnStyles.Add(colRUID); + + // Add AGE column style. + DataGridColumnStyle colRUserID = new DataGridTextBoxColumn(); + colRUserID.MappingName = "AGE"; + colRUserID.HeaderText = "Age"; + colRUserID.Width = 50; + tsRU.GridColumnStyles.Add(colRUserID); + + // Add SEX column style. + DataGridColumnStyle colSex = new DataGridTextBoxColumn(); + colSex.MappingName = "SEX"; + colSex.HeaderText = "Sex"; + colSex.Width = 50; + tsRU.GridColumnStyles.Add(colSex); + + // Add DOB column style. + DataGridColumnStyle colDOB = new DataGridTextBoxColumn(); + colDOB.MappingName = "DOB"; + colDOB.HeaderText = "Date of Birth"; + colDOB.Width = 100; + tsRU.GridColumnStyles.Add(colDOB); + + this.dataGrid1.TableStyles.Add(tsRU); + + //Create DataGridTableStyle for Visit table + DataGridTableStyle tsVisit = new DataGridTableStyle(); + tsVisit.MappingName = "Visit"; + tsVisit.ReadOnly = true; + + // Add VISIT/ADMIT_DATE&TIME column style + DataGridColumnStyle colVDate = new DataGridTextBoxColumn(); + colVDate.MappingName = "VISIT/ADMIT_DATE&TIME"; + colVDate.HeaderText = "Visit Date & Time"; + colVDate.Width = 150; + tsVisit.GridColumnStyles.Add(colVDate); + + // Add LOC._OF_ENCOUNTER column style + DataGridColumnStyle colLocation = new DataGridTextBoxColumn(); + colLocation.MappingName = "LOC._OF_ENCOUNTER"; + colLocation.HeaderText = "Location of Encounter"; + colLocation.Width = 200; + tsVisit.GridColumnStyles.Add(colLocation); + + // Add CLINIC column style + DataGridColumnStyle colClinic = new DataGridTextBoxColumn(); + colClinic.MappingName = "CLINIC"; + colClinic.HeaderText = "Clinic"; + colClinic.Width = 100; + tsVisit.GridColumnStyles.Add(colClinic); + + this.dataGrid1.TableStyles.Add(tsVisit); + + } + + } +} diff --git a/cs/bmx_0200scr/BMX2/BMXNetTest/frmVisitDemo.resx b/cs/bmx_0200scr/BMX2/BMXNetTest/frmVisitDemo.resx new file mode 100644 index 0000000..6b0e402 --- /dev/null +++ b/cs/bmx_0200scr/BMX2/BMXNetTest/frmVisitDemo.resx @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Private + + + False + + + Private + + + False + + + Private + + + Private + + + False + + + Private + + + Private + + + False + + + True + + + Private + + + 8, 8 + + + True + + + Private + + + False + + + True + + + Private + + + 8, 8 + + + True + + + Private + + + False + + + Private + + + Private + + + False + + + (Default) + + + False + + + False + + + 8, 8 + + + True + + + 80 + + + True + + + frmVisitDemo + + + Private + + \ No newline at end of file diff --git a/cs/bmx_0200scr/BMXNetLib.cs b/cs/bmx_0200scr/BMXNetLib.cs new file mode 100644 index 0000000..b8bd10f --- /dev/null +++ b/cs/bmx_0200scr/BMXNetLib.cs @@ -0,0 +1,1312 @@ +using System; +using System.Diagnostics; +using System.Text; +using System.IO; +using System.Net.Sockets; +using System.Net; +using System.Security.Cryptography; +using System.Security.Permissions; +using System.Security.Principal; +using System.Threading; +using System.Timers; + +namespace IndianHealthService.BMXNet +{ + /// + /// BMXNetLib implements low-level socket connectivity to RPMS databases. + /// The VA RPC Broker must be running on the RPMS server in order for + /// BMXNetLib to connect. + /// + [DnsPermission(SecurityAction.Assert, Unrestricted = true)] + public class BMXNetLib + { + public BMXNetLib() + { + m_sWKID = "BMX"; + m_sWINH = ""; + m_sPRCH = ""; + m_sWISH = ""; + m_cHDR = ADEBHDR(m_sWKID,m_sWINH,m_sPRCH,m_sWISH); + + } + + #region Piece Functions + + /// + /// Corresponds to M's $L(STRING,DELIMITER) + /// + /// + /// + /// + public static int PieceLength(string sInput, string sDelim) + { + char[] cDelim = sDelim.ToCharArray(); + string [] cSplit = sInput.Split(cDelim); + return cSplit.GetLength(0); + } + + /// + /// Corresponds to M's $$Piece function + /// + /// + /// + /// + /// + public static string Piece(string sInput, string sDelim, int nNumber) + { + try + { + char[] cDelim = sDelim.ToCharArray(); + string [] cSplit = sInput.Split(cDelim); + int nLength = cSplit.GetLength(0); + if ((nLength < nNumber)||(nNumber < 1)) + return ""; + return cSplit[nNumber-1]; + } + catch (Exception bmxEx) + { + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + } + + } + + public static string Piece(string sInput, string sDelim, int nNumber, int nEnd) + { + try + { + if (nNumber < 0) + nNumber = 1; + + if (nEnd < nNumber) + return ""; + + if (nEnd == nNumber) + return Piece(sInput, sDelim, nNumber); + + char[] cDelim = sDelim.ToCharArray(); + string [] cSplit = sInput.Split(cDelim); + int nLength = cSplit.GetLength(0); + if ((nLength < nNumber)||(nNumber < 1)) + return ""; + + //nNumber = 1-based index of the starting element to return + //nLength = count of elements + //nEnd = 1-based index of last element to return + //nCount = number of elements past nNumber to return + + //convert nNumber to 0-based index: + nNumber--; + + //convert nEnd to 0-based index; + nEnd--; + + //Calculate nCount; + int nCount = nEnd - nNumber + 1; + + //Adjust nCount for number of elements + if (nCount + nNumber >= nLength) + { + nCount = nLength - nNumber; + } + + string sRet = string.Join(sDelim, cSplit, nNumber, nCount ); + return sRet; + } + catch (Exception bmxEx) + { + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + } + } + + #endregion Piece Functions + + #region RPX Fields + + private string m_sWKID; + private string m_sWISH; + private string m_sPRCH; + private string m_sWINH; + private string m_cHDR; + private string m_cAppContext; + private bool m_bConnected; + private int m_nMServerPort; + private string m_cServerAddress; + private string m_cDUZ; + private string m_cLoginFacility; + private TcpClient m_pCommSocket; + private string m_sNameSpace = ""; + private int m_nReceiveTimeout = 30000; + + #endregion RPX Fields + + #region Encryption Keys + private string[] m_sKey = new string[] + { + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + @"MUST PROVIDE A VALID KEY", + }; + #endregion Encryption Keys + + #region RPX Functions + + /// + /// Given strInput = "13" builds "013" if nLength = 3. Default for nLength is 3. + /// + /// + /// + private string ADEBLDPadString(string strInput) + { + return ADEBLDPadString(strInput, 3); + } + + /// + /// Given strInput = "13" builds "013" if nLength = 3 Default for nLength is 3. + /// + /// + /// Default = 3 + /// + private string ADEBLDPadString(string strInput, int nLength /*=3*/) + { + return strInput.PadLeft(nLength, '0'); + } + + /// + /// Concatenates zero-padded length of sInput to sInput + /// Given "Hello" returns "004Hello" + /// If nSize = 5, returns "00004Hello" + /// Default for nSize is 3. + /// + /// + /// + private string ADEBLDB(string sInput) + { + return ADEBLDB(sInput, 3); + } + + /// + /// Concatenates zero-padded length of sInput to sInput + /// Given "Hello" returns "004Hello" + /// If nSize = 5, returns "00004Hello" + /// Default for nSize is 3. + /// + /// + /// + /// + private string ADEBLDB(string sInput, int nSize /*=3*/) + { + int nLen = sInput.Length; + string sLen = this.ADEBLDPadString(nLen.ToString(), nSize); + return sLen + sInput; + } + + /// + /// Build protocol header + /// + /// + /// + /// + /// + /// + private string ADEBHDR(string sWKID, string sWINH, string sPRCH, string sWISH) + { + string strResult; + strResult = sWKID+";"+sWINH+";"+sPRCH+";"+sWISH+";"; + strResult = ADEBLDB(strResult); + return strResult; + } + private string ADEBLDMsg(string cHDR, string cRPC, string cParam) + { + string sMult = ""; + return ADEBLDMsg(cHDR, cRPC, cParam, ref sMult); + } + private string ADEBLDMsg(string cHDR, string cRPC, string cParam, ref string cMult) + { + //Builds RPC message + //Automatically splits parameters longer than 200 into subscripted array + string cMSG; + string sBuild = ""; + string sPiece = ""; + string sBig = ""; + int l; + int nLength; + + if (cParam == "") + { + cMSG = "0" + cRPC ; + } + else + { + l = PieceLength(cParam, "^"); + for (int j=1; j <= l; j++) + { + sPiece = Piece(cParam, "^", j); + if ((j == l) && (sPiece.Length > 200)) + { + //Split up long param into array pieces + sBig = sPiece; + sPiece = ".x"; + nLength = sPiece.Length + 1; + sPiece = ADEBLDPadString(nLength.ToString()) + "2" + sPiece; + sBuild = sBuild + sPiece; + int nSubscript = 1; + string sSubscript =""; + int nSubLen = 0; + string sSubLen =""; + int nBigLen = sBig.Length; + string sHunk =""; + int nHunkLen = 0; + string sHunkLen =""; + int nChunk = 0; + do + { + nChunk = (sBig.Length > 200)?200:sBig.Length ; + sHunk = sBig.Substring(0, nChunk); + sBig = sBig.Remove(0, nChunk); + nBigLen = sBig.Length; + sSubscript = nSubscript.ToString(); + nSubLen = sSubscript.Length; + sSubLen = nSubLen.ToString(); + sSubLen = ADEBLDPadString(sSubLen); + nHunkLen = sHunk.Length; + sHunkLen = nHunkLen.ToString(); + sHunkLen = ADEBLDPadString(sHunkLen); + cMult = cMult + sSubLen + sSubscript + sHunkLen + sHunk; + nSubscript++; + } while (nBigLen > 0); + } + else + { + nLength = sPiece.Length +1; + sPiece = ADEBLDPadString(nLength.ToString()) + "0" + sPiece; + sBuild = sBuild + sPiece; + } + } + nLength = sBuild.Length; + string sTotLen = ADEBLDPadString(nLength.ToString(),5); + if (cMult.Length > 0) + { + cMSG = "1"+ cRPC + "^" +sTotLen + sBuild; + } + else + { + cMSG = "0"+ cRPC + "^" +sTotLen + sBuild; + } + } + cMSG = ADEBLDB(cMSG, 5); + cMSG = cHDR + cMSG; + return cMSG; + } + + internal string ADEEncryp(string sInput) + { + //Encrypt a string + string strResult; + string strPercent; + string strAssoc; + string strIdix; + int nPercent; + int nAssocix; + int nIdix; + Debug.Assert(sInput != ""); + System.Random rRand = new Random(DateTime.Now.Second); + + nPercent = rRand.Next(0,10000); + nPercent += 72439; + nAssocix = nPercent % 20; + nAssocix++; + Debug.Assert(nAssocix < 21); + strPercent = nPercent.ToString(); + strPercent = strPercent.Substring(1,2); + nIdix = Convert.ToInt32(strPercent); + nIdix = nIdix % 20; + nIdix++; + Debug.Assert(nIdix < 21); + + const int nEncryptBase = 101; + strAssoc = LoadKey(nEncryptBase + nAssocix); + Debug.Assert(strAssoc.Length == 94); + strIdix = LoadKey(nEncryptBase + nIdix); + Debug.Assert(strIdix.Length == 94); + string sEncrypted = ""; + + foreach (char c in sInput) + { + string d = c.ToString(); + int nFindChar = strIdix.IndexOf(c); + if (nFindChar > -1) + { + d = strAssoc.Substring(nFindChar,1); + } + sEncrypted += d; + } + + strResult = (char) (nIdix + 31) + sEncrypted + (char) (nAssocix + 31); + + return strResult; + } + + internal string ADEDecryp(string sInput) + { + //Encrypt a string + string strAssoc; + string strIdix; + int nAssocix; + int nIdix; + Debug.Assert(sInput != ""); + + //get associator string index + char cAssocix = sInput[sInput.Length-1]; + nAssocix =(int) cAssocix; + nAssocix -= 31; + Debug.Assert(nAssocix < 21); + + //get identifier string index + char cIdix = sInput[0]; + nIdix = (int) cIdix; + nIdix -= 31; + Debug.Assert(nIdix < 21); + + //get associator string + const int nEncryptBase = 101; + strAssoc = LoadKey(nEncryptBase + nAssocix); + Debug.Assert(strAssoc.Length == 94); + + //get identifier string + strIdix = LoadKey(nEncryptBase + nIdix); + Debug.Assert(strIdix.Length == 94); + + //translated result + string sDecrypted = ""; + sInput = sInput.Substring(1, sInput.Length - 2); + foreach (char c in sInput) + { + string d = c.ToString(); + int nFindChar = strAssoc.IndexOf(c); + if (nFindChar > -1) + { + d = strIdix.Substring(nFindChar,1); + } + sDecrypted += d; + } + + return sDecrypted; + } + + internal string BMXEncrypt(string sInput) + { + + ASCIIEncoding textConverter = new ASCIIEncoding(); + RijndaelManaged myRijndael = new RijndaelManaged(); + byte[] encrypted; + byte[] toEncrypt; + byte[] key; + byte[] IV; + + string sKey="pouphfoz sfdbqjuvmbwft qizmphfoz"; + string sIV = "Gichin Funakoshi"; + key = textConverter.GetBytes(sKey); + IV = textConverter.GetBytes(sIV); + + //Get an encryptor. + ICryptoTransform encryptor = myRijndael.CreateEncryptor(key, IV); + + //Encrypt the data. + MemoryStream msEncrypt = new MemoryStream(); + CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); + + //Convert the input data to a byte array. + toEncrypt = textConverter.GetBytes(sInput); + + //Write all data to the crypto stream and flush it. + csEncrypt.Write(toEncrypt, 0, toEncrypt.Length); + csEncrypt.FlushFinalBlock(); + + //Get encrypted array of bytes. + encrypted = msEncrypt.ToArray(); + + //Convert to string to send to RPMS + string sEncrypted = "" ; + byte bTmp; + string sTmp; + for (int j =0; j < encrypted.Length; j++) + { + bTmp = encrypted[j]; + sTmp = bTmp.ToString(); + sEncrypted += sTmp; + if (j < (encrypted.Length -1)) + sEncrypted += "~"; + } + return sEncrypted; + } + + internal string BMXDecrypt(string sInput) + { + try + { + byte[] fromEncrypt; + ASCIIEncoding textConverter = new ASCIIEncoding(); + RijndaelManaged myRijndael = new RijndaelManaged(); + string sRPMSEncrypted = sInput; + string sBar = "~"; + char[] cBar = sBar.ToCharArray(); + string[] sArray; + sArray = sRPMSEncrypted.Split(cBar); + byte[] bRPMSEncrypted = new byte[sArray.GetLength(0)]; + byte[] key; + byte[] IV; + + //Convert the RPMS-stored string to a byte array + for (int j = 0; j < sArray.GetLength(0); j++) + { + bRPMSEncrypted[j] = Byte.Parse(sArray[j]); + } + + //Get a decryptor that uses the same key and IV as the encryptor. + string sKey="pouphfoz sfdbqjuvmbwft qizmphfoz"; + string sIV = "Gichin Funakoshi"; + key = textConverter.GetBytes(sKey); + IV = textConverter.GetBytes(sIV); + ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV); + + MemoryStream msDecrypt = new MemoryStream(bRPMSEncrypted); + CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); + + fromEncrypt = new byte[bRPMSEncrypted.Length - 2]; + + //Read the data out of the crypto stream. + csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length); + + int nZ = FindChar(fromEncrypt, (char) 0); + + //Convert the byte array back into a string. + string sResult; + if (nZ < 0) + { + sResult = textConverter.GetString(fromEncrypt); + } + else + { + sResult = textConverter.GetString(fromEncrypt, 0, nZ); + } + return sResult; + } + catch (Exception ex) + { + Debug.Write(ex.Message); + return ""; + } + } + + public static int FindChar(byte[] c, char y) + { + int n = 0; + int nRet = -1; + for (n=0; n < c.Length; n++) + { + if (y == (char) c[n]) + { + nRet = n; + break; + } + } + + return nRet; + } + + public static int FindChar(string s, char y) + { + int n = 0; + int nRet = -1; + foreach (char c in s) + { + if (y == c) + { + nRet = n; + break; + } + n++; + } + return nRet; + } + + + /// + /// Returns index of first instance of sSubString in sString. + /// If sSubString not found, returns -1. + /// + /// + /// + /// + public static int FindSubString(string sString, string sSubString) + { + int nFound = -1; + int nLimit = sString.Length - sSubString.Length + 1; + if (nLimit < 0) + return -1; + + int nSubLength = sSubString.Length; + for (int j=0; j < nLimit; j++) + { + if (sString.Substring(j, nSubLength) == sSubString) + { + nFound = j; + break; + } + } + return nFound; + } + + private string LoadKey(int nID) + { + nID -= 102; + Debug.Assert( nID < 20); + return m_sKey[nID]; + } + + private void OpenConnectionCommon(string sServerAddress) + { + try + { + m_cServerAddress = sServerAddress; + + //Connect with the server + TcpClient connector = new TcpClient(); + + try + { + connector = new TcpClient(); + connector.Connect(m_cServerAddress, m_nMServerPort); + } + catch (SocketException exSocket) + { + string s = exSocket.Message + exSocket.StackTrace; + throw new BMXNetException(s); + } + + //Prepare & send the connect message + string cSend = "TCPconnect^" + m_sNameSpace + "^^"; + int nLen = cSend.Length; + string sLen = nLen.ToString(); + sLen = sLen.PadLeft(5, '0'); + cSend = "{BMX}" + sLen + cSend; + + NetworkStream ns = connector.GetStream(); + byte[] sendBytes = Encoding.ASCII.GetBytes(cSend); + ns.Write(sendBytes,0,sendBytes.Length); + + m_pCommSocket = connector; + return; + + } + catch (BMXNetException bmxEx) + { + throw bmxEx; + } + catch (Exception ex) + { + string s = ex.Message + ex.StackTrace; + throw new BMXNetException(s); + } + }//End OpenConnectionCommon + + [SocketPermissionAttribute(SecurityAction.Assert, + Access="Connect", + Host="All", + Port="All", + Transport="All")] + public bool OpenConnection(string sServerAddress, WindowsIdentity winIdentity) + { + try + { + OpenConnectionCommon(sServerAddress); + bool bSecurity; + try + { + bSecurity = SendSecurityRequest(winIdentity); + + } + catch (Exception ex) + { + //Close the connection + SendString(m_pCommSocket, "#BYE#"); + m_pCommSocket.Close(); + m_bConnected = false; + m_cServerAddress = ""; + throw ex; + } + + m_bConnected = bSecurity; + return m_bConnected; + } + catch (BMXNetException bmxEx) + { + throw bmxEx; + } + catch (Exception ex) + { + string s = ex.Message + ex.StackTrace; + throw new BMXNetException(s); + } + } + + StreamWriter m_LogWriter; + bool m_bLogging = false; + + public void StartLog() + { + try + { + if (m_bLogging) + { + throw new Exception("Already logging."); + } + string sFile = "BMXLog " + DateTime.Now.DayOfYear.ToString() + " " + + DateTime.Now.Hour.ToString() + " " + DateTime.Now.Minute.ToString() + + " " + DateTime.Now.Second.ToString() + ".log"; + StartLog(sFile); + return; + } + catch (Exception ex) + { + throw ex; + } + } + + public void StartLog(string LogFileName) + { + try + { + if (m_bLogging) + { + throw new Exception("Already logging."); + } + m_LogWriter = File.AppendText(LogFileName); + m_bLogging = true; + return; + } + catch (Exception ex) + { + throw ex; + } + } + + public void StopLog() + { + try + { + //Close the writer and underlying file. + if (m_bLogging == false) + { + return; + } + m_LogWriter.Close(); + m_bLogging = false; + return; + } + catch (Exception ex) + { + throw ex; + } + } + + private static void Log(String logMessage, TextWriter w) + { + w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), + DateTime.Now.ToLongDateString()); + w.WriteLine(" :"); + w.WriteLine(" :{0}", logMessage); + w.WriteLine("-------------------------------"); + // Update the underlying file. + w.Flush(); + } + + [SocketPermissionAttribute(SecurityAction.Assert, + Access="Connect", + Host="All", + Port="All", + Transport="All")] + public bool OpenConnection(string sServerAddress, string sAccess, string sVerify) + { + try + { + this.OpenConnectionCommon(sServerAddress); + + try + { + bool bSecurity = SendSecurityRequest(sAccess, sVerify); + } + catch (Exception ex) + { + //Close the connection + SendString(m_pCommSocket, "#BYE#"); + m_pCommSocket.Close(); + m_bConnected = false; + m_cServerAddress = ""; + throw ex; + } + + m_bConnected = true; + return m_bConnected; + } + catch (BMXNetException bmxEx) + { + throw bmxEx; + } + catch (Exception ex) + { + string s = ex.Message + ex.StackTrace; + throw new BMXNetException(s); + } + } + + private void SendString(TcpClient tcpClient, string cSendString) + { + string sMult = ""; + SendString(tcpClient, cSendString, sMult); + } + + private void SendString(TcpClient tcpClient, string cSendString, string cMult) + { + int nLen = cSendString.Length; + string sLen = nLen.ToString(); + sLen = sLen.PadLeft(5, '0'); + cSendString = sLen + cSendString; + + nLen += 15; + sLen = nLen.ToString(); + sLen = sLen.PadLeft(5, '0'); + + cSendString = "{BMX}" + sLen + cSendString; + cSendString = cSendString + cMult; + + NetworkStream ns = tcpClient.GetStream(); + byte[] sendBytes = Encoding.ASCII.GetBytes(cSendString); + ns.Write(sendBytes,0,sendBytes.Length); + if (this.m_bLogging == true) + { + Log("Sent: " + cSendString, this.m_LogWriter); + } + return; + } + + private string ReceiveString(TcpClient tcpClient) + { + NetworkStream ns = tcpClient.GetStream(); + + int nTimeOut = this.m_nReceiveTimeout; + int nCnt = 0; + int nTimeElapsed = 0; + while (ns.DataAvailable == false) + { + if (nCnt > 9999) + break; + if (nTimeElapsed > nTimeOut) + break; + nCnt++; + nTimeElapsed += 50; + Thread.Sleep(50); + } + + Debug.Assert(ns.DataAvailable == true); + if (ns.DataAvailable == false) + { + this.CloseConnection(); + throw new Exception("BMXNetLib.ReceiveString timeout. Connection Closed."); + //return ""; + } + + byte[] bReadBuffer = new byte[1024]; + string sReadBuffer = ""; + StringBuilder sbAll = new StringBuilder("", 1024); + int numberOfBytesRead = 0; + + // Incoming message may be larger than the buffer size. + + bool bFinished = false; + int nFind = -1; + bool bStarted = false; + int lpBuf = 0; + string sError = ""; + string sAppError = ""; + do + { + + numberOfBytesRead = ns.Read(bReadBuffer, 0, bReadBuffer.Length); + if ((numberOfBytesRead == 1)&&(bStarted == false)) + { + Thread.Sleep(15); + numberOfBytesRead += ns.Read(bReadBuffer,1, bReadBuffer.Length-1); + //Debug.Write("ReceiveString waiting for data...\n"); + } + if (bStarted == false) + { + //Process error info at beginning of returned string + int nErrLen = bReadBuffer[0]; + int nAppLen = bReadBuffer[bReadBuffer[0]+1]; + if ((bReadBuffer[2] == 0)&&(bReadBuffer[3] == 0)) + { //special case: M error trap invoked in SND^XWBTCPC + lpBuf += 2; + } + sError = Encoding.ASCII.GetString(bReadBuffer, lpBuf + 1, nErrLen); + if (sError != "") + { + throw new BMXNetException(sError); + } + sAppError = Encoding.ASCII.GetString(bReadBuffer, lpBuf+1+nErrLen+1, nAppLen); + lpBuf += (nErrLen + nAppLen + 2); + numberOfBytesRead -= (nErrLen + nAppLen + 2); + bStarted = true; + } + + nFind = FindChar(bReadBuffer, (char) 4); + if (nFind > -1) + bFinished = true; + Debug.Assert(numberOfBytesRead > -1); + sReadBuffer = Encoding.ASCII.GetString(bReadBuffer, lpBuf, numberOfBytesRead); + lpBuf = 0; + if (nFind > -1) + { + sbAll.Append(sReadBuffer, 0, numberOfBytesRead -1); + } + else + { + sbAll.Append(sReadBuffer); + } + } + while(bFinished == false); + if (this.m_bLogging == true) + { + Log("Received: " + sbAll.ToString(), this.m_LogWriter); + } + return sbAll.ToString(); + + } + private bool SendSecurityRequest(WindowsIdentity winIdentity) + { + string strReceive = ""; + string cMSG; + string sTest; + + //Build AV Call + cMSG = ADEBLDMsg(m_cHDR, "BMX AV CODE", winIdentity.Name); + SendString(m_pCommSocket, cMSG); + + strReceive = ReceiveString(m_pCommSocket); + sTest = strReceive.Substring(0,3); + + + char[] cDelim = {(char) 13,(char) 10,(char) 0}; + string sDelim = new string(cDelim); + int nPiece = 1; + m_cDUZ = Piece(strReceive, sDelim , nPiece); + if ((m_cDUZ == "0")||(m_cDUZ == "")) + { + nPiece = 7; + string sReason = Piece(strReceive, sDelim, nPiece); + throw new Exception(sReason); + } + + return true; + } + + private bool SendSecurityRequest(string sAccess, string sVerify) + { + string strReceive = ""; + string cMSG; + sAccess = sAccess.ToUpper(); + sVerify = sVerify.ToUpper(); + + //Build AV Call + string strAV = sAccess + ";" + sVerify; + strAV = ADEEncryp(strAV); + cMSG = ADEBLDMsg(m_cHDR, "XUS AV CODE", strAV); + SendString(m_pCommSocket, cMSG); + + strReceive = ReceiveString(m_pCommSocket); + + char[] cDelim = {(char) 13,(char) 10,(char) 0}; + string sDelim = new string(cDelim); + int nPiece = 1; + m_cDUZ = Piece(strReceive, sDelim , nPiece); + if ((m_cDUZ == "0")||(m_cDUZ == "")) + { + nPiece = 7; + string sReason = Piece(strReceive, sDelim, nPiece); + throw new Exception(sReason); + } + + return true; + } + + public void CloseConnection() + { + if (!m_bConnected) + { + return; + } + SendString(m_pCommSocket, "#BYE#"); + m_pCommSocket.Close(); + m_bConnected = false; + m_cServerAddress = ""; + // m_cDUZ2 = ""; + m_cDUZ = ""; + } + + public bool Lock(string Variable) + { + return Lock(Variable, "", ""); + } + + public bool Lock(string Variable, string Increment) + { + return Lock(Variable, Increment, ""); + } + + /// + /// Lock a local or global M variable + /// Returns true if lock is obtained during TimeOut seconds + /// Use + to increment, - to decrement lock. + /// + /// + /// + /// + /// + public bool Lock(string Variable, string Increment, string TimeOut) + { + try + { + string sContext = this.AppContext; + this.AppContext = "BMXRPC"; + Variable = Variable.Replace("^","~"); + string sRet = "0"; + bool bRet = false; + string sParam = Variable + "^" + Increment + "^" + TimeOut; + sRet = TransmitRPC("BMX LOCK", sParam); + bRet = (sRet == "1")?true:false; + this.AppContext = sContext; + return bRet; + } + catch (Exception ex) + { + string sMsg = ex.Message; + return false; + } + } + + static ReaderWriterLock m_rwl = new ReaderWriterLock(); + private int m_nRWLTimeout = 30000; //30-second default timeout + + /// + /// Returns a reference to the internal ReaderWriterLock member. + /// + public ReaderWriterLock BMXRWL + { + get + { + return m_rwl; + } + } + + /// + /// Sets and returns the timeout in milliseconds for locking the transmit port. + /// If the transmit port is unavailable an ApplicationException will be thrown. + /// + public int RWLTimeout + { + get + { + return m_nRWLTimeout; + } + set + { + m_nRWLTimeout = value; + } + } + + public string TransmitRPC(string sRPC, string sParam, int nLockTimeOut) + { + try + { + try + { + if (m_bConnected == false) + { + throw new BMXNetException("BMXNetLib.TransmitRPC failed because BMXNetLib is not connected to RPMS."); + } + Debug.Assert(m_cDUZ != ""); + Debug.Assert(m_pCommSocket != null); + + string sOldAppContext = ""; + if (sRPC.StartsWith("BMX")&&(this.m_cAppContext != "BMXRPC")) + { + sOldAppContext = this.m_cAppContext; + this.AppContext = "BMXRPC"; + } + string sMult = ""; + string sSend = ADEBLDMsg(m_cHDR, sRPC, sParam, ref sMult); + SendString(m_pCommSocket, sSend, sMult); + // Debug.Write("TransmitRPC Sent: " + sSend + "\n"); + string strResult = ReceiveString(m_pCommSocket); + // Debug.Write("TransmitRPC Received: " + strResult + "\n"); + + if (sOldAppContext != "") + { + this.AppContext = sOldAppContext; + } + return strResult; + } + catch (Exception ex) + { + if (ex.Message == "Unable to write data to the transport connection.") + { + m_bConnected = false; + } + throw ex; + } + finally + { + } + } + catch (ApplicationException aex) + { + // The writer lock request timed out. + Debug.Write("TransmitRPC writer lock request timed out.\n"); + throw aex; + } + catch (Exception OuterEx) + { + throw OuterEx; + } + } + + public string TransmitRPC(string sRPC, string sParam) + { + try + { + return TransmitRPC(sRPC, sParam, m_nRWLTimeout); + } + catch (ApplicationException aex) + { + throw aex; + } + catch (Exception ex) + { + throw ex; + } + } + + public string GetLoginFacility() + { + try + { + if (m_bConnected == false) + { + throw new BMXNetException("BMXNetLib is not connected to RPMS"); + } + + if (m_cLoginFacility != "") + { + return m_cLoginFacility; + } + + Debug.Assert(m_pCommSocket != null); + Debug.Assert(m_cDUZ != ""); + SendString(m_pCommSocket, ADEBLDMsg(m_cHDR, "BMXGetFac", m_cDUZ)); + string sFac = ReceiveString(m_pCommSocket); + m_cLoginFacility = sFac; + return sFac; + } + catch (BMXNetException bmxEx) + { + string sMessage = bmxEx.Message + bmxEx.StackTrace; + throw new BMXNetException(sMessage); + } + catch (Exception ex) + { + throw ex; + } + } + + #endregion RPX Functions + + #region RPX Properties + + /// + /// Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. + /// If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. + /// The default is 30 seconds. + /// + public int ReceiveTimeout + { + get { return m_nReceiveTimeout; } + set { m_nReceiveTimeout = value; } + } + + public string WKID + { + get + { + return m_sWKID; + } + set + { + m_sWKID = value; + } + } + + public string PRCH + { + get + { + return m_sPRCH; + } + set + { + m_sPRCH = value; + } + } + + public string WINH + { + get + { + return m_sWINH; + } + set + { + m_sWINH = value; + } + } + + public string WISH + { + get + { + return m_sWISH; + } + set + { + m_sWISH = value; + } + } + + /// + /// Gets/sets the Kernel Application context + /// Throws an exception if unable to set the context. + /// + public string AppContext + { + get + { + return m_cAppContext; + } + set + { + //Send the changed context to RPMS + if ((m_bConnected == true) && (value != "")) + { + try + { + string sRPC = ADEEncryp(value); + string sAuthentication = TransmitRPC("XWB CREATE CONTEXT", sRPC); + + if (BMXNetLib.FindSubString(sAuthentication, "does not have access to option") > -1) + { + throw new BMXNetException(sAuthentication); + } + + } + catch (Exception ex) + { + Debug.Write(ex.Message); + throw ex; + } + } + m_cAppContext = value; + } + } + + public bool Connected + { + get + { + return m_bConnected; + } + } + + public string DUZ + { + get + { + return m_cDUZ; + } + } + + public string MServerAddress + { + get + { + return m_cServerAddress; + } + } + + public string MServerNamespace + { + get + { + return m_sNameSpace; + } + set + { + m_sNameSpace = value; + } + } + + public int MServerPort + { + get + { + return m_nMServerPort; + } + set + { + m_nMServerPort = value; + } + } + + public string NameSpace + { + get + { + return m_sNameSpace; + } + set + { + m_sNameSpace = value; + } + } + + #endregion RPX Properties + + } +}