📄 teachermisview.cpp
字号:
// TeacherMISView.cpp : implementation of the CTeacherMISView class
//
#include "stdafx.h"
#include "TeacherMIS.h"
#include "TeacherMISDoc.h"
#include "TeacherMISView.h"
#include "AddTeacherDlg.h"
#include "ModifyDlg.h"
#include "CountDlg.h"
#include "QueryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTeacherMISView
IMPLEMENT_DYNCREATE(CTeacherMISView, CFormView)
BEGIN_MESSAGE_MAP(CTeacherMISView, CFormView)
//{{AFX_MSG_MAP(CTeacherMISView)
ON_BN_CLICKED(IDC_BUTTON_ALL, OnButtonAll)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
ON_BN_CLICKED(IDC_BUTTON_SPC, OnButtonSpc)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTeacherMISView construction/destruction
CTeacherMISView::CTeacherMISView()
: CFormView(CTeacherMISView::IDD)
{
//{{AFX_DATA_INIT(CTeacherMISView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CTeacherMISView::~CTeacherMISView()
{
}
void CTeacherMISView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTeacherMISView)
DDX_Control(pDX, IDC_LIST_TEACHER, m_listTeacher);
//}}AFX_DATA_MAP
}
BOOL CTeacherMISView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CTeacherMISView::OnInitialUpdate()
{
CString strConnection="File Name=my_data.udl";
pDB=new CADODatabase;
pDB->Open(strConnection);
pRs=new CADORecordset(pDB);
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_listTeacher.InsertColumn(0,"编号",LVCFMT_LEFT,40,-1);
m_listTeacher.InsertColumn(1,"姓名",LVCFMT_LEFT,60,-1);
m_listTeacher.InsertColumn(2,"职工分类",LVCFMT_LEFT,80,-1);
m_listTeacher.InsertColumn(3,"性别",LVCFMT_LEFT,60,-1);
m_listTeacher.InsertColumn(4,"年龄",LVCFMT_LEFT,40,-1);
m_listTeacher.InsertColumn(5,"职务",LVCFMT_LEFT,60,-1);
m_listTeacher.InsertColumn(6,"职称",LVCFMT_LEFT,60,-1);
m_listTeacher.InsertColumn(7,"政治面貌",LVCFMT_LEFT,80,-1);
m_listTeacher.InsertColumn(8,"学历",LVCFMT_LEFT,60,-1);
m_listTeacher.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);
}
/////////////////////////////////////////////////////////////////////////////
// CTeacherMISView printing
BOOL CTeacherMISView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTeacherMISView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTeacherMISView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CTeacherMISView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CTeacherMISView diagnostics
#ifdef _DEBUG
void CTeacherMISView::AssertValid() const
{
CFormView::AssertValid();
}
void CTeacherMISView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CTeacherMISDoc* CTeacherMISView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTeacherMISDoc)));
return (CTeacherMISDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTeacherMISView message handlers
void CTeacherMISView::RefreshList(CADORecordset &recordset)
{
m_listTeacher.DeleteAllItems();
if(!(recordset.IsOpen()))
return;
if(recordset.GetRecordCount()<=0)
return;
recordset.MoveFirst();
CString strId,strAge,strName,strKind,strSex,strPost,strJobTitle,strOrientation,strEducation;
int indexofList=0;
while(!(recordset.IsEOF()))
{
recordset.GetFieldValue("id",strId);
recordset.GetFieldValue("name",strName);
recordset.GetFieldValue("kind",strKind);
recordset.GetFieldValue("sex",strSex);
recordset.GetFieldValue("age",strAge);
recordset.GetFieldValue("post",strPost);
recordset.GetFieldValue("job_title",strJobTitle);
recordset.GetFieldValue("orientation",strOrientation);
recordset.GetFieldValue("education",strEducation);
m_listTeacher.InsertItem(indexofList,strId);
m_listTeacher.SetItemText(indexofList,1,strName);
m_listTeacher.SetItemText(indexofList,2,strKind);
m_listTeacher.SetItemText(indexofList,3,strSex);
m_listTeacher.SetItemText(indexofList,4,strAge);
m_listTeacher.SetItemText(indexofList,5,strPost);
m_listTeacher.SetItemText(indexofList,6,strJobTitle);
m_listTeacher.SetItemText(indexofList,7,strOrientation);
m_listTeacher.SetItemText(indexofList,8,strEducation);
indexofList+=1;
recordset.MoveNext();
}
recordset.MoveFirst();
}
void CTeacherMISView::OnButtonAll()
{
//MessageBox("erroe");
pRs->Open("select * from info",CADORecordset.openQuery);
RefreshList(*pRs);
m_listTeacher.SetFocus();
m_listTeacher.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
}
void CTeacherMISView::OnButtonAdd()
{
CAddTeacherDlg addTeacher;
addTeacher.DoModal();
pRs->Open("select * from info",CADORecordset.openQuery);
RefreshList(*pRs);
m_listTeacher.SetFocus();
m_listTeacher.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
}
void CTeacherMISView::OnButtonDelete()
{
int sel=m_listTeacher.GetSelectionMark();
if(sel<0)
{
MessageBox("没有选择删除的记录!");
return;
}
CString strID=m_listTeacher.GetItemText(sel,0);
CString strSQL="delete from info where id="+strID;
pDB->Execute(strSQL);
//pRs->Open("select * from info",CADORecordset.openQuery);
pRs->Requery(adConnectUnspecified);
RefreshList(*pRs);
m_listTeacher.SetFocus();
m_listTeacher.SetItemState(sel,LVIS_SELECTED,LVIS_SELECTED);
}
void CTeacherMISView::OnButtonModify()
{
int sel=m_listTeacher.GetSelectionMark();
if(sel<0)
{
MessageBox("没有选择修改的记录!");
return;
}
CString strID=m_listTeacher.GetItemText(sel,0);
CModifyDlg modify;
modify.setID(strID);
modify.DoModal();
if(pRs->IsOpen())
pRs->Requery(adConnectUnspecified);
else
pRs->Open("select * from info",CADORecordset.openQuery);
RefreshList(*pRs);
m_listTeacher.SetFocus();
m_listTeacher.SetItemState(sel,LVIS_SELECTED,LVIS_SELECTED);
}
void CTeacherMISView::OnButtonSpc()
{
CString onjob,doctor,master,develop,female,party;
pRs->Open("select * from info where kind!='退休人员'",CADORecordset.openQuery);
onjob.Format("%d",pRs->GetRecordCount());
pRs->Open("select * from info where education='博士'",CADORecordset.openQuery);
doctor.Format("%d",pRs->GetRecordCount());
pRs->Open("select * from info where education='硕士'",CADORecordset.openQuery);
master.Format("%d",pRs->GetRecordCount());
pRs->Open("select * from info where job_title='高级'",CADORecordset.openQuery);
develop.Format("%d",pRs->GetRecordCount());
pRs->Open("select * from info where sex='女'",CADORecordset.openQuery);
female.Format("%d",pRs->GetRecordCount());
pRs->Open("select * from info where orientation='中共党员'",CADORecordset.openQuery);
party.Format("%d",pRs->GetRecordCount());
CCountDlg count;
count.setOnjob(onjob);
count.setDoctor(doctor);
count.setMaster(master);
count.setDevelop(develop);
count.setFemale(female);
count.setParty(party);
count.DoModal();
}
void CTeacherMISView::OnButtonQuery()
{
CString strQuery;
CQueryDlg query;
query.DoModal();
strQuery=query.getStrQuery();
//MessageBox(strQuery);
pRs->Open("select * from info where 1=1 "+strQuery,CADORecordset.openQuery);
RefreshList(*pRs);
m_listTeacher.SetFocus();
m_listTeacher.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -