📄 mainfrm.cpp
字号:
testview->m_ListCtrl.SetItemText(i,0,buf);
m_recordset.GetFieldValue(1,OleVar);
testview->m_ListCtrl.SetItemText(i,1,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(2,OleVar);
buf.Format("%d",OleVar.m_iVal);
testview->m_ListCtrl.SetItemText(i,2,buf);
m_recordset.GetFieldValue(3,OleVar);
testview->m_ListCtrl.SetItemText(i,3,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(4,OleVar);
testview->m_ListCtrl.SetItemText(i,4,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(5,OleVar);
testview->m_ListCtrl.SetItemText(i,5,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(6,OleVar);
testview->m_ListCtrl.SetItemText(i,6,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(7,OleVar);
testview->m_ListCtrl.SetItemText(i,7,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(8,OleVar);
testview->m_ListCtrl.SetItemText(i,8,OleVar.m_pstring->GetBuffer(1));
m_recordset.GetFieldValue(9,OleVar);
buf.Format("%d",OleVar.m_iVal);
testview->m_ListCtrl.SetItemText(i,9,buf);
m_recordset.MoveNext();
i++;
}
testview->m_ListCtrl.SetRedraw(TRUE);
testview->m_ListCtrl.Invalidate();
}
void CMainFrame::OnQh()
{
// TODO: Add your command handler code here
CTestPaperApp* pApp=(CTestPaperApp*) AfxGetApp();
if(pApp->enterdlg.struser!="administrator")
{
AfxMessageBox("对不起!你是一般用户身份!");
return;
}
if(BoolConnent==FALSE)
{
AfxMessageBox("请连接数据源!");
return;
}
if(AfxMessageBox("确实需要全部删除学生成绩表吗?",MB_YESNO)==IDYES)
{
CString strSQL;
strSQL.Empty();
strSQL.Format("delete from 成绩表");
m_database.ExecuteSQL(strSQL);
}
}
void CMainFrame::OnChaxun()
{
// TODO: Add your command handler code here
if(BoolConnent==FALSE || m_recordset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
else
{
CXinQueryDialog Querydlg;
Querydlg.DoModal();
}
}
void CMainFrame::OnTongji()
{
// TODO: Add your command handler code here
if(BoolConnent==FALSE || m_recordset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
else
{
CStatDialog Statdlg;
Statdlg.DoModal();
}
}
void CMainFrame::OnShezhi()
{
// TODO: Add your command handler code here
if(BoolConnent==FALSE)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
xindlg.DoModal();
}
void CMainFrame::OnSelchangeCombo1()
{
Refreshdata();
}
void CMainFrame::OnSelchangeCombo2()
{
Refreshdata();
}
void CMainFrame::OnQsqs()
{
// TODO: Add your command handler code here
if(BoolConnent==FALSE || m_recordset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
if(!m_recordset.CanUpdate())
return;
if(AfxMessageBox("确实需要删除全部题目吗?",MB_YESNO)==IDYES)
{
CString tempstr;
CString tempstr2;
CString strSQL;
strSQL.Empty();
m_wndAddress1.GetLBText(m_wndAddress1.GetCurSel(),tempstr);
tempstr.TrimLeft(" ");
m_wndAddress2.GetLBText(m_wndAddress2.GetCurSel(),tempstr2);
tempstr2.TrimLeft(" ");
strSQL.Format("delete from %s%s",tempstr,tempstr2);
m_database.ExecuteSQL(strSQL);
Refreshdata();
}
}
void CMainFrame::OnScsc()
{
// TODO: Add your command handler code here
int i=testview->m_ListCtrl.GetHotItem();
CString strSQL;
if(BoolConnent==FALSE || m_recordset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
if(!m_recordset.CanUpdate())
return;
if(i==-1)
{
AfxMessageBox("请选择删除项!");
return;
}
else
{
if(AfxMessageBox("确实需要删除该题目吗?",MB_YESNO)==IDYES)
{
CString tempstr;
CString tempstr2;
CString strSQL;
strSQL.Empty();
m_wndAddress1.GetLBText(m_wndAddress1.GetCurSel(),tempstr);
tempstr.TrimLeft(" ");
m_wndAddress2.GetLBText(m_wndAddress2.GetCurSel(),tempstr2);
tempstr2.TrimLeft(" ");
int keyid=atoi(testview->m_ListCtrl.GetItemText(i,9));
strSQL.Format("delete from %s%s where 识别号=%d",tempstr,tempstr2,keyid);
m_database.ExecuteSQL(strSQL);
Refreshdata();
}
}
}
void CMainFrame::OnXgxg()
{
// TODO: Add your command handler code here
if(BoolConnent==FALSE || m_recordset.GetRecordCount()==0)
{
AfxMessageBox("请连接数据源或无记录!");
return;
}
int i=testview->m_ListCtrl.GetHotItem();
if(i==-1)
{
AfxMessageBox("请选择修改项!");
return;
}
else
{
ming=1;
CXgDialog Xgdlg;
Xgdlg.DoModal();
}
}
void CMainFrame::OnLrlr()
{
// TODO: Add your command handler code here
if(BoolConnent==FALSE)
{
AfxMessageBox("请连接数据源!");
return;
}
else
{
CLrDialog Lrdlg;
Lrdlg.DoModal();
}
}
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CFrameWnd::PreTranslateMessage(pMsg);
}
void CMainFrame::OnPwd()
{
// TODO: Add your command handler code here
ShellExecute(0, "open","密码管理\\密码管理.exe", NULL, NULL, SW_SHOWNORMAL);
}
void CMainFrame::OnPwdsc()
{
// TODO: Add your command handler code here
if(AfxMessageBox("确实需要删除全部密码设置吗?",MB_YESNO)==IDYES)
{
CString strSQL;
strSQL.Empty();
strSQL.Format("delete from 密码表");
m_database.ExecuteSQL(strSQL);
}
}
BOOL CMainFrame::ChooseTestPaper()//试题抽取函数
{
int value1;
int value2;
CString subjectname;
CString author;
CString strSQL;
CString strSQL1;
CString strSQL2;
CString strSQL3;
CString buf[10];
CDBVariant OleVar1;
CDBVariant OleVar2;
CTestPaperApp* pApp=(CTestPaperApp*) AfxGetApp();
if(pApp->enterdlg.struser!="administrator")
{
AfxMessageBox("对不起!你是一般用户身份!");
return FALSE;
}
if(BoolConnent==FALSE)
{
AfxMessageBox("请连接数据源或无记录!");
return FALSE;
}
strSQL.Empty();
strSQL.Format("delete from 试卷表");
m_database.ExecuteSQL(strSQL);
try
{
if(m_temprecordset1.IsOpen())
{
m_temprecordset1.Close();
m_temprecordset1.Open(CRecordset::dynaset,"select * from 试卷参数设置");
}
else
{
m_temprecordset1.Open(CRecordset::dynaset,"select * from 试卷参数设置");
}
}
catch(...)
{
AfxMessageBox("cann't open table!");
return FALSE;
}
if(m_temprecordset1.GetRecordCount()==0)
{
AfxMessageBox("无试卷参数,无法生成试卷!");
return FALSE;
}
m_temprecordset1.MoveLast();
m_temprecordset1.GetFieldValue(1,OleVar1);
subjectname=OleVar1.m_pstring->GetBuffer(1);//获取学科名
subjectname.TrimLeft();
subjectname.TrimRight();
m_temprecordset1.GetFieldValue(2,OleVar1);
author=OleVar1.m_pstring->GetBuffer(1);//考试对象
author.TrimLeft( );
author.TrimRight( );
m_temprecordset1.GetFieldValue(4,OleVar1);
value1=OleVar1.m_iVal;
m_temprecordset1.GetFieldValue(5,OleVar1);
value2=OleVar1.m_iVal;
strSQL1.Format("select * from %s单选题 where 考试对象='"+author+"'",subjectname);
strSQL2.Format("select * from %s判断题 where 考试对象='"+author+"'",subjectname);
try
{
if(m_temprecordset2.IsOpen())
{
m_temprecordset2.Close();
m_temprecordset2.Open(CRecordset::dynaset,strSQL1);
}
else
{
m_temprecordset2.Open(CRecordset::dynaset,strSQL1);
}
}
catch(...)
{
AfxMessageBox("cann't open table!");
return FALSE;
}
try
{
if(m_temprecordset3.IsOpen())
{
m_temprecordset3.Close();
m_temprecordset3.Open(CRecordset::dynaset,strSQL2);
}
else
{
m_temprecordset3.Open(CRecordset::dynaset,strSQL2);
}
}
catch(...)
{
AfxMessageBox("cann't open table!");
return FALSE;
}
int number1=0;
int number2=0;
if(m_temprecordset2.GetRecordCount()==0)
{
AfxMessageBox("对不起,无足够试题可选!");
return FALSE;
}
else
{
m_temprecordset2.MoveFirst();
while(!m_temprecordset2.IsEOF())
{
number1=number1+1;
m_temprecordset2.MoveNext();
}
}
if(m_temprecordset3.GetRecordCount()==0)
{
AfxMessageBox("对不起,无足够试题可选!");
return FALSE;
}
else
{
m_temprecordset3.MoveFirst();
while(!m_temprecordset3.IsEOF())
{
number2=number2+1;
m_temprecordset3.MoveNext();
}
}
if(number1<value1 || number2<value2)
{
AfxMessageBox("对不起,无足够试题可选!");
return FALSE;
}
try
{
CString paperstr;
paperstr.Format("select * from 试卷表");
if(m_testpaperrecordset.IsOpen())
{
m_testpaperrecordset.Close();
m_testpaperrecordset.Open(CRecordset::dynaset,paperstr);
}
else
{
m_testpaperrecordset.Open(CRecordset::dynaset,paperstr);//dbOpenDynaset
}
}
catch(...)
{
AfxMessageBox("cann't open table!");
return FALSE;
}
int temp[100];
int temp2[100];
srand((unsigned)time( NULL));//随机数发生器
BOOL exit1;
BOOL exit2;
do
{
exit1=TRUE;
for(int j=0;j<value1;j++)
{
int a=rand()%number1;
temp[j]=a;
}
for(int i=0;i<value1;i++)
{
for(int k=0;k<value1;k++)
{
if(i!=k)
{
if(temp[i]==temp[k])
{
exit1=FALSE;
}
}
}
}
}while(!exit1);
do
{
exit2=TRUE;
for(int j=0;j<value2;j++)
{
int a=rand()%number2;
temp2[j]=a;
}
for(int i=0;i<value2;i++)
{
for(int k=0;k<value2;k++)
{
if(i!=k)
{
if(temp2[i]==temp2[k])
{
exit2=FALSE;
}
}
}
}
}while(!exit2);
for(int m=0;m<value1;m++)
{
m_temprecordset2.MoveFirst();
m_temprecordset2.Move(temp[m]);
int tem=0;
m_temprecordset2.GetFieldValue(tem,OleVar2);
buf[0].Format("%d",OleVar2.m_iVal);
m_temprecordset2.GetFieldValue(1,OleVar2);
buf[1]=OleVar2.m_pstring->GetBuffer(1);
buf[1].TrimLeft();
buf[1].TrimRight();
m_temprecordset2.GetFieldValue(2,OleVar2);
buf[2].Format("%d",OleVar2.m_iVal);
m_temprecordset2.GetFieldValue(3,OleVar2);
buf[3]=OleVar2.m_pstring->GetBuffer(1);
buf[3].TrimLeft();
buf[3].TrimRight();
m_temprecordset2.GetFieldValue(4,OleVar2);
buf[4]=OleVar2.m_pstring->GetBuffer(1);
buf[4].TrimLeft();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -