⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statdialog.cpp

📁 这是目前正应用于辽宁省很多县级中学的试题库系统源代码
💻 CPP
字号:
// StatDialog.cpp : implementation file
//

#include "stdafx.h"
#include "TestPaper.h"
#include "StatDialog.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStatDialog dialog


CStatDialog::CStatDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CStatDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStatDialog)
	m_statbox1 = _T("");
	m_statedit1 = _T("");
	m_statedit3 = _T("");
	m_statbox3 = _T("");
	m_statbox6 = _T("");
	m_statbox5 = _T("");
	//}}AFX_DATA_INIT
}


void CStatDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStatDialog)
	DDX_Control(pDX, IDC_COMBO5, m_constatbox5);
	DDX_Control(pDX, IDC_CHECK6, m_statcheck6);
	DDX_Control(pDX, IDC_CHECK5, m_statcheck5);
	DDX_Control(pDX, IDC_COMBO3, m_constatbox3);
	DDX_Control(pDX, IDC_CHECK3, m_statcheck3);
	DDX_Control(pDX, IDC_CHECK2, m_statcheck2);
	DDX_Control(pDX, IDC_CHECK1, m_statcheck1);
	DDX_CBString(pDX, IDC_COMBO1, m_statbox1);
	DDX_Text(pDX, IDC_EDIT1, m_statedit1);
	DDX_Text(pDX, IDC_EDIT3, m_statedit3);
	DDX_CBString(pDX, IDC_COMBO3, m_statbox3);
	DDX_CBString(pDX, IDC_COMBO6, m_statbox6);
	DDX_CBString(pDX, IDC_COMBO5, m_statbox5);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStatDialog, CDialog)
	//{{AFX_MSG_MAP(CStatDialog)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
	ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
	ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
	ON_BN_CLICKED(IDC_CHECK6, OnCheck6)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStatDialog message handlers

