//**************************************************************************** // $Module type: Package // $Module name: CheckDSN package // $Author : Nils G. Svedmyr // Created : 2001-07-05 @ 11:27 // // Description : Checks for necessary ODBC DSN's Sources (Used with the ODBC driver) // // $Rev History // 2001-07-05 Module header created //**************************************************************************** Use ODBC_Drv.pkg // DAC standard package. Use Working.pkg // Working message (instead of using the sentinel) //**************************************************************************** // $Module type: CLASS // $Module name: oDSNArray // $Author : Nils G. Svedmyr // Created : 2001-08-03 @ 10:25 // // Description : To keep multiple ODBC DSN names. // // $Rev History // 2001-08-03 Module header created //**************************************************************************** Class cDSNArray is a Array Procedure Construct_Object Forward Send Construct_Object End_Procedure // Construct_Object // Takes a string with DSN names, each surrounded with a // double quote ("). Returns: Number of items. Function LoadDSNArray String sDSN Returns Integer Integer iPos1 iPos2 String sName Move (Trim(sDSN)) to sDSN Repeat Move (Pos('"', sDSN)) to iPos1 Move (Replace('"', sDSN, '')) to sDSN Move (Pos('"', sDSN)) to iPos2 Move (Replace('"', sDSN, '')) to sDSN Move (Mid(sDSN, (iPos2 - iPos1), iPos1)) to sName //Showln "sName = " sName " iPos1 = " iPos1 " iPos2 = " iPos2 " sDSN = " sDSN If (sName <> '') Set Array_Value item (Item_Count(Self)) to sName Until (Not (sDSN contains '"')) Function_Return (Item_Count(Self)) End_Function // LoadArray Procedure Dump Integer iCount iItems String sValue Get Item_Count to iItems Showln "DNS array object = " (Self) For iCount from 0 to (iItems -1) Get String_Value item iCount to sValue showln "DNS value = " sValue Loop // For iCount from 0 to (iItems -1) Showln "" End_Procedure // Dump Procedure End_Construct_Object Forward Send End_Construct_Object End_Procedure // End_Construct_Object End_Class // cDSNArray // Check that necessary DSN's has been setup prior start of application: // Input : DSN Name and Id of the programs Panel object. Procedure DoCheckDSNName Global String sDSN Handle hoPanel Integer iRetval iItems iCount Boolean bOk Handle hWnd hoArray String sName Get Create U_cDSNArray to hoArray If (Active_State(Self)) Send StartWorkingMessage "Checking ODBC Data Source Name's..." Get LoadDSNArray of hoArray sDSN to iItems //Send Dump of hoArray For iCount from 1 to iItems Get String_Value of hoArray item (iCount - 1) to sName Get CheckDSNName sName to bOk If Not bOk Break Loop // For iCount from 1 to iItems Send StopWorkingMessage Send Destroy of hoArray If Not bOk Begin If (iItems = 1) Move ("You need to have a ODBC Data Source Name named" * String(sDsn) * "on your computer to be able to run this program. Do you want to create it now with Windows ODBC Administrator?\n\n Note: If you press 'No' this program will be aborted.") to sName Else Move ("You need to have ODBC Data Source Name's named" * String(sDsn) * "on your computer to be able to run this program. Do you want to create them now with Windows ODBC Administrator?\n\n Note: If you press 'No' this program will be aborted.") to sName Get YesNo_Box sName "Control Panel - ODBC Sources" to iRetval If (iRetval = MBR_NO) Abort Get Window_Handle of hoPanel to hWnd ODBCManager hWnd End // If Not (bOk1 and bOk2) Begin End_Procedure // DoCheckDSNName // Helper function for DoCheckDSNName // Returns: True if success // False if fail Function CheckDSNName Global String sDefaultDSN Returns Boolean Integer iCount iNumDSN Boolean bState String sDSNName ODBCEnumerateDataSources iNumDSN For iCount From 1 to iNumDSN ODBCDSNName iCount to sDSNName If (Uppercase(sDSNName) contains Uppercase(sDefaultDSN)) Move (True) to bState Loop // For iCount From 1 to iNumDSN Function_Return bState End_Function // CheckDSNName