📄 childfrm.cpp
字号:
);
m_ThreadParam.m_ptrGridCtrl->put_HighLight(
MSFlexGridLib::flexHighlightAlways
);
m_ThreadParam.m_ptrGridCtrl->put_ScrollBars(
MSFlexGridLib::flexScrollBarBoth
);
if(m_GridFont.m_lf.lfHeight != 0)
{
COleFont font(pGridCtrl->GetFont());
font.SetBold(m_GridFont.m_bIsBold);
font.SetCharset(m_GridFont.m_lf.lfCharSet);
font.SetItalic(m_GridFont.m_lf.lfItalic);
font.SetName(m_GridFont.m_strFaceName);
CY cy;
cy.Lo = m_GridFont.m_nSize;
cy.Hi = 0;
cy.int64 = cy.Lo;
font.SetSize(cy);
font.SetUnderline(m_GridFont.m_lf.lfUnderline);
font.SetWeight(m_GridFont.m_lf.lfWeight);
}
m_ThreadParam.m_ptrGridCtrl->put_Cols(0);
m_ThreadParam.m_ptrGridCtrl->put_Rows(1);
m_ThreadParam.m_ptrGridCtrl->put_Cols(wParam);
if(m_nGridCount == 2)
{
POSITION pos = m_GridList.FindIndex(m_nIndex);
if(pos != NULL)
{
++m_nIndex;
if(m_strStatusText.CompareNoCase(g_szMessages) != 0)
DisplayResults((CMSFlexGrid*)m_GridList.GetAt(pos), m_nIndex);
bool bOkUI = true;
if(m_bCloseMainFrameAfterCancel)
bOkUI = false;
if(m_bDisconnectAllAfterCancel)
bOkUI = false;
if(m_bCloseAfterCancel)
bOkUI = false;
if(bOkUI)
{
LONG lIdle = 0;
while(AfxGetApp()->OnIdle(lIdle++));
}
}
}
pGridCtrl->MoveWindow(0, 0, rect.Width(), rect.Height());
}
}
catch(COleDispatchException* e)
{
lResult = -1L;
UNUSED_ALWAYS(e);
if(e)
e->Delete();
}
catch(...)
{
lResult = -1L;
}
if(lResult == -1L)
{
if(pGridCtrl != NULL)
{
pGridCtrl->DestroyWindow();
delete pGridCtrl;
pGridCtrl = NULL;
}
}
}
return lResult;
}
LONG CChildFrame::OnSetGridRows(UINT wParam, LONG lParam)
{
LRESULT lResult = 0L;
if(::IsWindow(m_hWnd))
{
UNUSED_ALWAYS(lParam);
try
{
if(m_ThreadParam.m_ptrGridCtrl != NULL)
{
m_pResultView->SetRedraw(FALSE);
HRESULT hr = m_ThreadParam.m_ptrGridCtrl->put_Redraw(FALSE);
if(FAILED(hr))
_com_issue_error(hr);
hr = m_ThreadParam.m_ptrGridCtrl->put_Rows(wParam);
if(FAILED(hr))
_com_issue_error(hr);
hr = m_ThreadParam.m_ptrGridCtrl->put_Redraw(TRUE);
if(FAILED(hr))
_com_issue_error(hr);
m_pResultView->SetRedraw(TRUE);
if(m_nGridCount == 1)
if(m_strStatusText.CompareNoCase(g_szMessages) != 0)
m_ThreadParam.m_pGridCtrl->ShowWindow(SW_SHOW);
}
}
catch(...)
{
lResult = -1L;
}
}
return lResult;
}
void CChildFrame::OnViewMessages()
{
if(m_strStatusText.CompareNoCase(g_szMessages) != 0)
{
HideResultSets();
m_pResultView->GetRichEditCtrl().SetWindowText(m_strMessages.c_str());
m_strStatusText = g_szMessages;
}
else
{
if(m_strProcText.length())
{
m_pResultView->GetRichEditCtrl().SetWindowText(m_strProcText.c_str());
m_pResultView->GetRichEditCtrl().SetSel(0, 0); // Scroll up!
m_strStatusText.Format(
_T("# of lines of text: %d"),
m_pResultView->GetRichEditCtrl().GetLineCount()
);
}
else
{
int nCurrentSet = 1;
if(m_nIndex != 0)
nCurrentSet = m_nIndex;
POSITION pos = m_GridList.FindIndex(nCurrentSet-1);
if(pos == NULL)
{
m_pResultView->GetRichEditCtrl().SetWindowText(NULL);
m_strStatusText = "Results grid #0 of 0; 0 row(s); 0 col(s)";
}
else
{
CMSFlexGrid* pGrid = (CMSFlexGrid*)m_GridList.GetAt(pos);
if(pGrid != NULL)
DisplayResults(pGrid, nCurrentSet);
}
}
}
m_pResultView->Invalidate();
m_pResultView->UpdateWindow();
}
void CChildFrame::OnUpdateViewMessages(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_database.IsOpen() && m_strMessages.length());
pCmdUI->SetCheck(!m_strStatusText.CompareNoCase(g_szMessages) &&
m_database.IsOpen() && m_strMessages.length());
}
void CChildFrame::OnTimer(UINT nIDEvent)
{
if(m_nTimerID != nIDEvent)
CMDIChildWnd::OnTimer(nIDEvent);
else
{
if(m_bExecuting)
{
SetExecutionTime();
if(!m_bProcText)
SetResultSetInfo();
}
}
}
void CChildFrame::SetResultSetInfo()
{
if(m_strStatusText.CompareNoCase(g_szMessages) != 0)
{
int nCurrentSet = 1;
if(m_nIndex != 0)
nCurrentSet = m_nIndex;
POSITION pos = m_GridList.FindIndex(nCurrentSet-1);
if(pos != NULL)
{
CMSFlexGrid* pGrid = (CMSFlexGrid*)m_GridList.GetAt(pos);
if(pGrid != NULL)
{
m_strStatusText.Format(_T("Results grid #%d of %d; %d row(s); %d col(s)"),
nCurrentSet, m_nGridCount, pGrid->GetRows()-1, pGrid->GetCols());
m_wndStatusBar.SetPaneText(m_nResultSetPaneNo, m_strStatusText);
}
}
}
}
void CChildFrame::CloseRecordset()
{
try
{
if(m_pSet != NULL && m_pSet->IsOpen())
{
m_pSet->Close();
m_pSet->m_hstmt = NULL;
}
}
catch(...)
{
TRACE(_T("Errors occurred.\n"));
}
}
BOOL CChildFrame::IsSQLCancelSupported()
{
UWORD bSQLCancelSupported = 0;
::SQLGetFunctions(m_database.m_hdbc, SQL_API_SQLCANCEL, &bSQLCancelSupported);
return bSQLCancelSupported;
}
BOOL CChildFrame::IsTextDataSource()
{
UCHAR buffer[200];
SWORD cbData;
::SQLGetInfo(m_database.m_hdbc, SQL_DBMS_NAME, (PTR)buffer, 200, &cbData);
CString sBuff = buffer;
return !sBuff.CompareNoCase(g_szText);
}
BOOL CChildFrame::IsODBCJetDriver()
{
UCHAR buffer[200];
SWORD cbData;
::SQLGetInfo(m_database.m_hdbc, SQL_DRIVER_NAME, (PTR)buffer, 200, &cbData);
CString sBuff = buffer;
return !sBuff.CompareNoCase(g_szODBCJTDriver);
}
BOOL CChildFrame::IsMultiResultSetsSupported()
{
UCHAR buffer[200];
SWORD cbData;
::SQLGetInfo(m_database.m_hdbc, SQL_MULT_RESULT_SETS, (PTR)buffer, 200, &cbData);
return (CString(buffer) == _T("Y"));
}
BOOL CChildFrame::IsSQLRowCountSupported()
{
UWORD bSQLRowCountSupported = 0;
::SQLGetFunctions(m_database.m_hdbc, SQL_API_SQLROWCOUNT, &bSQLRowCountSupported);
return bSQLRowCountSupported;
}
void CChildFrame::OnHelpOdbcInfo()
{
CWaitCursor wait;
// Create our property sheet
CMyPropertySheet sheet(_T("ODBC Driver Info"));
// Create all our property pages
CDriverInfo DriverInfoPage(&m_database);
CFunctions FunctionsPage(&m_database);
CSupportedSQL SupportedSQLPage(&m_database);
CDataTypes DataTypesPage(&m_database);
CIdentifiers IdentifiersPage(&m_database);
CLimits LimitsPage(&m_database);
CMisc1 Misc1Page(&m_database);
CMisc2 Misc2Page(&m_database);
// Add the pages to our sheet
sheet.AddPage(&DriverInfoPage);
sheet.AddPage(&FunctionsPage);
sheet.AddPage(&SupportedSQLPage);
sheet.AddPage(&DataTypesPage);
sheet.AddPage(&IdentifiersPage);
sheet.AddPage(&LimitsPage);
sheet.AddPage(&Misc1Page);
sheet.AddPage(&Misc2Page);
sheet.DoModal();
}
void CChildFrame::OnUpdateHelpOdbcInfo(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_database.IsOpen() && !m_bExecuting);
}
BOOL CChildFrame::SetQueryDef(const CString& sDBName, const CString& sSQL)
{
CWaitCursor wait;
BOOL bRet = TRUE;
CString sMsg;
try
{
CDaoDatabase db;
db.Open(sDBName);
CDaoQueryDef qDef(&db);
qDef.Open(sSQL);
m_strProcText = qDef.GetSQL();
qDef.Close();
db.Close();
}
catch(CDaoException* e)
{
bRet = FALSE;
if(e)
{
if(e->m_pErrorInfo)
sMsg.Format(
_T("%s (%d)"),
(LPCTSTR)e->m_pErrorInfo->m_strDescription,
e->m_pErrorInfo->m_lErrorCode
);
else
{
sMsg.Format(
_T("ERROR:CDaoException\n\n")
_T("SCODE_CODE =%d\n")
_T("SCODE_FACILITY =%d\n")
_T("SCODE_SEVERITY =%d\n")
_T("ResultFromScode =%d\n"),
SCODE_CODE (e->m_scode),
SCODE_FACILITY (e->m_scode),
SCODE_SEVERITY (e->m_scode),
ResultFromScode (e->m_scode)
);
}
e->Delete();
}
}
catch(CMemoryException* e)
{
bRet = FALSE;
sMsg = "Out-of-Memory.";
if(e)
e->Delete();
}
catch(...)
{
sMsg = "Errors occurred.";
}
if(!sMsg.IsEmpty())
{
if(m_strMessages.length())
m_strMessages += _T("\n\n");
m_strMessages += sMsg;
}
return bRet;
}
void CChildFrame::OnClose()
{
bool bOKToClose = true;
if(m_bCanceling)
m_bCloseAfterCancel = TRUE;
else
{
if(IsIconic())
ShowWindow(SW_SHOWNORMAL);
if(m_bExecuting)
{
CString sMsg = "A query execution is in progress. Are you sure you wish to cancel this query?";
if(AfxMessageBox(sMsg, MB_YESNO | MB_ICONQUESTION) == IDNO)
bOKToClose = false;
else
{
if(!m_bCanceling)
{
m_bCloseAfterCancel = TRUE;
CancelQuery();
bOKToClose = false;
}
}
}
}
if(m_bCanceling)
if(!m_bCanceled)
bOKToClose = false;
if(bOKToClose)
CMDIChildWnd::OnClose();
}
void CChildFrame::OnSetDbcomboFocus()
{
m_comboBox.SetFocus();
}
void CChildFrame::PostNcDestroy()
{
CWaitCursor wait;
ClearGridList();
if(m_font.m_hObject != NULL)
{
m_font.Detach();
m_font.m_hObject = NULL;
}
try
{
if(m_database.IsOpen())
m_database.Close();
if(m_pSet != NULL)
{
delete m_pSet;
m_pSet = NULL;
}
}
catch(...)
{
TRACE(_T("Errors occurred.\n"));
}
if(m_nTimerID != 0)
{
if(::IsWindow(this->m_hWnd))
KillTimer(m_nTimerID);
m_nTimerID = 0;
}
if(m_pThreadCancelSQL != NULL &&
AfxIsValidAddress(m_pThreadCancelSQL, sizeof(m_pThreadCancelSQL)) &&
m_pThreadCancelSQL->m_hThread != NULL)
{
m_pThreadCancelSQL->PostThreadMessage(WM_QUIT, 0L, 0L);
::WaitForSingleObject(m_pThreadCancelSQL->m_hThread, 30000);
}
if(m_pThreadExecuteSQL != NULL &&
AfxIsValidAddress(m_pThreadExecuteSQL, sizeof(m_pThreadExecuteSQL)) &&
m_pThreadExecuteSQL->m_hThread != NULL)
{
m_pThreadExecuteSQL->PostThreadMessage(WM_QUIT, 0L, 0L);
::WaitForSingleObject(m_pThreadExecuteSQL->m_hThread, 30000);
}
CMDIChildWnd::PostNcDestroy();
}
/////////////////////////////////////////////////////////////////////////////
// Helpers for saving/restoring font state
void CChildFrame::GetProfileFont(LPCTSTR szSec, LOGFONT* plf, const bool& bGrid,
BOOL* pIsBold, int* pSize)
{
CWinApp* pApp = AfxGetApp();
plf->lfHeight = pApp->GetProfileInt(szSec, g_szHeight, 0);
if(plf->lfHeight != 0)
{
plf->lfWeight = pApp->GetProfileInt(szSec, g_szWeight, 0);
plf->lfItalic = (BYTE)pApp->GetProfileInt(szSec, g_szItalic, 0);
plf->lfUnderline = (BYTE)pApp->GetProfileInt(szSec, g_szUnderline, 0);
plf->lfPitchAndFamily = (BYTE)pApp->GetProfileInt(szSec, g_szPitchAndFamily, 0);
plf->lfCharSet = (BYTE)pApp->GetProfileInt(szSec, g_szCharSet, DEFAULT_CHARSET);
CString strFont = pApp->GetProfileString(szSec, g_szFaceName, g_szSystem);
lstrcpyn((TCHAR*)plf->lfFaceName, strFont, sizeof(plf->lfFaceName));
plf->lfFaceName[sizeof(plf->lfFaceName)-1] = 0;
if(bGrid)
{
*pIsBold = pApp->GetProfileInt(szSec, g_szBold, 0);
*pSize = pApp->GetProfileInt(szSec, g_szSize, 0);
}
}
}
void CChildFrame::WriteProfileFont(LPCTSTR szSec, const LOGFONT* plf,
const bool& bGrid, BOOL* pIsBold, int* pSize)
{
if(plf->lfHeight != 0)
{
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt(szSec, g_szHeight, plf->lfHeight);
pApp->WriteProfileInt(szSec, g_szWeight, plf->lfWeight);
pApp->WriteProfileInt(szSec, g_szItalic, plf->lfItalic);
pApp->WriteProfileInt(szSec, g_szUnderline, plf->lfUnderline);
pApp->WriteProfileInt(szSec, g_szPitchAndFamily, plf->lfPitchAndFamily);
pApp->WriteProfileInt(szSec, g_szCharSet, plf->lfCharSet);
pApp->WriteProfileString(szSec, g_szFaceName, (LPCTSTR)plf->lfFaceName);
if(bGrid)
{
pApp->WriteProfileInt(szSec, g_szBold, *pIsBold);
pApp->WriteProfileInt(szSec, g_szSize, *pSize);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -