📄 ex6view.cpp
字号:
// ex6View.cpp : implementation of the CEx6View class
//
#include "stdafx.h"
#include "ex6.h"
#include "ex6Doc.h"
#include "ex6View.h"
#include "ClassInfoSet.h"
#include "ClassInfoDlg.h"
#include "SeekClassDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx6View
IMPLEMENT_DYNCREATE(CEx6View, CScrollView)
BEGIN_MESSAGE_MAP(CEx6View, CScrollView)
//{{AFX_MSG_MAP(CEx6View)
ON_COMMAND(ID_CLASSINFO_ADD, OnClassinfoAdd)
ON_COMMAND(ID_CLASSINFO_SEEK, OnClassinfoSeek)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEx6View construction/destruction
LOGFONT m_lfFont;
CString m_strClassNO;
CString m_strSQL;
CEx6View::CEx6View()
{
// TODO: add construction code here
memset(&m_lfFont,0,sizeof(LOGFONT));
m_lfFont.lfHeight=12;
m_lfFont.lfCharSet=GB2312_CHARSET;
strcpy(m_lfFont.lfFaceName,"宋体");
m_strClassNO=m_strSQL="";
}
CEx6View::~CEx6View()
{
}
BOOL CEx6View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx6View drawing
void CEx6View::OnDraw(CDC* pDC)
{
CEx6Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CFont font;
font.CreateFontIndirect(&m_lfFont);
CFont *oldFont = pDC->SelectObject(&font);
DispClassInfo(pDC,m_strClassNO,m_strSQL);
pDC->SelectObject(oldFont);
}
void CEx6View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CEx6View printing
BOOL CEx6View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx6View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx6View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CEx6View::DispClassInfo(CDC *pDC,CString strClass,CString strSQL)
{
CFont font;
LOGFONT lf=m_lfFont;
lf.lfWeight=700;
strcpy(lf.lfFaceName,"幼圆");
font.CreateFontIndirect(&lf);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int nLineHeight=(int)((tm.tmHeight+tm.tmExternalLeading)*1.5);
int x=0,y=0,nWidth;
CFont *oldFont = pDC->SelectObject(&font);
CString strHeader[]={"班级号","所在院系","专业名称","学制","入学时间"};
int nStrWidth[]={10,25,25,8,10};
CClassInfoSet cSet;
cSet.m_strFilter=strSQL;
cSet.Open();
for(UINT i=0;i<cSet.m_nFields;i++)
{
nWidth=tm.tmAveCharWidth*nStrWidth[i];
pDC->TextOut(x,y,strHeader[i]);
x +=nWidth;
}
pDC->SelectObject(oldFont);
CString str;
while(!cSet.IsEOF())
{
if(strClass==cSet.m_classno){
lf.lfWeight=0;
strcpy(lf.lfFaceName,"楷体_GB2312"/*宋体_GB2312*/);
font.DeleteObject();
font.CreateFontIndirect(&lf);
pDC->SelectObject(&font);
}else
pDC->SelectObject(oldFont);
x=0;y+=nLineHeight;
for(UINT i=0;i<cSet.m_nFields;i++){
cSet.GetFieldValue(i,str);
nWidth=tm.tmAveCharWidth*nStrWidth[i];
pDC->TextOut(x,y,str);
x+=nWidth;
}
cSet.MoveNext();
}
cSet.Close();
CSize sizeTotal;
sizeTotal.cx=x + nWidth; sizeTotal.cy=y + nLineHeight;
SetScrollSizes(MM_TEXT,sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CEx6View diagnostics
#ifdef _DEBUG
void CEx6View::AssertValid() const
{
CScrollView::AssertValid();
}
void CEx6View::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CEx6Doc* CEx6View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx6Doc)));
return (CEx6Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx6View message handlers
void CEx6View::OnClassinfoAdd()
{
// TODO: Add your command handler code here
CClassInfoDlg dlg;
if(dlg.DoModal()!=IDOK)return;
CClassInfoSet infoSet;
infoSet.m_strFilter.Format("classno='%s' AND depart='%s' AND special='%s'",
dlg.m_strClassNO,dlg.m_strDepart,dlg.m_strSpecial);
infoSet.Open();
if(!infoSet.IsEOF()){
MessageBox(dlg.m_strClassNO+"班级记录已添加过!");
if(infoSet.IsOpen()) infoSet.Close();
return;
}
if(infoSet.IsOpen())infoSet.Close();
CClassInfoSet addSet;
if(addSet.Open()){
addSet.AddNew();
addSet.m_classno=dlg.m_strClassNO;
addSet.m_depart=dlg.m_strDepart;
addSet.m_entertime=dlg.m_tEnter;
addSet.m_special=dlg.m_strSpecial;
addSet.m_studyyear=(float)atof(dlg.m_strYear);
addSet.Update();
addSet.Requery();
}
if(addSet.IsOpen())addSet.Close();
m_strClassNO=dlg.m_strClassNO;
m_strSQL="";
MessageBox("稍等片刻,单击[确定]按钮!",
"特别提示",MB_OK|MB_ICONINFORMATION);
Invalidate();
}
void CEx6View::OnClassinfoSeek()
{
// TODO: Add your command handler code here
CSeekClassDlg dlg;
if(dlg.DoModal()==IDOK){
m_strClassNO="";
m_strSQL=dlg.m_strSQL;
Invalidate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -