?? addrecord.cpp
字號:
// AddRecord.cpp : implementation file
//
#include "stdafx.h"
#include "cj.h"
#include "AddRecord.h"
#include "Page1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddRecord dialog
CAddRecord::CAddRecord(CWnd* pParent /*=NULL*/)
: CDialog(CAddRecord::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddRecord)
m_xueqi = _T("");
m_xuejie = _T("");
m_xibie = _T("");
m_class = _T("");
m_course = 0.0f;
m_strcmb_studentID = _T("");
//}}AFX_DATA_INIT
}
void CAddRecord::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddRecord)
DDX_Control(pDX, IDC_cmbStudentID, m_cmb_studentID);
DDX_Control(pDX, IDC_cmbKemu, m_cmb_kemu);
DDX_Text(pDX, IDC_edit_Xueqi, m_xueqi);
DDX_Text(pDX, IDC_edit_Xuejie, m_xuejie);
DDX_Text(pDX, IDC_edit_Xibie, m_xibie);
DDX_Text(pDX, IDC_edit_Class, m_class);
DDX_Text(pDX, IDC_edit_course, m_course);
DDV_MinMaxFloat(pDX, m_course, 0.f, 1000.f);
DDX_CBString(pDX, IDC_cmbStudentID, m_strcmb_studentID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddRecord, CDialog)
//{{AFX_MSG_MAP(CAddRecord)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddRecord message handlers
BOOL CAddRecord::OnInitDialog()
{
CDialog::OnInitDialog();
CDatabase m_database;
if(!m_database.Open(_T("student"))) return false;
CRecordset rs(&m_database);
//得到學界ID
strXuejie=m_xuejie;
rs.Open(CRecordset::forwardOnly,
"select 學界ID from 學界 where 學界名稱='"+strXuejie+"'");
rs.GetFieldValue("學界ID",strXuejieID);
rs.Close();
//得到系別ID
strXibie=m_xibie;
rs.Open(CRecordset::forwardOnly,
"select 系別ID from 系別 where 系別名稱='"+strXibie+"'");
rs.GetFieldValue("系別ID",strXiBieID);
rs.Close();
//得到學期ID
strXueQi=m_xueqi;
rs.Open(CRecordset::forwardOnly,
"select 學期ID from 學期 where 學期='"+strXueQi+"'");
rs.GetFieldValue("學期ID",strXueQiID);
rs.Close();
//得到班級ID
strClass=m_class;
rs.Open(CRecordset::forwardOnly,
"select 班級ID from 班級 where 班級名稱='"+strClass+"'");
rs.GetFieldValue("班級ID",strClassID);
rs.Close();
//設(shè)置考試科目的下拉框所取的值。
CString str;
rs.Open(CRecordset::forwardOnly,
"select 考試科目 from 考試科目表 where 學界ID='"+strXuejieID+"' and 系別ID='"+strXiBieID+"' and 班級ID='"+strClassID+"' and 學期ID='"+strXueQiID+"'");
while(!rs.IsEOF())
{
rs.GetFieldValue("考試科目",str);
m_cmb_kemu.AddString(str);
rs.MoveNext();
}
rs.Close();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAddRecord::OnOK()
{
UpdateData();//更新
CDatabase m_database;//連接數(shù)據(jù)源對象
//if(m_database.IsOpen())
// m_database.Close();
m_database.Open(_T("student"));
CRecordset rs(&m_database);
CAddRecord dlg;
CString strKemu,SQL,str;
int icount1,icount2;
if(m_cmb_kemu.GetCurSel()==-1)
{
MessageBox("科目不能為空","系統(tǒng)提示:",MB_ICONEXCLAMATION);
return;
}
if(m_strcmb_studentID.IsEmpty())
{
MessageBox("學號不能為空","系統(tǒng)提示:",MB_ICONEXCLAMATION);
return;
}
m_cmb_kemu.GetLBText(m_cmb_kemu.GetCurSel(),strKemu);
str.Format("%.3f",m_course);
m_strcmb_studentID.TrimLeft();
m_strcmb_studentID.TrimRight();//裁剪m_strcmb_studentID的右邊的空格
//查詢學生表,確認是否有此學生。
rs.Open(CRecordset::forwardOnly,
"select * from 學生表 where 學界ID='"+strXuejieID+"' and 系別ID='"+strXiBieID+"' and 班級ID='"+strClassID+"' and 學號ID='"+m_strcmb_studentID+"'");
icount1=rs.GetRecordCount();
rs.Close();
//查詢成績表,查看是否有此學生的這門科目的成績。
rs.Open(CRecordset::forwardOnly,
"select * from 成績表 where 學界ID='"+strXuejieID+"' and 系別ID='"+strXiBieID+"' and 班級ID='"+strClassID+"' and 學期ID='"+strXueQiID+"' and 學號ID='"+m_strcmb_studentID+"' and 考試科目名稱='"+strKemu+"'");
icount2=rs.GetRecordCount();
rs.Close();
if(icount1==0)
{
MessageBox("數(shù)據(jù)庫中不存在此學生的信息!","系統(tǒng)提示:",MB_ICONEXCLAMATION);
return;
}
else
{
if(icount2==0)
{
SQL="insert into 成績表 (學界ID,系別ID,班級ID,學期ID,學號ID,考試科目名稱,成績) \
values('"+strXuejieID+"','"+strXiBieID+"','"+strClassID+"','"+strXueQiID+"','"+m_strcmb_studentID+"','"+strKemu+"','"+str+"')";
m_database.ExecuteSQL(SQL);
m_database.Close();
}
else
{
MessageBox("數(shù)據(jù)庫中已經(jīng)有此學生此門科目的成績了!","系統(tǒng)提示:",MB_ICONEXCLAMATION);
return;
}
}
CDialog::OnOK();
}
void CAddRecord::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -