📄 hourstatdlg.cpp
字号:
// HourStatDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TeacherMIS.h"
#include "HourStatDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHourStatDlg dialog
CHourStatDlg::CHourStatDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHourStatDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHourStatDlg)
m_strYearAll = _T("");
m_strTchID = _T("");
m_strTchName = _T("");
//}}AFX_DATA_INIT
CString strConnection="File Name=TeacherMIS.udl";
pDB=new CADODatabase;
pDB->Open(strConnection);
pRs=new CADORecordset(pDB);
}
void CHourStatDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHourStatDlg)
DDX_Control(pDX, IDC_LIST_ALLNUM, m_listAllNum);
DDX_Control(pDX, IDC_BUTTON_QUERY, m_btnQuery);
DDX_Text(pDX, IDC_EDIT_YEARALL, m_strYearAll);
DDX_Text(pDX, IDC_EDIT_TCHID, m_strTchID);
DDX_Text(pDX, IDC_EDIT_TCHNAME, m_strTchName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHourStatDlg, CDialog)
//{{AFX_MSG_MAP(CHourStatDlg)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHourStatDlg message handlers
BOOL CHourStatDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_listAllNum.InsertColumn(0,"所授课程名称",LVCFMT_LEFT,150,-1);
m_listAllNum.InsertColumn(1,"单门课时",LVCFMT_LEFT,80,-1);
m_listAllNum.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHourStatDlg::RefreshList(CADORecordset &recordset)
{
m_listAllNum.DeleteAllItems();
if (!recordset.IsOpen())
return;
if (recordset.GetRecordCount()<=0)
return;
recordset.MoveFirst();
CString strCourseName;
int strNum;
int indexofList=0;
while(!(recordset.IsEOF()))
{
recordset.GetFieldValue("Name",strCourseName);
recordset.GetFieldValue("AllNum",strNum);//数据类型要一样
m_listAllNum.InsertItem(indexofList,strCourseName);
strCourseName.Format("%d", strNum);
m_listAllNum.SetItemText(indexofList,1,strCourseName);
indexofList+=1;
recordset.MoveNext();
}
recordset.MoveFirst();
}
int CHourStatDlg::HaveID(CString cID)
{
CADORecordset* pRs=new CADORecordset(((CTeacherMISApp*)AfxGetApp())->pDB);
CString strSQL;
int m;
strSQL.Format("select Name,AllNum from VIEWTC where TchID='%s'",cID);
pRs->Open(strSQL,CADORecordset::openQuery);
if(pRs->GetRecordCount()>=1)
m=1;
else m=-1;
pRs->Close();
delete pRs;
return m;
}
void CHourStatDlg::OnButtonQuery()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_strTchID.IsEmpty())
{
MessageBox("请输入教师编号!");
return;
}
CHourStatDlg name;
if (name.HaveID(m_strTchID)<0)
{
MessageBox("该教师没代课!");
return;
}
CString strSQL;
strSQL.Format("select * from VIEWTC where TchID=%s",m_strTchID);
pRs->Open(strSQL,CADORecordset.openQuery);
RefreshList2(*pRs);
RefreshList(*pRs);
UpdateData(FALSE);
//List控件中首记录设为高亮状态
m_listAllNum.SetFocus();
m_listAllNum.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
}
void CHourStatDlg::RefreshList2(CADORecordset& recordset)
{
if (!recordset.IsOpen())
return;
if (recordset.GetRecordCount()<=0)
return;
recordset.MoveFirst();
CString strName;
int number=0,thenumber;
while(!(recordset.IsEOF()))
{
recordset.GetFieldValue("AllNum",thenumber);
number+= thenumber;
recordset.MoveNext();
}
recordset.MoveFirst();
m_strYearAll.Format("%d", number);
//yanjiuchulaile,kaixin,cixiboy
CADORecordset* pRs=new CADORecordset(((CTeacherMISApp*)AfxGetApp())->pDB);
strName.Format("select * from VIEWTC where TchID=%s",m_strTchID);
pRs->Open(strName,CADORecordset::openQuery);
if (recordset.IsOpen()||recordset.GetRecordCount()>=0)
pRs->GetFieldValue("Expr1",m_strTchName);
else
MessageBox("没有此记录!");
pRs->Close();
delete pRs;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -