📄 stupage1.cpp
字号:
// StuPage1.cpp : implementation file
//
#include "stdafx.h"
#include "SCMIS.h"
#include "StuPage1.h"
#include"CCourseSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CDatabase db;
#include"StuProSht.h"
/////////////////////////////////////////////////////////////////////////////
// CStuPage1 property page
IMPLEMENT_DYNCREATE(CStuPage1, CPropertyPage)
CStuPage1::CStuPage1() : CPropertyPage(CStuPage1::IDD)
{
//{{AFX_DATA_INIT(CStuPage1)
m_name = _T("");
m_teacher = _T("");
m_score = 0;
m_hour = 0;
m_where = _T("");
m_intro = _T("");
m_when = _T("");
//}}AFX_DATA_INIT
rs=new CCcourseSet(&db);
}
CStuPage1::~CStuPage1()
{
}
void CStuPage1::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStuPage1)
DDX_Control(pDX, IDC_LIST1, m_course);
DDX_Text(pDX, IDC_EDIT1, m_name);
DDX_Text(pDX, IDC_EDIT2, m_teacher);
DDX_Text(pDX, IDC_EDIT4, m_score);
DDX_Text(pDX, IDC_EDIT8, m_hour);
DDX_Text(pDX, IDC_EDIT5, m_where);
DDX_Text(pDX, IDC_EDIT7, m_intro);
DDX_Text(pDX, IDC_EDIT6, m_when);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStuPage1, CPropertyPage)
//{{AFX_MSG_MAP(CStuPage1)
ON_BN_CLICKED(IDC_FIRST, OnFirst)
ON_BN_CLICKED(IDC_PREV, OnPrev)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_LAST, OnLast)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStuPage1 message handlers
void CStuPage1::OnFirst()
{
// TODO: Add your control notification handler code here
rs->MoveFirst();
OnMove();
this->UpdateData(FALSE);
}
void CStuPage1::OnPrev()
{
// TODO: Add your control notification handler code here
if(!rs->IsBOF())
{
rs->MovePrev();
OnMove();
}
}
void CStuPage1::OnNext()
{
// TODO: Add your control notification handler code here
if(!rs->IsEOF())
{
rs->MoveNext();
OnMove();
}
}
void CStuPage1::OnLast()
{
// TODO: Add your control notification handler code here
rs->MoveLast();
OnMove();
}
void CStuPage1::OnMove()
{ this->m_hour=rs->m_PERIOD;
this->m_intro=rs->m_INTRO;
this->m_name=rs->m_NAME;
this->m_score=rs->m_CREDIT_HOUR;
this->m_teacher=rs->m_TEACHER;
this->m_when=rs->m_CLASSTIME;
this->m_where=rs->m_CLASSROOM;
this->UpdateData(FALSE);
}
void CStuPage1::OnButtonDelete()
{
// TODO: Add your control notification handler code here
int j=m_course.GetSelectionMark();
CString strSQL;
if(j==-1)
MessageBox("请首先选择一条记录");
else{
CString ct=m_course.GetItemText(j,0);
strSQL.Format("delete from sc where corid='%s'",ct);
db.ExecuteSQL(strSQL);
CStuProSht *m_dlg;
m_dlg=(CStuProSht*)this->GetParent();
this->m_stuid=m_dlg->m_id;
FreshData();
m_dlg->m_page2.RefreshData();
}
}
void CStuPage1::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CStuPage1::FreshData()
{
CRecordset rs1(&db);
m_course.DeleteAllItems();
rs1.Open(CRecordset::forwardOnly,"select course.id ,course.name from course,sc where course.id=sc.corid and sc.stuid='"+m_stuid+"' order by course.id");
char buf[20];
int i=0;
CDBVariant varValue;
while(!rs1.IsEOF())
{
int temp=0;
rs1.GetFieldValue(temp,varValue);
//sprintf(buf,"%d",varValue.m_lVal); m_course.InsertItem(i,buf);//if is int type ,write this way
sprintf(buf,"%s",varValue.m_pstring->GetBuffer(1)); m_course.InsertItem(i,buf);
//m_course.SetItemText(i,0,varValue.m_pstring->GetBuffer(1));
rs1.GetFieldValue(1,varValue);
m_course.SetItemText(i,1,varValue.m_pstring->GetBuffer(1));
rs1.MoveNext();
i++;
}
rs1.Close();
}
void CStuPage1::OnButtonAdd()
{
// TODO: Add your control notification handler code here
CString m_r0=rs->m_ID;
CString m_r1=rs->m_NAME;
CString strSQL;
//m_stuid="1";
CStuProSht *m_dlg;
m_dlg=(CStuProSht*)this->GetParent();
this->m_stuid=m_dlg->m_id;
CRecordset rs(&db);
strSQL.Format("select * from sc where stuid='%s' and corid='%s'",m_stuid,m_r0);
rs.Open(CRecordset::forwardOnly,strSQL);
if(rs.GetRecordCount()==0)
{
strSQL.Format("insert into sc(stuid,corid) values( '%s','%s') ",m_stuid,m_r0);
db.ExecuteSQL(strSQL);
FreshData();
m_dlg->m_page2.RefreshData();
}
}
BOOL CStuPage1::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
m_course.InsertColumn(0,"课程编号");
m_course.InsertColumn(1,"课程名称");
RECT rect;
m_course.GetWindowRect(&rect);
int wid=rect.right-rect.left;
m_course.SetColumnWidth(0,wid/2);
m_course.SetColumnWidth(1,wid/2);
m_course.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_course.SetTextBkColor(RGB(192,192,0));
m_course.SetTextColor(RGB(0,0,255));
CString strSQL;
strSQL.Format("select * from COURSE ");
rs->Open(AFX_DB_USE_DEFAULT_TYPE/*CRecordset::forwardOnly*/,strSQL);
rs->MoveFirst();
this->m_hour=rs->m_PERIOD;
this->m_intro=rs->m_INTRO;
this->m_name=rs->m_NAME;
this->m_score=rs->m_CREDIT_HOUR;
this->m_teacher=rs->m_TEACHER;
this->m_when=rs->m_CLASSTIME;
this->m_where=rs->m_CLASSROOM;
CStuProSht *m_dlg;
m_dlg=(CStuProSht*)this->GetParent();
this->m_stuid=m_dlg->m_id;
this->UpdateData(FALSE);
FreshData();
return TRUE;
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -