ViewMainDialog

xiaoxiao2021-03-06  37

ViewMainDialog

//MAINDIALOG.CPP: IMPLEMENTATION OF CMAINDIALOG

// this Will Fill A Tree Control Like this: //2ame // Memname // Variablename // Memname // ... # include "stdafx.h" #include "maindialog.h"

// ATLControls.h Is Shipped with a sample atl program with vc # include "atlcontrols.h" #import "sas.tlb"

#import "saswman.dll" #import "c: / program files / common files / system / ado / msado15.dll" Rename ("EOF", "AdoEOF")

/// CMAINDIALOGLRESULT CMAINDIALOG :: OnNitdialog (Uint UMSG, WPARAM WPARAM, LPARAM LPARAM, BOOL & BHAND) {

Unsigned long i; long j;

// this is defined in atlControls.h; it is not part of win32.

ATLControls :: CTreeViewCtrl ctrlTreeView; ctrlTreeView.Attach (GetDlgItem (IDC_TREE1)); BSTR xmlInfo; HRESULT hr; _bstr_t strSource; SASWorkspaceManager :: IWorkspaceManager2Ptr pIWorkspaceManager; SAS :: IWorkspacePtr pIWorkspace; SASWorkspaceManager :: IServerDef2Ptr pIServerDef = NULL; hr = pIWorkspaceManager.CreateInstance ("SasworkspaceManager.Workspacemanager.1");

ADODB :: _ ConnectionPtr obConnection = NULL; ADODB :: _ RecordsetPtr obRecordset = NULL; hr = obRecordset.CreateInstance (__uuidof (ADODB :: Recordset)); hr = obConnection.CreateInstance (__uuidof (ADODB :: Connection));

// The smart pointers will throw an exception if any function returns a bad hr, so we // do not need to check for hr's try {pIWorkspaceManager-> Workspaces-> UseXMLInErrorInfo = false;. // Start SAS and get the Workspace // *********************************** PIWORKSPACE = PiWorkspaceManager-> Workspaces-> CreateWorkspaceByServer (_BSTR_T ("Localsas"), SasworkspaceManager :: VisibilityProcess, Null, _BSTR_T (""), _BSTR_T (""), & XMLINFO); // ***** end local sas code *********** // ***** Remote Sas code ** ************ //piserverdef.createInstance ("SasWorkspaceManager.serverDef "); // piServerDef-> port = 5307; // piServerDef-> protocol = sasworkspaceManager :: protocolbridge; // piServerdef -> PutMachineDNSName (_bstr_t ( "your.iomserver.com")); // pIWorkspace = pIWorkspaceManager-> Workspaces-> CreateWorkspaceByServer (// _bstr_t ( "remotesas"), SASWorkspaceManager :: VisibilityProcess, // pIServerDef, _bstr_t ( "username "), _BSTR_T (" password "), & xmlinf O); // ***** End Remote Sas code *********** // Valid Protocols // SasworkspaceManager :: Protocolcom // SasworkspaceManager :: Protocolbridge

// We can Run Sas Code Here to create a dataset or assoczire. You can also use a storedprocess, Which is where the sas // code is already on the sas server and you just tell sas to run it; you // can also pass in parameters from your program to the StoredProcess // That call might look something like this (assuming there is already a // program on the SAS server called init.sas) // SAS :: IStoredProcessServicePtr. pIStoredProcess; // pIStoredProcess = pIWorkspace-> LanguageService-> StoredProcessService; // pIStoredProcess-> PutRepository (_bstr_t ( "c: // stocks // Repository")); // pIStoredProcess-> Execute (_bstr_t ( "init"), _BSTR_T ("x = 5")); PiWorkspace-> LanguageSpace -> Submit ("libName stocks 'c: ////'; Data A; x = 5; y = 10; Run;");

// Output the SAS log to the Debug window OutputDebugString (pIWorkspace-> LanguageService-> FlushLog (10000)); // Connect the ADO Connection to the Workspace we created _bstr_t strConnect ( "Provider = SAS.IOMProvider.1; SAS Workspace ID = "); Strconnect = strconnect piworkspace-> uniqueidentifier;

HR = Obconnection-> Open (StrConnect, _bstr_t ("), _bstr_t (" "), null;

// Get A Safearray Containing All The Assigned Libraries SafeArray * psalibrefnames; PiWorkspace-> DataService-> ListLibrefs (& Psalibrefnames);

BSTR * PDATA; HTREEITEM TREELIBNAMEITEM; HTREEITEM TREEMEMNAMEITEM;

SafearrayAccessData (psalibrefnames, (void **) & pdata); adodb :: _ recordsetptr obmembers = null; hr = obmembers.createInstance (__UUIDB :: RECORDSET);

// Add each assigned library to the treeview for (i = 0; i rgsabound-> cElements; i ) {_bstr_t strLibname (pData [i]); treeLibnameItem = ctrlTreeView.InsertItem (strLibname, NULL, NULL);

// Add each dataset from each library to the treeview. // sashelp.vmember is a dataset the SAS system maintains that contains all the // contents of all libraries on the system. StrSource = "select * from sashelp.vmember where libname = ' " strLibname "' and memtype = 'DATA' "; obMembers-> Open (strSource, _variant_t ((IDispatch *) obConnection), ADODB :: adOpenForwardOnly, ADODB :: adLockReadOnly, ADODB :: adCmdText);

// add each variable (observation) from Each DataSet to the treaiView while (! Obmembers-> adoEof) {_BSTR_T STRMEMNAME (Obmembers-> Fields-> GetItem (_VARIANT_T ("Memname")) -> value);

TreeMemNameItem = CtrltreeView.Insertitem (StrMemName, TreelibNameItem, NULL);

strSource = strLibname strMemname "."; try {obRecordset-> Open (strSource, _variant_t ((IDispatch *) obConnection), ADODB :: adOpenForwardOnly, ADODB :: adLockReadOnly, ADODB :: adCmdTableDirect);

Long Fieldcount = ObRecordSet-> Fields-> count;

For (j = 0; j Fields-> GetItem (_VARIANT_T (J)) -> Name), treememnameItem, null;

ObRecordset-> Close ();} catch (_com_error e) {outputdebugstring (E.DESCRIPTION ());}

Obmembers-> moext ();

obMembers-> Close ();} SafeArrayUnaccessData (psaLibrefNames); SafeArrayDestroy (psaLibrefNames); pIWorkspaceManager-> Workspaces-> RemoveWorkspace (pIWorkspace); pIWorkspace-> Close ();. // Ensure that the SAS process is terminated} catch (_com_error e) {OutputDebugstring (E.DescriptionBox (NULL, E.Description (), "Error Caught!", MB_OK; for (j = 0; j errors-> count; j ) {OUTPUTDEBUGSTRING (_BSTR_T (Obconnection-> Errors-> GetItem (j) -> description));} OutputDebugString (_BSTR_T (Obconnection-> Errors-> count); return 1;}

:: MessageBox (Null, "Success!", "", MB_OK);

Return 1; // let the system set the focus}

转载请注明原文地址:https://www.9cbs.com/read-75439.html

New Post(0)