📄 demo_outputbar.cpp
字号:
// Demo_OutputBar.cpp : implementation file
//
#include "stdafx.h"
#include "SdbmsDemo.h"
#include "Demo_OutputBar.h"
#include "Sdbms.h"
extern CSdbms g_sdbms;
extern char *g_strSystemRight[];
extern char *g_strObjectRight[];
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDemo_OutputBar
CDemo_OutputBar::CDemo_OutputBar()
{
UpdateFont();
m_eChildBorder = OUTLINE;
m_nMaxCtrlID = IDC_OUTPUT;
}
CDemo_OutputBar::~CDemo_OutputBar()
{
for (int i=0; i<m_TableArray.GetSize(); i++)
{
delete m_TableArray[i];
}
}
BEGIN_MESSAGE_MAP(CDemo_OutputBar, CCJControlBar)
//{{AFX_MSG_MAP(CDemo_OutputBar)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemo_OutputBar message handlers
int CDemo_OutputBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCJControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// create the flat tab control.
if (!m_FlatTabCtrl.Create(NULL, NULL, WS_VISIBLE | WS_CHILD | FTS_HASARROWS |
FTS_BOTTOM | FTS_HASHOMEEND,
CRect(10,10,200,25), this, IDC_FLATTAB))
{
TRACE0( "Unable to create flat tab control bar\n" );
return -1;
}
// insert the actual tabs into the control.
m_FlatTabCtrl.InsertItem(0, "Debug");
m_FlatTabCtrl.InsertItem(1, "Information");
m_FlatTabCtrl.InsertItem(2, "Audit");
m_FlatTabCtrl.InsertItem(3, "Temp");
// define the default style for the output lists.
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP;
//创建Debug窗口
if (!m_DebugEdit.Create(dwStyle | ES_MULTILINE | ES_READONLY,
CRect(0,0,0,0), this, m_nMaxCtrlID++))
{
TRACE("Failed to create Debug window.\n");
return -1;
}
m_DebugEdit.SetFont(&m_Font);
//创建Information窗口
if (!m_InfoEdit.Create(dwStyle | ES_MULTILINE | ES_READONLY,
CRect(0,0,0,0), this, m_nMaxCtrlID++))
{
TRACE("Failed to create information window.\n");
return -1;
}
m_InfoEdit.SetFont(&m_Font);
//创建审计表AuditTable窗口
CDemo_TableList *pAuditTableList = new CDemo_TableList(NULL, g_sdbms.m_audit.m_pTable);
if (!pAuditTableList->Create(dwStyle | LVS_REPORT,
CRect(0,0,0,0), this, m_nMaxCtrlID++))
{
TRACE("Failed to create audit table window.\n");
return -1;
}
m_TableArray.Add(pAuditTableList);
//创建临时表TempTable窗口
CDemo_TableList *pTempTableList = new CDemo_TableList();
if (!pTempTableList->Create(dwStyle | LVS_REPORT,
CRect(0,0,0,0), this, m_nMaxCtrlID++))
{
TRACE("Failed to create temp table window.\n");
return -1;
}
m_TableArray.Add(pTempTableList);
// set the current tab.
SetActiveTabView(0);
return 0;
}
BOOL CDemo_OutputBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if(IDC_FLATTAB == (UINT)wParam)
{
NMHDR* pNMHDR = (NMHDR*)lParam;
switch(pNMHDR->code)
{
case TCN_SELCHANGING:
break;
case TCN_SELCHANGE:
SetActiveTabView(m_FlatTabCtrl.GetCurSel());
break;
}
}
return CCJControlBar::OnNotify(wParam, lParam, pResult);
}
void CDemo_OutputBar::OnSize(UINT nType, int cx, int cy)
{
CCJControlBar::OnSize(nType, cx, cy);
if(m_FlatTabCtrl.GetSafeHwnd())
{
CRect rc;
GetChildRect(rc);
rc.DeflateRect(1,1);
// resize the flat tab control.
m_FlatTabCtrl.MoveWindow(rc.left, rc.bottom-15, rc.Width(), 15);
int nBottom = rc.bottom;
if(IsHorzDocked()) {
nBottom -= 21;
} else if(IsVertDocked()) {
nBottom -= 34;
} else {
nBottom -= 19;
}
// resize lists.
m_DebugEdit.MoveWindow(rc.left, rc.top, rc.Width(), nBottom);
m_InfoEdit.MoveWindow(rc.left, rc.top, rc.Width(), nBottom);
for (int i=0; i<m_TableArray.GetSize(); i++)
{
m_TableArray[i]->MoveWindow(rc.left, rc.top, rc.Width(), nBottom);
//m_TableArray[i]->AutoSizeColumn();
}
}
}
void CDemo_OutputBar::Init()
{
SetActiveTabView(0);
m_DebugEdit.SetWindowText("");
m_InfoEdit.SetWindowText("");
int nCount = m_TableArray.GetSize() - 2;
for (int i=0; i<nCount; i++)
{
delete m_TableArray[0];
m_TableArray.RemoveAt(0);
m_FlatTabCtrl.DeleteItem(2);
}
m_TableArray[0]->DeleteAllItems();
}
void CDemo_OutputBar::UpdateFont()
{
m_Font.DeleteObject();
NONCLIENTMETRICS ncm;
memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
_tcscpy( ncm.lfMessageFont.lfFaceName, _T("Courier"));
m_Font.CreateFontIndirect(&ncm.lfMessageFont);
}
void CDemo_OutputBar::SetActiveTabView(int nTab)
{
m_DebugEdit.ShowWindow((nTab==0)?SW_SHOW:SW_HIDE);
m_InfoEdit.ShowWindow((nTab==1)?SW_SHOW:SW_HIDE);
for (int i=0; i<m_TableArray.GetSize(); i++)
m_TableArray[i]->ShowWindow((nTab==2+i)?SW_SHOW:SW_HIDE);
}
BOOL CDemo_OutputBar::SetActiveTabView(CSdbms_Database *pDB, CSdbms_Table *pTable)
{
ASSERT(pTable);
for (int i=0; i<m_TableArray.GetSize(); i++)
if ((m_TableArray[i]->m_pDatabase == pDB) && (m_TableArray[i]->m_pTable == pTable))
{
SetActiveTabView(2+i);
m_FlatTabCtrl.SetCurSel(2+i);
return TRUE;
}
return FALSE;
}
void CDemo_OutputBar::OutputDebugInformation(CString strMessage)
{
int nLength = m_DebugEdit.GetWindowTextLength();
m_DebugEdit.SetSel(nLength+1, nLength+1);
strMessage += "\r\n";
m_DebugEdit.ReplaceSel(strMessage);
SetActiveTabView(0);
m_FlatTabCtrl.SetCurSel(0);
}
void CDemo_OutputBar::OutputUserInformation(CSdbms_User *pUser)
{
ASSERT(pUser);
CString str, strTemp;
strTemp.Format("用户名:%s\r\n", pUser->m_strUserName);
str = strTemp;
strTemp.Format("用户口令:%s\r\n", pUser->m_strPassword);
str += strTemp;
strTemp.Format("用户ID:%d\r\n", pUser->m_nUserID);
str += strTemp;
strTemp.Format("用户最大安全级:%s\r\n", pUser->m_SecLevel.GetFormatString());
str += strTemp;
//输出用户在各表上的允许安全级和当前安全级
POSITION pos = g_sdbms.m_DBList.GetHeadPosition();
while (pos) //遍历所有的数据库
{
CSdbms_Database *pDB = g_sdbms.m_DBList.GetNext(pos);
if (!pDB->m_bInit)
pDB->Init();
for (int i=0; i<pDB->m_TableArray.GetSize(); i++) //遍历数据库中所有的表
{
CSdbms_Table *pTable = pDB->m_TableArray[i];
strTemp.Format("用户在数据库%s中的表%s上的允许安全级:%s,当前安全级:%s\r\n",
pDB->m_strDBName, pTable->m_strTableName,
pDB->GetUserAllowSecLevel(pUser, pTable).GetFormatString(),
pDB->GetUserCurSecLevel(pUser, pTable).GetFormatString());
str += strTemp;
}
}
int nLength = m_InfoEdit.GetWindowTextLength();
m_InfoEdit.SetSel(0, nLength);
m_InfoEdit.ReplaceSel(str);
SetActiveTabView(1);
m_FlatTabCtrl.SetCurSel(1);
}
void CDemo_OutputBar::OutputRoleInformation(CSdbms_Role *pRole, CSdbms_Database *pDB/*=NULL*/)
{
CString str, strTemp;
if (pRole == NULL) //数据库创建者
{
ASSERT(pDB);
CSdbms_Role *pCreatorRole = pDB->m_pCreatorRole;
str = "角色名:" + pDB->m_strDBName + ".OWNER\r\n";
strTemp.Format("角色ID:%d\r\n", pCreatorRole->m_nRoleID);
str += strTemp;
strTemp.Format("角色说明:数据库%s的创建者角色,拥有数据库内的所有权限!\r\n", pDB->m_strDBName);
str += strTemp;
str += " 包括增删查改及授权和收权命令,并可设置和改变数据对象的安全级。\r\n";
str += "对象权限被授予给了====> ";
CSdbms_RoleObjectRight *pRight = pCreatorRole->m_ORList.GetHead();
if (pRight->m_ToRoleArray.GetSize() > 0)
str += pRight->m_ToRoleArray[0]->m_strRoleName;
for (int i=1; i<pRight->m_ToRoleArray.GetSize(); i++)
{
str += ", ";
str += pRight->m_ToRoleArray[i]->m_strRoleName;
}
str += "\r\n";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -