📄 jlsj.cpp
字号:
// Jlsj.cpp : implementation file
//
#include "stdafx.h"
#include "SJFX.h"
#include "Jlsj.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJlsj dialog
CJlsj::CJlsj(CWnd* pParent /*=NULL*/)
: CDialog(CJlsj::IDD, pParent)
{
//{{AFX_DATA_INIT(CJlsj)
m_Bj = _T("");
m_Fs1 = 0;
m_Fs10 = 0;
m_Fs2 = 0;
m_Fs3 = 0;
m_Fs4 = 0;
m_Fs5 = 0;
m_Fs6 = 0;
m_Fs7 = 0;
m_Fs8 = 0;
m_Fs9 = 0;
m_Kc = _T("");
m_Zts = -1;
m_Zy = _T("");
m_Js = _T("");
//}}AFX_DATA_INIT
}
void CJlsj::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJlsj)
DDX_Control(pDX, IDC_S9, m_s9);
DDX_Control(pDX, IDC_S7, m_s7);
DDX_Control(pDX, IDC_S8, m_s8);
DDX_Control(pDX, IDC_S6, m_s6);
DDX_Control(pDX, IDC_S5, m_s5);
DDX_Control(pDX, IDC_S4, m_s4);
DDX_Control(pDX, IDC_S3, m_s3);
DDX_Control(pDX, IDC_S2, m_s2);
DDX_Control(pDX, IDC_S10, m_s10);
DDX_Control(pDX, IDC_S1, m_s1);
DDX_Control(pDX, IDC_FS_1, m_cFs1);
DDX_Control(pDX, IDC_FS_10, m_cFs10);
DDX_Control(pDX, IDC_FS_2, m_cFs2);
DDX_Control(pDX, IDC_FS_3, m_cFs3);
DDX_Control(pDX, IDC_FS_4, m_cFs4);
DDX_Control(pDX, IDC_FS_5, m_cFs5);
DDX_Control(pDX, IDC_FS_6, m_cFs6);
DDX_Control(pDX, IDC_FS_7, m_cFs7);
DDX_Control(pDX, IDC_FS_8, m_cFs8);
DDX_Control(pDX, IDC_FS_9, m_cFs9);
DDX_Control(pDX, IDC_FS_MTMF, m_cMtmf);
DDX_Text(pDX, IDC_BJ, m_Bj);
DDV_MaxChars(pDX, m_Bj, 10);
DDX_Text(pDX, IDC_FS_1, m_Fs1);
DDX_Text(pDX, IDC_FS_10, m_Fs10);
DDX_Text(pDX, IDC_FS_2, m_Fs2);
DDX_Text(pDX, IDC_FS_3, m_Fs3);
DDX_Text(pDX, IDC_FS_4, m_Fs4);
DDX_Text(pDX, IDC_FS_5, m_Fs5);
DDX_Text(pDX, IDC_FS_6, m_Fs6);
DDX_Text(pDX, IDC_FS_7, m_Fs7);
DDX_Text(pDX, IDC_FS_8, m_Fs8);
DDX_Text(pDX, IDC_FS_9, m_Fs9);
DDX_Text(pDX, IDC_KC, m_Kc);
DDV_MaxChars(pDX, m_Kc, 20);
DDX_CBIndex(pDX, IDC_ZTS, m_Zts);
DDX_Text(pDX, IDC_ZY, m_Zy);
DDV_MaxChars(pDX, m_Zy, 20);
DDX_Text(pDX, IDC_JS, m_Js);
DDV_MaxChars(pDX, m_Js, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJlsj, CDialog)
//{{AFX_MSG_MAP(CJlsj)
ON_CBN_SELCHANGE(IDC_ZTS, OnSelchangeZts)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJlsj message handlers
BOOL CJlsj::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
HideCtrl();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CJlsj::OnOK()
{
// TODO: Add extra validation here
UpdateData();
CString strSql;
CSJFXApp* pApp = (CSJFXApp*)AfxGetApp();
//判断试卷是否重复
strSql.Format("SELECT * FROM sjxx where zy = '%s' and bj= '%s' and kc='%s'",
m_Zy,m_Bj,m_Kc);
HRESULT hr = pApp->m_pRecordset->Open(strSql.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!SUCCEEDED(hr))
{
AfxMessageBox("打开试卷基本信息表出错!");
return ;
}
if(!pApp->m_pRecordset->adoEOF)
{
AfxMessageBox("该试卷已经存在!");
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_ZY);
pEdit->SetFocus();
pEdit->SetSel(0,m_Zy.GetLength());
pApp->m_pRecordset->Close();
return ;
}
pApp->m_pRecordset->Close();
AfxMessageBox("试卷基本信息中没有重复的记录!"); //?????
//产生成绩表的表名
CString strcjb;
while(1) {
strcjb.Format("%05d",rand());
strcjb="Cjb"+strcjb;
strSql.Format("SELECT * FROM sjxx where cjb = '%s' ", strcjb);
hr = pApp->m_pRecordset->Open(strSql.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!SUCCEEDED(hr))
{ AfxMessageBox("打开试卷基本信息表出错!"); return ; }
if(pApp->m_pRecordset->adoEOF) break;
else pApp->m_pRecordset->Close();
}
pApp->m_pRecordset->Close();
AfxMessageBox("成绩表的表名产生成功!"); //?????
//新增一条记录
strSql = "SELECT * FROM sjxx";
hr = pApp->m_pRecordset->Open(strSql.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!SUCCEEDED(hr))
{
AfxMessageBox("打开试卷基本信息表出错!");
return ;
}
CString str;
pApp->m_pRecordset->AddNew();
pApp->m_pRecordset->PutCollect("zy",_variant_t(m_Zy));
pApp->m_pRecordset->PutCollect("bj",_variant_t(m_Bj));
pApp->m_pRecordset->PutCollect("kc",_variant_t(m_Kc));
pApp->m_pRecordset->PutCollect("js",_variant_t(m_Js));
pApp->m_pRecordset->PutCollect("cjb",_variant_t(strcjb));
str.Format("%d",m_Zts+1);
pApp->m_pRecordset->PutCollect("ts",_variant_t(str));
switch(m_Zts+1)
{
case 10: str.Format("%d",m_Fs10);
pApp->m_pRecordset->PutCollect("mf10",_variant_t(str));
case 9: str.Format("%d",m_Fs9);
pApp->m_pRecordset->PutCollect("mf9",_variant_t(str));
case 8: str.Format("%d",m_Fs8);
pApp->m_pRecordset->PutCollect("mf8",_variant_t(str));
case 7: str.Format("%d",m_Fs7);
pApp->m_pRecordset->PutCollect("mf7",_variant_t(str));
case 6: str.Format("%d",m_Fs6);
pApp->m_pRecordset->PutCollect("mf6",_variant_t(str));
case 5: str.Format("%d",m_Fs5);
pApp->m_pRecordset->PutCollect("mf5",_variant_t(str));
case 4: str.Format("%d",m_Fs4);
pApp->m_pRecordset->PutCollect("mf4",_variant_t(str));
case 3: str.Format("%d",m_Fs3);
pApp->m_pRecordset->PutCollect("mf3",_variant_t(str));
case 2: str.Format("%d",m_Fs2);
pApp->m_pRecordset->PutCollect("mf2",_variant_t(str));
case 1: str.Format("%d",m_Fs1);
pApp->m_pRecordset->PutCollect("mf1",_variant_t(str));
}
pApp->m_pRecordset->Update();
pApp->m_pRecordset->Close();
AfxMessageBox("试卷基本信息表中增加一条新记录成功!"); //?????
//创建成绩表
strSql.Format("create table %s (Num char(7),Name char(10),Zf int,",strcjb);
switch(m_Zts+1)
{
case 10: strSql+="s10 int,";
case 9: strSql+="s9 int,";
case 8: strSql+="s8 int,";
case 7: strSql+="s7 int,";
case 6: strSql+="s6 int,";
case 5: strSql+="s5 int,";
case 4: strSql+="s4 int,";
case 3: strSql+="s3 int,";
case 2: strSql+="s2 int,";
case 1: strSql+="s1 int";
}
strSql+=");";
VARIANT RecordsAffected;
try {
pApp->m_pConnection->Execute((_bstr_t)strSql,&RecordsAffected,adCmdText);
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("创建新试卷的成绩表失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
AfxMessageBox("新试卷创建成功!");
pApp->m_Sj.Zy=m_Zy;
pApp->m_Sj.Bj=m_Bj;
pApp->m_Sj.Kc=m_Kc;
pApp->m_Sj.Js=m_Js;
pApp->m_Sj.Cjb=strcjb;
pApp->m_Sj.Zts=m_Zts+1;
// pApp->m_pView->Invalidate();
CDialog::OnOK();
}
void CJlsj::OnSelchangeZts()
{
// TODO: Add your control notification handler code here
UpdateData();
HideCtrl();
switch(m_Zts) {
case 9: m_cFs10.ShowWindow(SW_SHOW); m_s10.ShowWindow(SW_SHOW);
case 8: m_cFs9.ShowWindow(SW_SHOW); m_s9.ShowWindow(SW_SHOW);
case 7: m_cFs8.ShowWindow(SW_SHOW); m_s8.ShowWindow(SW_SHOW);
case 6: m_cFs7.ShowWindow(SW_SHOW); m_s7.ShowWindow(SW_SHOW);
case 5: m_cFs6.ShowWindow(SW_SHOW); m_s6.ShowWindow(SW_SHOW);
case 4: m_cFs5.ShowWindow(SW_SHOW); m_s5.ShowWindow(SW_SHOW);
case 3: m_cFs4.ShowWindow(SW_SHOW); m_s4.ShowWindow(SW_SHOW);
case 2: m_cFs3.ShowWindow(SW_SHOW); m_s3.ShowWindow(SW_SHOW);
case 1: m_cFs2.ShowWindow(SW_SHOW); m_s2.ShowWindow(SW_SHOW);
case 0: m_cFs1.ShowWindow(SW_SHOW); m_s1.ShowWindow(SW_SHOW);
default: m_cMtmf.ShowWindow(SW_SHOW);
}
}
void CJlsj::HideCtrl()
{
m_cFs1.ShowWindow(FALSE); m_s1.ShowWindow(FALSE);
m_cFs2.ShowWindow(FALSE); m_s2.ShowWindow(FALSE);
m_cFs3.ShowWindow(FALSE); m_s3.ShowWindow(FALSE);
m_cFs4.ShowWindow(FALSE); m_s4.ShowWindow(FALSE);
m_cFs5.ShowWindow(FALSE); m_s5.ShowWindow(FALSE);
m_cFs6.ShowWindow(FALSE); m_s6.ShowWindow(FALSE);
m_cFs7.ShowWindow(FALSE); m_s7.ShowWindow(FALSE);
m_cFs8.ShowWindow(FALSE); m_s8.ShowWindow(FALSE);
m_cFs9.ShowWindow(FALSE); m_s9.ShowWindow(FALSE);
m_cFs10.ShowWindow(FALSE);m_s10.ShowWindow(FALSE);
m_cMtmf.ShowWindow(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -