📄 xz.cpp
字号:
// XZ.cpp : implementation file
//
#include "stdafx.h"
#include "成绩管理系统.h"
#include "成绩管理系统Dlg.h"
#include "XZ.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString xzyhm,xzmm;
/////////////////////////////////////////////////////////////////////////////
// XZ dialog
XZ::XZ(CWnd* pParent /*=NULL*/)
: CDialog(XZ::IDD, pParent)
{
//{{AFX_DATA_INIT(XZ)
m_pscj = 0.0f;
m_kscj = 0.0f;
m_kcm = _T("");
m_rkls = _T("");
m_xf = 0.0f;
m_nl = 0;
m_szx = _T("");
m_xb = _T("");
m_xm = _T("");
m_bk = FALSE;
m_cx = FALSE;
m_xh = _T("");
m_kch = _T("");
//}}AFX_DATA_INIT
}
void XZ::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(XZ)
DDX_Control(pDX, IDC_XZCJ_KCH, m_KCH);
DDX_Control(pDX, IDC_XZCJ_XH, m_XH);
DDX_Control(pDX, IDC_XZCJ_CX, m_CX);
DDX_Control(pDX, IDC_XZCJ_BK, m_BK);
DDX_Control(pDX, IDC_XZSTU_XM, m_XM);
DDX_Control(pDX, IDC_XZSTU_XB, m_XB);
DDX_Control(pDX, IDC_XZSTU_SZX, m_SZX);
DDX_Control(pDX, IDC_XZSTU_NL, m_NL);
DDX_Control(pDX, IDC_XZKC_XF, m_XF);
DDX_Control(pDX, IDC_XZKC_RKLS, m_RKLS);
DDX_Control(pDX, IDC_XZKC_CKM, m_KCM);
DDX_Control(pDX, IDC_XZCJ_KSCJ, m_KSCJ);
DDX_Control(pDX, IDC_XZCJ_PSCJ, m_PSCJ);
DDX_Text(pDX, IDC_XZCJ_PSCJ, m_pscj);
DDX_Text(pDX, IDC_XZCJ_KSCJ, m_kscj);
DDX_Text(pDX, IDC_XZKC_CKM, m_kcm);
DDX_Text(pDX, IDC_XZKC_RKLS, m_rkls);
DDX_Text(pDX, IDC_XZKC_XF, m_xf);
DDX_Text(pDX, IDC_XZSTU_NL, m_nl);
DDX_Text(pDX, IDC_XZSTU_SZX, m_szx);
DDX_Text(pDX, IDC_XZSTU_XB, m_xb);
DDX_Text(pDX, IDC_XZSTU_XM, m_xm);
DDX_Check(pDX, IDC_XZCJ_BK, m_bk);
DDX_Check(pDX, IDC_XZCJ_CX, m_cx);
DDX_CBString(pDX, IDC_XZCJ_XH, m_xh);
DDX_CBString(pDX, IDC_XZCJ_KCH, m_kch);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(XZ, CDialog)
//{{AFX_MSG_MAP(XZ)
ON_WM_DESTROY()
ON_WM_CANCELMODE()
ON_BN_CLICKED(IDC_XZSTU_TJ, OnXzstuTj)
ON_WM_CAPTURECHANGED()
ON_BN_CLICKED(IDC_XZSTU_QX, OnXzstuQx)
ON_BN_CLICKED(IDC_XZKC_TJ, OnXzkcTj)
ON_BN_CLICKED(IDC_XZCK_QX, OnXzckQx)
ON_BN_CLICKED(IDC_XZCJ_TJ, OnXzcjTj)
ON_BN_CLICKED(IDC_XZCJ_QX, OnXzcjQx)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// XZ message handlers
void XZ::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void XZ::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
void XZ::OnXzstuTj()
{
UpdateData();
int i=1000;
if(m_xm=="")
{
AfxMessageBox("姓名不能为空!");
return;
}
_RecordsetPtr prst=NULL;
prst.CreateInstance(__uuidof(Recordset));
CString xm,xb,nl,szx,strSql,strsql;
m_XM.GetWindowText(xm);
m_XB.GetWindowText(xb);
m_NL.GetWindowText(nl);
m_SZX.GetWindowText(szx);
/*
strsql.Format("select 学号 from v_student");
prst=m_DBCnt->Execute(_bstr_t(strsql),NULL,adCmdText);
_variant_t holder;
if(!prst->adoEOF)
prst->MoveFirst();
while(!prst->adoEOF)
{
holder=prst->GetCollect("学号");
if(holder.intVal==i)
{
i++;
}
else break;
prst->MoveNext();
}*/
try
{
strSql.Format("INSERT INTO v_student(姓名,性别,年龄,所在系) VALUES('%s','%s',%d,'%s')",xm,xb,atoi(nl),szx);
prst=m_DBCnt->Execute(_bstr_t(strSql),NULL,adCmdText);
MessageBox("添加成功!");
}
catch(_com_error&e)
{
AfxMessageBox("操作异常或者是你所在的用户组无此权限!");
return;
}
}
BOOL XZ::OnInitDialog()
{
CDialog::OnInitDialog();
::CoInitialize(NULL);
// TODO: Add extra initialization here
// xzyhm=yhm;
// xzmm=mm;
xzyhm=zyhm;
xzmm=zmm;
try
{
m_DBCnt.CreateInstance(__uuidof(Connection));
CString strCn;
strCn.Empty();
strCn="driver={SQL Server};server=(local);"
+xzyhm
+";"+xzmm
+";database=StuGrade";
m_DBCnt->Open(_bstr_t(strCn),_bstr_t(""),_bstr_t(""),-1);
}
catch(_com_error&e)
{
AfxMessageBox("无法连接数据库!");
this->EndDialog(0);
}
m_bk=false;
m_cx=false;
Readstuxh();
Readcourkch();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void XZ::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here
CDialog::OnCaptureChanged(pWnd);
}
void XZ::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void XZ::OnXzstuQx()
{
// TODO: Add your control notification handler code here
m_XM.SetWindowText("");
m_XB.SetWindowText("");
m_NL.SetWindowText("");
m_SZX.SetWindowText("");
}
void XZ::OnXzkcTj()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_kcm=="")
{
AfxMessageBox("课程名不能为空!");
return;
}
_RecordsetPtr prst=NULL;
prst.CreateInstance(__uuidof(Recordset));
CString kcm,rkls,xf,strSql;
m_KCM.GetWindowText(kcm);
m_RKLS.GetWindowText(rkls);
m_XF.GetWindowText(xf);
try
{
strSql.Format("INSERT INTO v_course(课程名,任课老师,学分) VALUES('%s','%s',%f)",kcm,rkls,atof(xf));
prst=m_DBCnt->Execute(_bstr_t(strSql),NULL,adCmdText);
MessageBox("添加成功!");
}
catch(_com_error&e)
{
AfxMessageBox("操作异常或者是你所在的用户组无此权限!");
return;
}
}
void XZ::OnXzckQx()
{
// TODO: Add your control notification handler code here
m_KCM.SetWindowText("");
m_RKLS.SetWindowText("");
m_XF.SetWindowText("");
}
void XZ::OnXzcjTj()
{
// TODO: Add your control notification handler code here
UpdateData();
CString xh,kch,strsql;
m_XH.GetWindowText(xh);
m_KCH.GetWindowText(kch);
if(xh=="")
{
AfxMessageBox("学号不能为空!");
return;
}
if(kch=="")
{
AfxMessageBox("课程号不能为空!");
return;
}
_RecordsetPtr prst=NULL;
prst.CreateInstance(__uuidof(Recordset));
CString kscj,pscj,strSql;
int bk,cx;
float zpcj;
m_KSCJ.GetWindowText(kscj);
m_PSCJ.GetWindowText(pscj);
zpcj=atof(kscj)+atof(pscj);
if(m_BK.GetCheck())bk=1;
else bk=0;
if(m_CX.GetCheck())cx=1;
else cx=0;
if(bk==1&&cx==1)
{
AfxMessageBox("补考重修不能同时选上!");
return;
}
try
{
strsql.Format("select 学号,课程号 from v_sc");
prst=m_DBCnt->Execute(_bstr_t(strsql),NULL,adCmdText);
_variant_t holder1,holder2;
if(!prst->adoEOF)
prst->MoveFirst();
while(!prst->adoEOF)
{
holder1=prst->GetCollect("学号");
holder2=prst->GetCollect("课程号");
if(holder1.intVal==atoi(xh)&&holder2.intVal==atoi(kch))
{
AfxMessageBox("该成绩已存在,请重新操作!");
return;
}
prst->MoveNext();
}
strSql.Format("insert into v_sc(学号,课程号,考试成绩,平时成绩,总评成绩,补考,重修) values(%d,%d,%f,%f,%f,%d,%d)",atoi(xh),atoi(kch),atof(kscj),atof(pscj),zpcj,bool(bk),bool(cx));
prst=m_DBCnt->Execute(_bstr_t(strSql),NULL,adCmdText);
MessageBox("添加成功!");
}
catch(_com_error&e)
{
AfxMessageBox("操作异常或者是你所在的用户组无此权限!");
return;
}
}
void XZ::Readstuxh()
{
UpdateData();
CString strSql;
_variant_t holder;
_RecordsetPtr prst=NULL;
prst.CreateInstance(__uuidof(Recordset));
strSql.Format("select 学号 from v_student");
prst=m_DBCnt->Execute(_bstr_t(strSql),NULL,adCmdText);
int i=0;
if(prst->adoEOF)return;
else
{
prst->MoveFirst();
while(!prst->adoEOF)
{
holder=prst->GetCollect("学号");
m_XH.InsertString(i,holder.vt==VT_NULL?"":(char*)(_bstr_t)holder);
i++;
prst->MoveNext();
}
}
}
void XZ::Readcourkch()
{
UpdateData();
CString strSql;
_variant_t holder;
_RecordsetPtr prst=NULL;
prst.CreateInstance(__uuidof(Recordset));
strSql.Format("select 课程号 from v_course");
prst=m_DBCnt->Execute(_bstr_t(strSql),NULL,adCmdText);
int i=0;
if(prst->adoEOF)return;
else
{
prst->MoveFirst();
while(!prst->adoEOF)
{
holder=prst->GetCollect("课程号");
m_KCH.InsertString(i,holder.vt==VT_NULL?"":(char*)(_bstr_t)holder);
i++;
prst->MoveNext();
}
}
}
void XZ::OnXzcjQx()
{
// TODO: Add your control notification handler code here
m_KCH.SetWindowText("");
m_XH.SetWindowText("");
m_KSCJ.SetWindowText("");
m_PSCJ.SetWindowText("");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -