// sxconDlg.cpp : implementation file // #include "stdafx.h" #include "orxconst.h" #include "orxcon.h" #include "sxcon.h" #include "sxconDlg.h" #include #include #include // for DoBatch AfxHook/UnhookWindowCreate() #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: virtual BOOL OnInitDialog(); //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSxConDlg dialog CSxConDlg::CSxConDlg(CWnd* pParent /*=NULL*/) : CDialog(CSxConDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSxConDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_nReportsRunning = 0; } void CSxConDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSxConDlg) DDX_Control(pDX, IDC_ORACLEREPORTSCONTROL1, m_ctlOracleReports); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSxConDlg, CDialog) //{{AFX_MSG_MAP(CSxConDlg) ON_WM_SYSCOMMAND() ON_WM_DESTROY() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(ID_RUNREPORT, OnRunReport) ON_BN_CLICKED(ID_EDITPROPERTIES, OnEditProperties) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSxConDlg message handlers BOOL CSxConDlg::OnInitDialog() { // instantiate Reports control, etc. CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } pSysMenu->EnableMenuItem(SC_SIZE, MF_BYCOMMAND | MF_GRAYED); pSysMenu->EnableMenuItem(SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // // Set passed parameters, if any // CSxConApp *app = AfxSxConGetApp(); // report name if (app->m_cstrReport) m_ctlOracleReports.SetReportName((LPCTSTR)*(app->m_cstrReport)); // report server if (app->m_cstrRepSrv) m_ctlOracleReports.SetReportsServer((LPCTSTR)*(app->m_cstrRepSrv)); // connect string if (app->m_cstrUserId) m_ctlOracleReports.SetDatabaseUser((LPCTSTR)*(app->m_cstrUserId)); // destination name if (app->m_cstrDesName && !app->m_cstrDesName->IsEmpty()) m_ctlOracleReports.SetOutputName((LPCTSTR)*(app->m_cstrDesName)); // destination type if (app->m_eDesType != orODInReport) m_ctlOracleReports.SetOutputDestination(app->m_eDesType); // System Userid if (app->m_cstrSysUserId) { int ilen = (app->m_cstrSysUserId)->GetLength(); int ipss = (app->m_cstrSysUserId)->Find((TCHAR)_T('/')); CString sPusername = (app->m_cstrSysUserId)->Left(ipss); CString sPpassword = (app->m_cstrSysUserId)->Right(ilen - (ipss+1));; m_ctlOracleReports.SetSystemUser((LPCTSTR) sPusername); m_ctlOracleReports.SetSystemPassword((LPCTSTR) sPpassword); } // call mode m_ctlOracleReports.SetCallMode(app->m_eCallMode); // rest of the command line if (app->m_cstrParams && !app->m_cstrParams->IsEmpty()) m_ctlOracleReports.SetUserDefinedParameters((LPCTSTR)*(app->m_cstrParams)); // // If this is UI run, show properties first // if we where asked // if (app->m_bShowUI && app->m_bSetOpt) { # if 0 CWnd *onEditProps = GetDlgItem(ID_EDITPROPERTIES); if (onEditProps) PostMessage(WM_COMMAND, MAKEWPARAM(0, BN_CLICKED), (LPARAM)onEditProps->GetSafeHwnd()); # else m_ctlOracleReports.EditProperties(); # endif } // set dialog text,etc. UpdateDialog(); return TRUE; // return TRUE unless you set the focus to a control } void CSxConDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } void CSxConDlg::OnDestroy() { // hide, so user won't get upset EnableWindow(FALSE); ShowWindow(SW_HIDE); WinHelp(0L, HELP_QUIT); // wait until done with run, before destroying children (i.e. control) while (m_nReportsRunning) Sleep(500); CDialog::OnDestroy(); } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CSxConDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CSxConDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); return TRUE; } BEGIN_EVENTSINK_MAP(CSxConDlg, CDialog) //{{AFX_EVENTSINK_MAP(CSxConDlg) ON_EVENT(CSxConDlg, IDC_ORACLEREPORTSCONTROL1, 1 /* BeforeRunReport */, OnBeforeRunReportOracleReportsControl1, VTS_I4) ON_EVENT(CSxConDlg, IDC_ORACLEREPORTSCONTROL1, 2 /* AfterRunReport */, OnAfterRunReportOracleReportsControl1, VTS_I4 VTS_I4) ON_EVENT(CSxConDlg, IDC_ORACLEREPORTSCONTROL1, 3 /* RunReportProgress */, OnRunReportProgressOracleReportsControl1, VTS_I4 VTS_I4) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CSxConDlg::OnBeforeRunReportOracleReportsControl1(long ReportHandle) { ::InterlockedIncrement((LONG*)&(m_nReportsRunning)); CSxConApp *app = AfxSxConGetApp(); if (app->m_bShowAct) { // at this point nobody yet changed any properties, hopefully ;-) CString ocxcmdln = (LPCTSTR)m_ctlOracleReports.GetCommandLine(); CString msg; msg.GetBuffer(2048); msg.Format(IDS_OLE_REPORTSTART, ReportHandle, ocxcmdln); AfxMessageBox(msg); } } void CSxConDlg::OnAfterRunReportOracleReportsControl1(long ReportHandle, long ResultCode) { CSxConApp *app = AfxSxConGetApp(); if (app->m_bShowAct) { CString msg; CString ocxmsg = (LPCTSTR)m_ctlOracleReports.GetReportStateString(ReportHandle); //CString ocxdesname = (LPCTSTR)m_ctlOracleReports.GetReportOutputName(ReportHandle); msg.GetBuffer(1024+ocxmsg.GetLength()); msg.Format(IDS_OLE_REPORTEND, ReportHandle, ocxmsg); AfxMessageBox(msg); } ::InterlockedDecrement((LONG*)&(m_nReportsRunning)); } void CSxConDlg::OnRunReportProgressOracleReportsControl1(long ReportHandle, long ProgressCode) { // TODO: Add your control notification handler code here } int CSxConDlg::DoBatch() { // stolen from CDialog::DoModal(); // can be constructed with a resource template or InitModalIndirect ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL || m_lpDialogTemplate != NULL); // load resource as necessary LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate; HGLOBAL hDialogTemplate = m_hDialogTemplate; HINSTANCE hInst = AfxGetResourceHandle(); if (m_lpszTemplateName != NULL) { hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG); HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); } if (hDialogTemplate != NULL) lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate); // return -1 in case of failure to load the dialog template resource if (lpDialogTemplate == NULL) return -1; // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); CWnd* pParentWnd = CWnd::FromHandle(hWndParent); BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } // create modeless dialog AfxHookWindowCreate(this); #ifdef _AFXDLL if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), AfxGetModuleState()->m_dwVersion >= 0x410 ? hInst : NULL)) #else if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInst)) #endif { // run the sucker DoWhatYouGottaDo(); #if NEVER // run batch and quit right after if (m_nFlags & WF_CONTINUEMODAL) { // enter modal loop DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } // hide the window before enabling the parent, etc. SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW| SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); #endif } if (bEnableParent) ::EnableWindow(hWndParent, TRUE); if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd) ::SetActiveWindow(hWndParent); // destroy modal window DestroyWindow(); PostModal(); // unlock/free resources as necessary if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL) UnlockResource(hDialogTemplate); if (m_lpszTemplateName != NULL) FreeResource(hDialogTemplate); return m_nModalResult; } void CSxConDlg::UpdateDialog() { // set static controls text CString sReportName = m_ctlOracleReports.GetReportName(); //sReportName.MakeLower(); CWnd *pReportNameStatic = (CWnd*) GetDlgItem(IDC_REPORTNAME); pReportNameStatic->SetWindowText((LPCTSTR)sReportName); if (! sReportName.IsEmpty()) pReportNameStatic->SetWindowText((LPCTSTR)sReportName); else pReportNameStatic->SetWindowText(_T("")); CString sReportServer = m_ctlOracleReports.GetReportsServer(); //sReportServer.MakeLower(); CWnd *pReportServerStatic = (CWnd*) GetDlgItem(IDC_REPORTSERVER); pReportServerStatic->SetWindowText((LPCTSTR)sReportServer); if (! sReportServer.IsEmpty()) pReportServerStatic->SetWindowText((LPCTSTR)sReportServer); else pReportServerStatic->SetWindowText(_T("")); CString sDatabaseUser = m_ctlOracleReports.GetDatabaseUser(); CString sDatabaseName = m_ctlOracleReports.GetDatabaseName(); if (! sDatabaseName.IsEmpty()) { sDatabaseUser += (LPCTSTR)"@"; sDatabaseUser += (LPCTSTR)sDatabaseName; } CWnd *pDatabaseStatic = (CWnd*) GetDlgItem(IDC_DATABASECONNECT); if (! sDatabaseUser.IsEmpty()) pDatabaseStatic->SetWindowText((LPCTSTR)sDatabaseUser); else pDatabaseStatic->SetWindowText(_T("")); // check file exists Exist and enable Run button CWnd *pRunButton = (CWnd*) GetDlgItem(ID_RUNREPORT); BOOL bEnable = ((! sReportName.IsEmpty()) && ((! sReportServer.IsEmpty()) || // servername set, or ((! m_ctlOracleReports.GetCallMode()) && CheckFileExists( sReportName ))) && // local exe (! sDatabaseUser.IsEmpty())); pRunButton->EnableWindow(bEnable); } void CSxConDlg::OnRunReport() { #if 0 // show warninig if report (as specified) is not found CString sReportName = m_ctlOracleReports.GetReportName(); BOOL bDoIt = CheckFileExists( sReportName ); if (!bDoIt) bDoIt = (IDYES == AfxMessageBox(IDS_OLE_REPORTNOTLOCAL, MB_YESNO)); if (bDoIt) #endif DoWhatYouGottaDo(); } void CSxConDlg::OnEditProperties() { DEBUG_BREAK; m_ctlOracleReports.EditProperties(); UpdateDialog(); } // // Run report and quit if necessary // long CSxConDlg::DoWhatYouGottaDo() { DEBUG_BREAK; CSxConApp *app = AfxSxConGetApp(); // // If this is no-UI run, show properties first // if we where asked // if (!app->m_bShowUI && app->m_bSetOpt) m_ctlOracleReports.EditProperties(); BOOL bRun; long hr; long hReport; { CString str; // destruct before run, in case of exception CString str1; str1 = m_ctlOracleReports.GetReportName(); bRun = ! str1.IsEmpty(); str = m_ctlOracleReports.GetDatabaseUser(); bRun = bRun && (! str.IsEmpty()); // // Set call mode to sync or local, just for fun // (if mode is async and we quit connections will be // terminated - this is no problem, but not nice ;-) // // For constants value, see ocx typelib // str = m_ctlOracleReports.GetReportsServer(); // if no servername and run is not local -- no way, Jose. if (str.IsEmpty() && m_ctlOracleReports.GetCallMode(/* !LOCALEXE? */)) // no server specified? bRun = FALSE; //else // if (! m_ctlOracleReports.GetCallMode()) // local call and server name specified? // m_ctlOracleReports.SetCallMode(1 /* SYNCCALL */); // force sync call } // // Since this application can immediately quit after // submitting report, make sure we will stay up until // report is done. // if (bRun) { hr = m_ctlOracleReports.RunReport(&hReport); if (SUCCEEDED(hr) && ! app->m_bShowAct) { AfxMessageBox(IDS_OLE_NICERUN); // quit modal dialog (bShowUI), if done for the 1st time if (app->m_bShowUI && !app->m_bStayUp) { EndDialog(0); } } //else error shown // AfxMessageBox(IDS_OLE_BADRUN); } else // if (! app->m_bShowUI && app->m_bSetOpt ) { AfxMessageBox(IDS_OLE_NOMANDATORYPARS); } return hr; } BOOL CSxConDlg::DestroyWindow() { // TODO: Add your specialized code here and/or call the base class return CDialog::DestroyWindow(); }