📄 queryresultdialog.cpp
字号:
// QueryRESULTDialog.cpp : implementation file
//
#include "stdafx.h"
#include "TestPaper.h"
#include "QueryRESULTDialog.h"
#include "MainFrm.h"
#include "ResultXgDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CQueryRESULTDialog dialog
CQueryRESULTDialog::CQueryRESULTDialog(CWnd* pParent /*=NULL*/)
: CDialog(CQueryRESULTDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CQueryRESULTDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CQueryRESULTDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CQueryRESULTDialog)
DDX_Control(pDX, IDC_QUERYLIST, m_ListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CQueryRESULTDialog, CDialog)
//{{AFX_MSG_MAP(CQueryRESULTDialog)
ON_COMMAND(ID_RESULTXG, OnResultxg)
ON_COMMAND(ID_RESULTSC, OnResultsc)
ON_COMMAND(ID_RESULTQS, OnResultqs)
ON_WM_SIZE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_NOTIFY(NM_DBLCLK,IDC_QUERYLIST, OnResultDblclickList)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQueryRESULTDialog message handlers
BOOL CQueryRESULTDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON15);
this->SendMessage(WM_SETICON,ICON_BIG,(LPARAM)hIcon);
CRect rect;
GetClientRect(rect);
m_ListCtrl.SetBkColor(RGB(192,192,192));
m_ListCtrl.SetTextColor(RGB(0,0,0));
m_ListCtrl.SetTextBkColor(RGB(192,192,192));
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
int Listwid=rect.right-rect.left;
m_ListCtrl.InsertColumn(0,_T("题目编号"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(1,_T("考试对象"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(2,_T("难度级别"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(3,_T("题目内容"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(4,_T("选项A"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(5,_T("选项B"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(6,_T("选项C"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(7,_T("选项D"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(8,_T("标准答案"),LVCFMT_CENTER,Listwid/10);
m_ListCtrl.InsertColumn(9,_T("识别号"),LVCFMT_CENTER,Listwid/10);
CDBVariant OleVar;
CString buf;
int i=0;
pMainFrame->m_queryset.MoveFirst();
//for(int j=0;j<pMainFrame->m_queryset.GetRecordCount();j++)
while(!pMainFrame->m_queryset.IsEOF())
{
int temp=0;
pMainFrame->m_queryset.GetFieldValue(temp,OleVar);
buf.Format("%d",OleVar.m_iVal);
m_ListCtrl.InsertItem(i,"");
m_ListCtrl.SetItemText(i,0,buf);
pMainFrame->m_queryset.GetFieldValue(1,OleVar);
m_ListCtrl.SetItemText(i,1,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(2,OleVar);
buf.Format("%d",OleVar.m_iVal);
m_ListCtrl.SetItemText(i,2,buf);
pMainFrame->m_queryset.GetFieldValue(3,OleVar);
m_ListCtrl.SetItemText(i,3,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(4,OleVar);
m_ListCtrl.SetItemText(i,4,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(5,OleVar);
m_ListCtrl.SetItemText(i,5,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(6,OleVar);
m_ListCtrl.SetItemText(i,6,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(7,OleVar);
m_ListCtrl.SetItemText(i,7,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(8,OleVar);
m_ListCtrl.SetItemText(i,8,OleVar.m_pstring->GetBuffer(1));
pMainFrame->m_queryset.GetFieldValue(9,OleVar);
buf.Format("%d",OleVar.m_iVal);
m_ListCtrl.SetItemText(i,9,buf);
pMainFrame->m_queryset.MoveNext();
i++;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CQueryRESULTDialog::OnResultDblclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
CPoint cMousePoint;// 鼠标位置
GetCursorPos(&cMousePoint);// 屏幕的鼠标位置,并非窗口的
POINT cListOriginPoint;
CRect cListWindowRect;
UINT uFlags;
m_ListCtrl.GetWindowRect(&cListWindowRect);
cListOriginPoint = cListWindowRect.TopLeft();
CPoint cTestPoint(cMousePoint.x - cListOriginPoint.x,cMousePoint.y - cListOriginPoint.y);
nItem = m_ListCtrl.HitTest(cTestPoint,&uFlags);
if(nItem>=0)
{
CTestPaperApp* pApp=(CTestPaperApp*) AfxGetApp();
if(pApp->enterdlg.struser!="administrator")
{
return;
}
ClientToScreen(&cTestPoint);
CMenu* pMenu=new CMenu;
pMenu->LoadMenu(IDR_MENU3);
CMenu* pFileMenu=pMenu->GetSubMenu(0);
pFileMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,cTestPoint.x,cTestPoint.y,this);
delete pMenu;
}
}
void CQueryRESULTDialog::OnResultxg()
{
// TODO: Add your command handler code here
this->ShowWindow(SW_HIDE);
CResultXgDialog resultxgdlg;
resultxgdlg.DoModal();
}
void CQueryRESULTDialog::OnResultsc()
{
// TODO: Add your command handler code here
CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
int i=nItem;
CString strSQL;
if(pMainFrame->BoolConnent==FALSE || pMainFrame->m_queryset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
if(!pMainFrame->m_queryset.CanUpdate())
return;
if(i==-1)
{
AfxMessageBox("请选择删除项!");
return;
}
else
{
if(AfxMessageBox("确实需要删除该试题吗?",MB_YESNO)==IDYES)
{
CString strSQL;
strSQL.Empty();
int keyid=atoi(m_ListCtrl.GetItemText(i,9));
strSQL.Format("delete from %s%s where 识别号=%d",pMainFrame->tempyang1,pMainFrame->tempyang2,keyid);
pMainFrame->m_database.ExecuteSQL(strSQL);
m_ListCtrl.DeleteItem(i);
pMainFrame->Refreshdata();
}
}
}
void CQueryRESULTDialog::OnResultqs()
{
// TODO: Add your command handler code here
CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
if(pMainFrame->BoolConnent==FALSE || pMainFrame->m_queryset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
if(!pMainFrame->m_queryset.CanUpdate())
return;
if(AfxMessageBox("确实需要删除全部查询试题吗?",MB_YESNO)==IDYES)
{
pMainFrame->m_queryset.MoveFirst();
while(!pMainFrame->m_queryset.IsEOF())
{
int jj=9;
CDBVariant XgVa;
pMainFrame->m_queryset.GetFieldValue(jj,XgVa);
CString strSQL;
strSQL.Format("delete from %s%s where 识别号=%d",pMainFrame->tempyang1,pMainFrame->tempyang2,XgVa.m_iVal);
pMainFrame->m_database.ExecuteSQL(strSQL);
pMainFrame->m_queryset.MoveNext();
}
m_ListCtrl.DeleteAllItems();
pMainFrame->Refreshdata();
CDialog::OnOK();
}
}
void CQueryRESULTDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CQueryRESULTDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(rect);
m_ListCtrl.MoveWindow(rect);
int Listwid=rect.right-rect.left;
m_ListCtrl.SetColumnWidth(0,Listwid/10);
m_ListCtrl.SetColumnWidth(1,Listwid/10);
m_ListCtrl.SetColumnWidth(2,Listwid/10);
m_ListCtrl.SetColumnWidth(3,Listwid/10);
m_ListCtrl.SetColumnWidth(4,Listwid/10);
m_ListCtrl.SetColumnWidth(5,Listwid/10);
m_ListCtrl.SetColumnWidth(6,Listwid/10);
m_ListCtrl.SetColumnWidth(7,Listwid/10);
m_ListCtrl.SetColumnWidth(8,Listwid/10);
m_ListCtrl.SetColumnWidth(9,Listwid/10);
// Do not call CDialog::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -