📄 s2009072032view.cpp
字号:
// S2009072032View.cpp : implementation of the CS2009072032View class
//
#include "stdafx.h"
#include "S2009072032.h"
#include "MainFrm.h"
#include "S2009072032Doc.h"
#include "S2009072032View.h"
//#include "string.h"
#include "StudentSet.h"
#include "ScoreSet.h"
#include "CourseSet.h"
#include "StuInfoDlg.h"
#include "ScoreDlg.h"
#include "CourseDlg.h"
#include "QueryDlg.h"
#include "StatisticDlg.h"
#include "DrawDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CS2009072032View
IMPLEMENT_DYNCREATE(CS2009072032View, CListView)
BEGIN_MESSAGE_MAP(CS2009072032View, CListView)
//{{AFX_MSG_MAP(CS2009072032View)
ON_COMMAND(ID_OP_ADD, OnOpAdd)
ON_COMMAND(ID_OP_DELETE, OnOpDelete)
ON_COMMAND(ID_OP_MODIFY, OnOpModify)
ON_COMMAND(ID_OP_QUERY, OnOpQuery)
ON_COMMAND(ID_OP_STATISTIC, OnOpStatistic)
ON_COMMAND(ID_SELDATA_COURSEINFO, OnSeldataCourseinfo)
ON_COMMAND(ID_SELDATA_STUINFO, OnSeldataStuinfo)
ON_COMMAND(ID_SELDATA_STUSCORE, OnSeldataStuscore)
ON_WM_CONTEXTMENU()
ON_UPDATE_COMMAND_UI(ID_SELDATA_COURSEINFO, OnUpdateSeldataCourseinfo)
ON_UPDATE_COMMAND_UI(ID_SELDATA_STUINFO, OnUpdateSeldataStuinfo)
ON_UPDATE_COMMAND_UI(ID_SELDATA_STUSCORE, OnUpdateSeldataStuscore)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CS2009072032View construction/destruction
CS2009072032View::CS2009072032View()
{
// TODO: add construction code here
this->m_nSelTable=0;
}
CS2009072032View::~CS2009072032View()
{
}
BOOL CS2009072032View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style&=~LVS_TYPEMASK; //*
cs.style|=LVS_REPORT; //*
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CS2009072032View drawing
void CS2009072032View::OnDraw(CDC* pDC)
{
CS2009072032Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CS2009072032View::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CS2009072032View printing
BOOL CS2009072032View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CS2009072032View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CS2009072032View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CS2009072032View diagnostics
#ifdef _DEBUG
void CS2009072032View::AssertValid() const
{
CListView::AssertValid();
}
void CS2009072032View::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CS2009072032Doc* CS2009072032View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CS2009072032Doc)));
return (CS2009072032Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CS2009072032View message handlers
void CS2009072032View::DispAllRec(int nTable, int nField, CString strFilter)
{
//用于基于CListView的视图类。
//nTable==1时为student表,2为score表,3为course表。
//nField是用于排序的字段索引号。
CRecordset *cSet;
if(nTable==1)
cSet=new CStudentSet();
else if(nTable==2)
cSet=new CScoreSet();
else if(nTable==3)
cSet=new CCourseSet();
else
return;
CListCtrl& m_ListCtrl=this->GetListCtrl();
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//删除列表中所有行和列表头
m_ListCtrl.DeleteAllItems();
int nColumnCount=m_ListCtrl.GetHeaderCtrl()->GetItemCount();
for(int j=0; j<nColumnCount; j++)
m_ListCtrl.DeleteColumn(0);
cSet->Open(); //打开记录集
CODBCFieldInfo field;
int nWidth;
CString strField, strName;
//创建列表头
for(UINT i=0; i<cSet->m_nFields; i++){
cSet->GetODBCFieldInfo(i, field);
strName=field.m_strName;
nWidth=field.m_nPrecision*9; //计算列宽
if(nWidth<strName.GetLength()*9)
nWidth=strName.GetLength()*9;
if(nWidth<40)
nWidth=40;
m_ListCtrl.InsertColumn(i, strName, LVCFMT_LEFT, nWidth);
if(i==(UINT)nField)
strField=field.m_strName;
}
cSet->Close();
if(!strField.IsEmpty()) //按字段打开记录集,然后添加列表项
cSet->m_strSort=strField;
cSet->m_strFilter=strFilter;
cSet->Open();
int nItem=0;
CString str;
while(!cSet->IsEOF()){
for(UINT i=0; i<cSet->m_nFields; i++){
cSet->GetFieldValue(i, str);
if(i==0)
m_ListCtrl.InsertItem(nItem, str);
else
m_ListCtrl.SetItemText(nItem, i, str);
}
nItem++;
cSet->MoveNext();
}
cSet->Close(); //关闭记录集
if(cSet) //释放内存空间
delete cSet;
}
void CS2009072032View::OnOpAdd()
{
// TODO: Add your command handler code here
if(this->m_nSelTable==0)
{
MessageBox("请先选择数据!");
return;
}
CStuInfoDlg stuDlg;
CStudentSet stuSet;
CScoreDlg scoreDlg;
CScoreSet scoreSet;
CCourseSet courseSet;
CCourseDlg courseDlg;
switch(this->m_nSelTable)
{
case 1:
stuDlg.m_strOKText="添加";
stuSet.Open();
if(stuDlg.DoModal()==IDOK)
{
stuSet.AddNew();
stuSet.m_studentname=stuDlg.m_strName;
stuSet.m_studentno=stuDlg.m_strNO;
stuSet.m_special=stuDlg.m_strSpec;
stuSet.m_birthday=stuDlg.m_tBirth;
if(stuDlg.m_strSex=="男")
stuSet.m_xb=1;
else if(stuDlg.m_strSex=="女")
stuSet.m_xb=0;
stuSet.Update();
}
stuSet.Close();
this->OnSeldataStuinfo();
break;
case 2:
scoreDlg.m_strOKText="添加";
scoreSet.Open();
if(scoreDlg.DoModal()==IDOK)
{
scoreSet.AddNew();
scoreSet.m_studentno=scoreDlg.m_strStuNO;
scoreSet.m_course=scoreDlg.m_strCourseNO;
scoreSet.m_score=scoreDlg.m_fScore;
scoreSet.m_credit=scoreDlg.m_fCredit;
scoreSet.Update();
}
scoreSet.Close();
this->OnSeldataStuscore();
break;
case 3:
courseDlg.m_strOKText="添加";
courseSet.Open();
if(courseDlg.DoModal()==IDOK)
{
courseSet.AddNew();
courseSet.m_courseno=courseDlg.m_courseNO;
courseSet.m_coursename=courseDlg.m_coursename;
courseSet.m_coursetype=courseDlg.m_coursetype;
courseSet.m_credit=courseDlg.m_credit;
courseSet.m_hours=courseDlg.m_studyhours;
courseSet.m_openterm=(char)atoi(courseDlg.m_term);
courseSet.m_special=courseDlg.m_major;
courseSet.Update();
}
courseSet.Close();
this->OnSeldataCourseinfo();
break;
}
}
void CS2009072032View::OnOpDelete()
{
// TODO: Add your command handler code here
CListCtrl &m_ListCtrl=this->GetListCtrl();
POSITION posSel=m_ListCtrl.GetFirstSelectedItemPosition();
int nSelItem=-1;
if(posSel==NULL)
{
MessageBox("还没有选择一个记录!");
return;
}
else
nSelItem=m_ListCtrl.GetNextSelectedItem(posSel);
CStudentSet stuSet;
CScoreSet scoreSet;
CCourseSet courseSet;
char strSel[80];
switch(this->m_nSelTable)
{
case 1:
m_ListCtrl.GetItemText(nSelItem, 1, strSel, 11);
stuSet.Open();
while(!stuSet.IsEOF())
{
if(!strcmp(stuSet.m_studentno, strSel))
{
stuSet.Delete();
break;
}
stuSet.MoveNext();
}
stuSet.Close();
this->OnSeldataStuinfo();
break;
case 2:
m_ListCtrl.GetItemText(nSelItem, 0, strSel, 9);
scoreSet.Open();
while(!scoreSet.IsEOF())
{
if(!strcmp(scoreSet.m_studentno, strSel))
{
scoreSet.Delete();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -