www.pudn.com > 6433624505.rar > AllUser.cpp
// AllUser.cpp : implementation file
//
#include "stdafx.h"
#include "Browser.h"
#include "AllUser.h"
#include "Alltable.h"
#include "Detials.h"
#include "ProgDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAllUser dialog
CAllUser::CAllUser(CWnd* pParent /*=NULL*/)
: CDialog(CAllUser::IDD, pParent)
{
//{{AFX_DATA_INIT(CAllUser)
m_Edit = _T("");
//}}AFX_DATA_INIT
}
void CAllUser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAllUser)
DDX_Control(pDX, IDCANCEL, m_Close);
DDX_Control(pDX, IDC_USERLIST, m_List);
DDX_Text(pDX, IDC_USEREDIT, m_Edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAllUser, CDialog)
//{{AFX_MSG_MAP(CAllUser)
ON_NOTIFY(NM_CLICK, IDC_USERLIST, OnClickUserlist)
ON_NOTIFY(NM_DBLCLK, IDC_USERLIST, OnDblclkUserlist)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAllUser message handlers
BOOL CAllUser::OnInitDialog()
{
CDialog::OnInitDialog();
m_bitmapground.LoadBitmap(IDB_SONGROUND);
m_Close.LoadBitmaps(IDB_CLOSEONE,IDB_CLOSETWO);
names.clear();
values.clear();
count = 0;
m_List.SetTextColor(RGB (0, 0, 0));
m_List.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
OnRefresh();
return TRUE;
}
void CAllUser::OnRefresh()
{
CProgressDlg pro;
_RecordsetPtr pRstcount;
int counts;
m_List.DeleteAllItems();
CString _sql,_sqlcount;
if(select == 0)
{
_sql = "select * from dba_users";
_sqlcount = "select count(*) from dba_users";
SetWindowText("所有用户");
}
if(select == 1)
{
_sql = "select * from dba_tablespaces";
_sqlcount = "select count(*) from dba_tablespaces";
SetWindowText("所有表空间");
}
if(select == 2)
{
_sql = "select * from dba_triggers";
_sqlcount = "select count(*) from dba_triggers";
SetWindowText("所有触发器");
}
if(select == 3)
{
_sql = "select * from dba_procedures";
_sqlcount = "select count(*) from dba_procedures";
SetWindowText("所有存储过程");
}
if(select == 4)
{
_sql = "select * from dba_indexes";
_sqlcount = "select count(*) from dba_indexes";
SetWindowText("所有索引");
}
if(select == 5)
{
_sql = "select * from dba_sequences";
_sqlcount = "select count(*) from dba_sequences";
SetWindowText("所有序列");
}
_bstr_t sql = _sql;
_bstr_t sqlcount = _sqlcount;
CString val,name;
try
{
pRstcount = pConn->Execute(sqlcount,NULL,adCmdText);
_variant_t vCount = pRstcount->Fields->GetItem(long(0))->Value;
counts = vCount.iVal;
pro.Create(this);
pro.SetWindowText(_T("请稍后..."));
pro.m_Progress.SetRange(0,4*counts/30);
pro.m_Progress.SetPos(0);
pRst = pConn->Execute(sql,NULL,adCmdText);
colume = pRst->Fields->GetCount();
for(int a = 0;a < colume;a++)
{
name = (char *)_bstr_t(pRst->Fields->GetItem(long(a))->Name);
names.push_back(name);
}
while(!pRst->End)
{
for(int b = 0;b < colume;b++)
{
_variant_t vValue = pRst->Fields->GetItem(long(b))->Value;
if(vValue.vt == VT_NULL)
val = "NULL";
else
val = (char *)_bstr_t(vValue);
values.push_back(val);
}
count ++;
pro.m_Progress.SetPos(count/10);
pro.SetStatus(count);
pRst->MoveNext();
}
for(int col = 0;col < colume;col ++)
{
m_List.InsertColumn(col,names[col],80,80);
}
pro.SetStatus();
pRst = pConn->Execute(sql,NULL,adCmdText);
if(!pRst->End)
{
for(int col = 0;col < count;col ++)
{
m_List.InsertItem(col,values[col*colume]);
for(int subcol = 1;subcol < colume;subcol ++)
{
m_List.SetItemText(col,subcol,values[subcol+col*colume]);
}
pro.m_Progress.SetPos(counts+col/30);
}
}
count = 0;
pRst->Close();
pRst.Release();
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}
pro.DestroyWindow();
}
void CAllUser::OnClickUserlist(NMHDR* pNMHDR, LRESULT* pResult)
{
cursel = m_List.GetSelectionMark();
m_Edit.Empty();
m_Edit.Format("当前是第 %d 条记录\r\n",cursel + 1);
CString str[100];
if(cursel >= 0)
{
for(int i = 0;i < names.size(); i++)
{
str[i].Format("%s: %s\r\n",names[i],values[cursel*colume+i]);
m_Edit += str[i];
}
this->UpdateData(false);
}
*pResult = 0;
}
void CAllUser::OnDblclkUserlist(NMHDR* pNMHDR, LRESULT* pResult)
{
cursel = m_List.GetSelectionMark();
if(select == 1)
{
if(cursel >=0)
{
CAlltable alltable;
alltable.pConn = pConn;
alltable.select = 1;
alltable.User = this->User;
alltable.tablespace = values[cursel*colume];
alltable.DoModal();
}
else
AfxMessageBox(_T("未选定表"));
}
if(select == 2)
{
CDetials detials;
detials.pConn = pConn;
detials.select = 0;
detials.Choice = values[cursel*colume + 1];
detials.DoModal();
}
if(select == 3)
{
CDetials detials;
detials.pConn = pConn;
detials.select = 1;
detials.Choice = values[cursel*colume + 2];
detials.DoModal();
}
if(select == 5)
{
CDetials detials;
detials.pConn = pConn;
detials.select = 2;
detials.Choice = values[cursel*colume + 1];
detials.DoModal();
}
*pResult = 0;
}
void CAllUser::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
BITMAP bitMap;
m_bitmapground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bitmapground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);
CDialog::OnPaint();
}
void CAllUser::OnLButtonDown(UINT nFlags, CPoint point)
{
if(point.x >=5 && point.x <= 65 && point.y >= 2 && point.y <=30)
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x, point.y));
CDialog::OnLButtonDown(nFlags, point);
}