BOOL CStatDialog::OnInitDialog() //初始化
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON16);
	this->SendMessage(WM_SETICON,ICON_BIG,(LPARAM)hIcon);
	GetDlgItem(IDC_COMBO1)->EnableWindow(false);
	GetDlgItem(IDC_EDIT1)->EnableWindow(false);
	GetDlgItem(IDC_COMBO3)->EnableWindow(false);
	GetDlgItem(IDC_EDIT3)->EnableWindow(false);
	GetDlgItem(IDC_COMBO5)->EnableWindow(false);
	GetDlgItem(IDC_COMBO6)->EnableWindow(false);

	statcheck1=FALSE;
	statcheck2=FALSE;
	statcheck3=FALSE;
	statcheck4=FALSE;
	statcheck5=FALSE;


	CStdioFile MyFile;
	CString str;
	
	MyFile.Open("外部接口\\题库管理之学科名称.txt",CFile::modeRead|CFile::typeText);
	MyFile.SeekToBegin();
	while(MyFile.ReadString(str))
	{
		if(str!="")
		{
		m_constatbox5.AddString(str); 
		str.Empty();
		}
	}
	MyFile.Close();
	str.Empty();

	MyFile.Open("外部接口\\题库管理之考试对象.txt",CFile::modeRead|CFile::typeText);
	MyFile.SeekToBegin();
	while(MyFile.ReadString(str))
	{
		if(str!="")
		{
		m_constatbox3.AddString(str); 
		str.Empty();
		}
	}
	MyFile.Close();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CStatDialog::OnOK() //统计题目
{
	// TODO: Add extra validation here
	CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
	UpdateData(TRUE);
    int     strcount1;
	int     strcount2;
	CString strSQL;
	CString strSQL1;
	CString strSQL2;
	strSQL.Empty();
	strSQL1.Empty();
	strSQL2.Empty();
	if(m_statcheck1.GetCheck()==1 && m_statbox1!="")
	{
		statcheck1=TRUE;//级别
	}
	else
	{
		statcheck1=FALSE;
	}
	if(m_statcheck2.GetCheck()==1 && m_statedit1!="")
	{
		statcheck2=TRUE;//编号
	}
	else
	{
		statcheck2=FALSE;
	}
	if(m_statcheck3.GetCheck()==1 && m_statbox3!="")
	{
		statcheck3=TRUE;//对象
	}
	else
	{
		statcheck3=FALSE;
	}
	if(m_statcheck5.GetCheck()==1 && m_statbox5!="")
	{
		statcheck4=TRUE;
	}
	else
	{
		statcheck4=FALSE;
	}

	if(m_statcheck6.GetCheck()==1 && m_statbox6!="")
	{
		statcheck5=TRUE;
	}
	else
	{
		statcheck5=FALSE;
	}
	if(statcheck4==FALSE)
	{
		AfxMessageBox("请输入科目类型!");
		return;
	}


    if(statcheck5==FALSE)
	{

    	//---------------待加代码
		if(statcheck1==FALSE && statcheck2==FALSE && statcheck3==FALSE)
		{
		     strSQL1.Format("select * from %s单选题",m_statbox5);
		     strSQL2.Format("select * from %s判断题",m_statbox5);
		}
		if(statcheck2==TRUE)
		{
             strSQL1.Format("select * from %s单选题 where 题目编号="+m_statedit1+"",m_statbox5);
	         strSQL2.Format("select * from %s判断题 where 题目编号="+m_statedit1+"",m_statbox5);
		}
		else
		{
			if(statcheck1==TRUE && statcheck3==TRUE)
			{
		         strSQL1.Format("select * from %s单选题 where 难度级别="+m_statbox1+" and 考试对象='"+m_statbox3+"'",m_statbox5);
			     strSQL2.Format("select * from %s判断题 where 难度级别="+m_statbox1+" and 考试对象='"+m_statbox3+"'",m_statbox5);

			}
            if(statcheck1==TRUE && statcheck3==FALSE)
			{
	             strSQL1.Format("select * from %s单选题 where 难度级别="+m_statbox1+"",m_statbox5);
                 strSQL2.Format("select * from %s判断题 where 难度级别="+m_statbox1+"",m_statbox5);
			}
            if(statcheck1==FALSE && statcheck3==TRUE)
			{
		         strSQL1.Format("select * from %s单选题 where 考试对象='"+m_statbox3+"'",m_statbox5);
			     strSQL2.Format("select * from %s判断题 where 考试对象='"+m_statbox3+"'",m_statbox5);
			}
		}


        //---------------第一个表
		try
		{
		if(pMainFrame->m_statset.IsOpen())
		{
			pMainFrame->m_statset.Close();
            pMainFrame->m_statset.Open(CRecordset::dynaset,strSQL1);
		}
		else
		{
			pMainFrame->m_statset.Open(CRecordset::dynaset,strSQL1);
		}

		}
	    catch(...)
		{
		AfxMessageBox("cann't open table!");
		return;
		}
	    if(pMainFrame->m_statset.GetRecordCount()==0)
		{
				strcount1=0;
		}
	    else
		{   
		int countnumber=0;
		pMainFrame->m_statset.MoveFirst();
		while(!pMainFrame->m_statset.IsEOF())
		{
			countnumber=countnumber+1;
			pMainFrame->m_statset.MoveNext();
		}
		strcount1=countnumber;
		}
		//---------------第二个表
		try
		{
		if(pMainFrame->m_statset.IsOpen())
		{
			pMainFrame->m_statset.Close();
            pMainFrame->m_statset.Open(CRecordset::dynaset,strSQL2);
		}
		else
		{
			pMainFrame->m_statset.Open(CRecordset::dynaset,strSQL2);
		}

		}
	    catch(...)
		{
		AfxMessageBox("cann't open table!");
		return;
		}
	    if(pMainFrame->m_statset.GetRecordCount()==0)
		{
				strcount2=0;
		}
	    else
		{   
		int countnumb=0;
		pMainFrame->m_statset.MoveFirst();
		while(!pMainFrame->m_statset.IsEOF())
		{
			countnumb=countnumb+1;
			pMainFrame->m_statset.MoveNext();
		}
		strcount2=countnumb;
		}
		CString output;
		output.Empty(); 
		int mmm;
		mmm=strcount1+strcount2;
		output.Format("%d",mmm);
		m_statedit3=output;
		UpdateData(FALSE);
	    return;
		
    }
	else
	{

	    if(statcheck1==FALSE && statcheck2==FALSE && statcheck3==FALSE)
		{
		     strSQL.Format("select * from %s%s",m_statbox5,m_statbox6);
		}

	    if(statcheck2==TRUE)
		{
             strSQL.Format("select * from %s%s where 题目编号="+m_statedit1+"",m_statbox5,m_statbox6);
		}
	    else
		{
	         if(statcheck1==TRUE && statcheck3==TRUE)
			 {
		           strSQL.Format("select * from %s%s where 难度级别="+m_statbox1+" and 考试对象='"+m_statbox3+"'",m_statbox5,m_statbox6);
			 }
             if(statcheck1==TRUE && statcheck3==FALSE)
			 {
	              strSQL.Format("select * from %s%s where 难度级别="+m_statbox1+"",m_statbox5,m_statbox6);
			 }
             if(statcheck1==FALSE && statcheck3==TRUE)
			 {
		          strSQL.Format("select * from %s%s where 考试对象='"+m_statbox3+"'",m_statbox5,m_statbox6);
			 }
		}
	    try
		{
		if(pMainFrame->m_statset.IsOpen())
		{
			pMainFrame->m_statset.Close();
            pMainFrame->m_statset.Open(CRecordset::dynaset,strSQL);
		}
		else
		{
			pMainFrame->m_statset.Open(CRecordset::dynaset,strSQL);
		}

		}
	    catch(...)
		{
		AfxMessageBox("cann't open table!");
		return;
		}
	    if(pMainFrame->m_statset.GetRecordCount()==0)
		{
		        m_statedit3="0";
		}
	    else
		{   
		int countnumber=0;
		pMainFrame->m_statset.MoveFirst();
		while(!pMainFrame->m_statset.IsEOF())
		{
			countnumber=countnumber+1;
			pMainFrame->m_statset.MoveNext();
		}

        CString strcount;
	    strcount.Format("%d",countnumber);
		m_statedit3=strcount;
		}
	    UpdateData(FALSE);
	    return;
	}
}

