📄 begbdview.cpp
字号:
// BegbdView.cpp : implementation of the CBegbdView class
//
#include "stdafx.h"
#include "Begbd.h"
#include "BegbdSet.h"
#include "BegbdDoc.h"
#include "BegbdView.h"
#include "AddDialog.h"
#include "DeleteDialog.h"
#include "EidtDialog.h"
#include "FindDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBegbdView
IMPLEMENT_DYNCREATE(CBegbdView, CRecordView)
BEGIN_MESSAGE_MAP(CBegbdView, CRecordView)
//{{AFX_MSG_MAP(CBegbdView)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_ALL, OnAll)
ON_BN_CLICKED(IDC_SORT, OnSort)
ON_BN_CLICKED(IDC_DELET, OnDelet)
ON_BN_CLICKED(IDC_EDIT, OnEdit)
ON_BN_CLICKED(IDC_FIND, OnFind)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBegbdView construction/destruction
CBegbdView::CBegbdView()
: CRecordView(CBegbdView::IDD)
{
//{{AFX_DATA_INIT(CBegbdView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CBegbdView::~CBegbdView()
{
}
void CBegbdView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBegbdView)
DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
//}}AFX_DATA_MAP
}
BOOL CBegbdView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CBegbdView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_begbdSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_Brush = CreateSolidBrush(RGB(30,100,60));
m_ListCtrl.SetBkColor(RGB(240,247,220));
m_ListCtrl.SetTextBkColor(RGB(200,200,80));
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_ListCtrl.InsertColumn(0,_T("学号"),LVCFMT_IMAGE|LVCFMT_LEFT);
m_ListCtrl.InsertColumn(1,_T("姓名"));
m_ListCtrl.InsertColumn(2,_T("班级"));
m_ListCtrl.InsertColumn(3,_T("英语"));
m_ListCtrl.InsertColumn(4,_T("数学"));
m_ListCtrl.InsertColumn(5,_T("计算机"));
int j;
for(j=0;j<6;j++)
{
m_ListCtrl.SetColumnWidth(j,90);
}
this->Show();
}
/////////////////////////////////////////////////////////////////////////////
// CBegbdView printing
BOOL CBegbdView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBegbdView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBegbdView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CBegbdView diagnostics
#ifdef _DEBUG
void CBegbdView::AssertValid() const
{
CRecordView::AssertValid();
}
void CBegbdView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CBegbdDoc* CBegbdView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBegbdDoc)));
return (CBegbdDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBegbdView database support
CRecordset* CBegbdView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CBegbdView message handlers
HBRUSH CBegbdView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/* HBRUSH hbr = CRecordView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
*/
return m_Brush;
}
int CBegbdView::Show()
{
int i=0;
m_pSet->MoveFirst();
do
{
CString s;
s.Format("%d",m_pSet->m_column1);
m_ListCtrl.InsertItem(i,s,0);
m_ListCtrl.SetItemText(i,1,m_pSet->m_column2);
m_ListCtrl.SetItemText(i,2,m_pSet->m_column3);
s.Format("%d",m_pSet->m_column4);
m_ListCtrl.SetItemText(i,3,s);
s.Format("%d",m_pSet->m_column5);
m_ListCtrl.SetItemText(i,4,s);
s.Format("%d",m_pSet->m_column6);
m_ListCtrl.SetItemText(i,5,s);
i++;
m_pSet->MoveNext();
}
while(!m_pSet->IsEOF());
m_pSet->MoveFirst();
return i;
}
void CBegbdView::OnAdd()
{
// TODO: Add your control notification handler code here
CAddDialog dlg;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_Xuehao==0)
{
AfxMessageBox("学号不可为零!");
}
else
{
m_pSet->AddNew();
m_pSet->m_column1=dlg.m_Xuehao;
m_pSet->m_column2=dlg.m_strName;
m_pSet->m_column3=dlg.m_Maths;
m_pSet->m_column4=dlg.m_English;
m_pSet->m_column5=dlg.m_Math;
m_pSet->m_column6=dlg.m_CPT;
m_pSet->Update();
m_pSet->Requery();
m_pSet->MoveLast();
CString s;
s.Format("%d",dlg.m_Xuehao);
m_ListCtrl.InsertItem(0,s,0);
m_ListCtrl.SetItemText(0,1,dlg.m_strName);
m_ListCtrl.SetItemText(0,2,dlg.m_Maths);
s.Format("%d",dlg.m_English);
m_ListCtrl.SetItemText(0,3,s);
s.Format("%d",dlg.m_Math);
m_ListCtrl.SetItemText(0,4,s);
s.Format("%d",dlg.m_CPT);
m_ListCtrl.SetItemText(0,5,s);
}
}
m_pSet->MoveFirst();
}
void CBegbdView::OnAll()
{
// TODO: Add your control notification handler code here
m_ListCtrl.DeleteAllItems();
this->Show();
}
void CBegbdView::OnSort()
{
// TODO: Add your control notification handler code here
m_ListCtrl.DeleteAllItems();
m_pSet->m_strSort = "[英语]";
m_pSet->Requery();
this->Show();
}
void CBegbdView::OnDelet()
{
// TODO: Add your control notification handler code here
CDeleteDialog dlg;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_Password != 1234)
AfxMessageBox("你没有权限删除记录!请重新输入密码!");
else
{
BOOL b=FALSE;
m_pSet->MoveFirst();
do
{
if(dlg.m_Xuehao != m_pSet->m_column1)
m_pSet->MoveNext();
else
{
m_ListCtrl.DeleteAllItems();
b=TRUE;
m_pSet->Delete();
m_pSet->Requery();
this->Show();
m_pSet->MoveFirst();
break;
}
}
while(!m_pSet->IsEOF());
if(b==FALSE)
AfxMessageBox("没有此记录!");
}
}
}
void CBegbdView::OnEdit()
{
// TODO: Add your control notification handler code here
CEidtDialog dlg;
if(dlg.DoModal() == IDOK)
{
if(dlg.m_Password != 1234)
AfxMessageBox("你没有权限更改记录!请重新输入密码!");
else
{
BOOL b=FALSE;
m_pSet->MoveFirst();
do
{
if(dlg.m_Xuehao!=m_pSet->m_column1)
m_pSet->MoveNext();
else
{
m_ListCtrl.DeleteAllItems();
m_pSet->Edit();
b=TRUE;
m_pSet->m_column1 = dlg.m_Xuehao;
m_pSet->m_column2 = dlg.m_strName;
m_pSet->m_column3 = dlg.m_Maths;
m_pSet->m_column4 = dlg.m_English;
m_pSet->m_column5 = dlg.m_Math;
m_pSet->m_column6 = dlg.m_CPT;
m_pSet->Update();
m_pSet->Requery();
this->Show();
m_pSet->MoveFirst();
break;
}
}while(!m_pSet->IsEOF());
if(b==FALSE)
AfxMessageBox("没有此记录");
}
}
}
void CBegbdView::OnFind()
{
// TODO: Add your control notification handler code here
BOOL k=FALSE;
CFindDialog dlg;
if(dlg.DoModal()==IDOK)
{
m_pSet->MoveFirst();
m_ListCtrl.DeleteAllItems();
do{
if(dlg.m_Xuehao != m_pSet->m_column1)
m_pSet->MoveNext();
else
{
k=TRUE;
CString s;
s.Format("%d",m_pSet->m_column1);
m_ListCtrl.InsertItem(0,s);
m_ListCtrl.SetItemText(0,1,m_pSet->m_column2);
s.Format("%s",m_pSet->m_column3);
m_ListCtrl.SetItemText(0,2,s);
s.Format("%d",m_pSet->m_column4);
m_ListCtrl.SetItemText(0,3,s);
m_pSet->MoveNext();
}
}
while(!m_pSet->IsEOF());
if(k==FALSE)
AfxMessageBox("没有符合条件的记录!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -