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

📄 xgdialog.cpp

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

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

/////////////////////////////////////////////////////////////////////////////
// CXgDialog dialog


CXgDialog::CXgDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CXgDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CXgDialog)
	m_Xgedit1 = _T("");
	m_Xgbox1 = _T("");
	m_Xgedit10 = _T("");
	m_Xgedit4 = _T("");
	m_Xgedit5 = _T("");
	m_Xgedit6 = _T("");
	m_Xgedit8 = _T("");
	m_Xgedit7 = _T("");
	m_Xgbox2 = _T("");
	//}}AFX_DATA_INIT
}


void CXgDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXgDialog)
	DDX_Control(pDX, IDC_BUTTON4, m_xgbutton2);
	DDX_Control(pDX, IDC_BUTTON1, m_xgbutton1);
	DDX_Control(pDX, IDC_COMBO2, m_conXgbox2);
	DDX_Text(pDX, IDC_EDIT1, m_Xgedit1);
	DDX_CBString(pDX, IDC_COMBO1, m_Xgbox1);
	DDX_Text(pDX, IDC_EDIT10, m_Xgedit10);
	DDX_Text(pDX, IDC_EDIT4, m_Xgedit4);
	DDX_Text(pDX, IDC_EDIT5, m_Xgedit5);
	DDX_Text(pDX, IDC_EDIT6, m_Xgedit6);
	DDX_Text(pDX, IDC_EDIT8, m_Xgedit8);
	DDX_Text(pDX, IDC_EDIT7, m_Xgedit7);
	DDX_CBString(pDX, IDC_COMBO2, m_Xgbox2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CXgDialog, CDialog)
	//{{AFX_MSG_MAP(CXgDialog)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXgDialog message handlers

BOOL CXgDialog::OnInitDialog() //初始化
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
	HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON13);
	this->SendMessage(WM_SETICON,ICON_BIG,(LPARAM)hIcon);

	if(pMainFrame->ming==2)
	{
		this->SetWindowText("题目修改和删除");
		this->m_xgbutton1.SetWindowText("题目修改");
		this->m_xgbutton2.SetWindowText("题目删除");
	}

	CStdioFile MyFile;
	CString str;
	MyFile.Open("外部接口\\题库管理之考试对象.txt",CFile::modeRead|CFile::typeText);
	MyFile.SeekToBegin();
	while(MyFile.ReadString(str))
	{
		if(str!="")
		{
		m_conXgbox2.AddString(str); 
		str.Empty();
		}
	}
	MyFile.Close();

	if(pMainFrame->BoolConnent==FALSE)
	{
		GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
	}
	
	if(!pMainFrame->m_recordset.CanUpdate()|| !pMainFrame->m_recordset.IsOpen())
         return FALSE;
	int i=pMainFrame->testview->m_ListCtrl.GetHotItem();
    CString tempstr;
	CString tempstr2;
	CString strSQL;
   	strSQL.Empty();
    int keyid=atoi(pMainFrame->testview->m_ListCtrl.GetItemText(i,9));
    pMainFrame->m_recordset.MoveFirst();
	while(!pMainFrame->m_recordset.IsEOF())
	{
		int jj=9;
		CDBVariant XgVa;
		pMainFrame->m_recordset.GetFieldValue(jj,XgVa);
		if(keyid==XgVa.m_iVal)
		{
			break;
		}
		pMainFrame->m_recordset.MoveNext();
	}
	CString Xgtemp;
	CDBVariant XgOleVar;
	int qq=0;
	pMainFrame->m_recordset.GetFieldValue(qq,XgOleVar);
	Xgtemp.Format("%d",XgOleVar.m_iVal);
	m_Xgedit1=Xgtemp;

	pMainFrame->m_recordset.GetFieldValue(1,XgOleVar);

	m_Xgbox2=XgOleVar.m_pstring->GetBuffer(1);
	

	pMainFrame->m_recordset.GetFieldValue(2,XgOleVar);
    CString Xgtemp3;
	Xgtemp3.Format("%d",XgOleVar.m_iVal);
	m_Xgbox1=Xgtemp3;

	pMainFrame->m_recordset.GetFieldValue(3,XgOleVar);
	m_Xgedit5=XgOleVar.m_pstring->GetBuffer(1);

	pMainFrame->m_recordset.GetFieldValue(4,XgOleVar);
	m_Xgedit10=XgOleVar.m_pstring->GetBuffer(1);

	pMainFrame->m_recordset.GetFieldValue(5,XgOleVar);
    m_Xgedit7=XgOleVar.m_pstring->GetBuffer(1);

	
	pMainFrame->m_recordset.GetFieldValue(6,XgOleVar);
	m_Xgedit4=XgOleVar.m_pstring->GetBuffer(1);

	pMainFrame->m_recordset.GetFieldValue(7,XgOleVar);
	m_Xgedit8=XgOleVar.m_pstring->GetBuffer(1);

	pMainFrame->m_recordset.GetFieldValue(8,XgOleVar);
	m_Xgedit6=XgOleVar.m_pstring->GetBuffer(1);

    GetDlgItem(IDC_EDIT1)->EnableWindow(true);
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CXgDialog::OnButton2() 
{
	// TODO: Add your control notification handler code here
	//CDialog::OnOK();
//	CDialog::OnOK();
}

void CXgDialog::OnButton1() //修改题目
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
	int j=pMainFrame->testview->m_ListCtrl.GetHotItem();
	CString tempstr;
	CString tempstr2;
	CString strSQL;
    strSQL.Empty();
    int keyid=atoi(pMainFrame->testview->m_ListCtrl.GetItemText(j,9));
	if(!pMainFrame->m_recordset.CanUpdate())
	{
		AfxMessageBox("不可更新!");
		return;
	}
	CString cstr1,cstr2;
	int nIndex1 = pMainFrame->m_wndAddress1.GetCurSel();
    int nIndex2 = pMainFrame->m_wndAddress2.GetCurSel();
    pMainFrame->m_wndAddress1.GetLBText(nIndex1,cstr1);
	cstr1.TrimLeft("   ");
    pMainFrame->m_wndAddress2.GetLBText(nIndex2,cstr2);
	cstr2.TrimLeft("   ");
	if(atoi(m_Xgedit1)<=0)
	{
		AfxMessageBox("请输入正确的题目编号值!");
		return;
	}
	if(m_Xgedit10=="")
	{
		m_Xgedit10=" ";
	}
	if(m_Xgedit5=="")
	{
		m_Xgedit5=" ";
	}
	if(m_Xgedit4=="")
	{
		m_Xgedit4=" ";
	}
	if(m_Xgedit8=="")
	{
		m_Xgedit8=" ";
	}
	if(m_Xgedit6=="")
	{
		m_Xgedit6=" ";
	}
	if(m_Xgedit7=="")
	{
		m_Xgedit7=" ";
	}
	if(m_Xgbox2=="")
	{
		m_Xgbox2=" ";
	}
	
	CString editstr;
	editstr.Empty();
	editstr.Format("update %s%s set 题目编号='"+m_Xgedit1
		            +"',考试对象='"+m_Xgbox2+"',难度级别='"+m_Xgbox1+"',题目内容='"+m_Xgedit5
		            +"',选项A='"+m_Xgedit10+"',选项B='"+m_Xgedit7
		            +"',选项C='"+m_Xgedit4+"',选项D='"+m_Xgedit8+"',标准答案='"+m_Xgedit6+"'where 识别号=%d",cstr1,cstr2,keyid);
    try
	{
		pMainFrame->m_database.ExecuteSQL(editstr);
	
	}
	catch(...)
	{
		AfxMessageBox("出现异常!");
		return;
	}
	pMainFrame->Refreshdata();
	CDialog::OnOK();
}

void CXgDialog::OnButton4() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
	if(pMainFrame->ming==2)
	{
	int i=pMainFrame->testview->m_ListCtrl.GetHotItem();
	CString strSQL;
	if(AfxMessageBox("确实需要删除该题目吗?",MB_YESNO)==IDYES)
	{
		CDialog::OnOK();
		CString tempstr;
	    CString tempstr2;
	    CString strSQL;
   	    strSQL.Empty();
	    pMainFrame->m_wndAddress1.GetLBText(pMainFrame->m_wndAddress1.GetCurSel(),tempstr);
	    tempstr.TrimLeft("   ");
        pMainFrame->m_wndAddress2.GetLBText(pMainFrame->m_wndAddress2.GetCurSel(),tempstr2);
	    tempstr2.TrimLeft("   ");
	    int keyid=atoi(pMainFrame->testview->m_ListCtrl.GetItemText(i,9));
	    strSQL.Format("delete from %s%s where 识别号=%d",tempstr,tempstr2,keyid);
		pMainFrame->m_database.ExecuteSQL(strSQL);
		pMainFrame->Refreshdata();
	}
		
		
	}
	
	else
	{
	CDialog::OnOK();
	}
	
}

⌨️ 快捷键说明

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