void CStatDialog::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CStatDialog::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	if(m_statcheck1.GetCheck()==1)
		GetDlgItem(IDC_COMBO1)->EnableWindow(true);
	if(m_statcheck1.GetCheck()==0)
		GetDlgItem(IDC_COMBO1)->EnableWindow(false);
}

void CStatDialog::OnCheck2() 
{
	// TODO: Add your control notification handler code here
	if(m_statcheck2.GetCheck()==1)
		GetDlgItem(IDC_EDIT1)->EnableWindow(true);
	if(m_statcheck2.GetCheck()==0)
		GetDlgItem(IDC_EDIT1)->EnableWindow(false);
	
}

void CStatDialog::OnCheck3() 
{
	// TODO: Add your control notification handler code here
	if(m_statcheck3.GetCheck()==1)
		GetDlgItem(IDC_COMBO3)->EnableWindow(true);
	if(m_statcheck3.GetCheck()==0)
		GetDlgItem(IDC_COMBO3)->EnableWindow(false);
	
}
	

void CStatDialog::OnCheck5() 
{
	// TODO: Add your control notification handler code here
	if(m_statcheck5.GetCheck()==1)
		GetDlgItem(IDC_COMBO5)->EnableWindow(true);
	if(m_statcheck5.GetCheck()==0)
		GetDlgItem(IDC_COMBO5)->EnableWindow(false);
	
}

void CStatDialog::OnCheck6() 
{
	// TODO: Add your control notification handler code here
	if(m_statcheck6.GetCheck()==1)
		GetDlgItem(IDC_COMBO6)->EnableWindow(true);
	if(m_statcheck6.GetCheck()==0)
		GetDlgItem(IDC_COMBO6)->EnableWindow(false);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -