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

📄 addrecord.cpp

📁 VC++编写的论文管理系统
💻 CPP
字号:
// AddRecord.cpp : implementation file
//

#include "stdafx.h"
#include "qq.h"
#include "AddRecord.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAddRecord dialog


CAddRecord::CAddRecord(int nFlag,CWnd* pParent /*=NULL*/)
	: CDialog(CAddRecord::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddRecord)
	m_edit1 = _T("");
	m_edit2 = _T("");
	m_edit3 = _T("");
	m_edit4 = _T("");
	m_edit5 = _T("");
	m_edit6 = _T("");
	m_edit7 = _T("");
	m_edit8 = _T("");
	m_edit9 = _T("");
	m_edit10 = _T("");
	//}}AFX_DATA_INIT
	m_nFlag = nFlag;
}


void CAddRecord::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddRecord)
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDX_Text(pDX, IDC_EDIT3, m_edit3);
	DDX_Text(pDX, IDC_EDIT4, m_edit4);
	DDX_Text(pDX, IDC_EDIT5, m_edit5);
	DDX_Text(pDX, IDC_EDIT6, m_edit6);
	DDX_Text(pDX, IDC_EDIT7, m_edit7);
	DDX_Text(pDX, IDC_EDIT8, m_edit8);
	DDX_Text(pDX, IDC_EDIT9, m_edit9);
	DDX_Text(pDX, IDC_EDIT10, m_edit10);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddRecord, CDialog)
	//{{AFX_MSG_MAP(CAddRecord)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddRecord message handlers

void CAddRecord::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	
}

BOOL CAddRecord::OnInitDialog() 
{
	CDialog::OnInitDialog();
	switch( m_nFlag )
	{
	case 0:
		SetWindowText("增加记录");
		GetDlgItem(IDOK)->SetWindowText("增加");
		break;
	case 1:
				SetWindowText("修改记录");
		GetDlgItem(IDOK)->SetWindowText("修改");
		break;
	case 2:
		SetWindowText("删除记录");
		GetDlgItem(IDOK)->SetWindowText("删除");
		break;
	}
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAddRecord::OnOK() 
{
	// TODO: Add extra validation here
		int nStart=0,nPos;
	int nLen;
	CString chKey1,chKey2,chKey3,chKey4;
	CString enKey1,enKey2,enKey3,enKey4;

	switch( m_nFlag )
	{
	case 0:
		UpdateData(true);
		if( m_edit5.IsEmpty() )
		{
			MessageBox("论文题目不能不为空!","出错",MB_OK);
			break;
		}
		m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		if( !m_StuInfoSet.IsEOF() )
		{
		
	
		m_StuInfoSet.MoveFirst();
		do 
		{
			if( m_StuInfoSet.m_stuid == m_edit1 )
				break;
			m_StuInfoSet.MoveNext();
		}while(!m_StuInfoSet.IsEOF());
			}
//	m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_StuInfoSet.AddNew();
		m_StuInfoSet.m_stuid = m_edit1;
		m_StuInfoSet.m_stuname = m_edit3;
		m_StuInfoSet.m_gradeclass = m_edit2;
		m_StuInfoSet.Update();//更新记录
		m_StuInfoSet.Close();//关闭数据库,写入了一条新的记录

		m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
				if( !m_ThesisInfoSet.IsEOF() )
		{
		m_ThesisInfoSet.MoveFirst();
		do 
		{
			if(m_ThesisInfoSet.m_stuid == m_edit1)
				break;
			m_ThesisInfoSet.MoveNext();
		}while(!m_ThesisInfoSet.IsEOF());
				}
//	m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_ThesisInfoSet.AddNew();
    m_ThesisInfoSet.m_stuid = m_edit1;
		m_ThesisInfoSet.m_name = m_edit5;
		m_ThesisInfoSet.m_type = m_edit10;
	nLen = m_edit7.GetLength();
	nPos = m_edit7.Find(",",nStart);
   	chKey1 = m_edit7.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit7.Find(",",nStart);
   	chKey2 = m_edit7.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit7.Find(",",nStart);
   	chKey3 = m_edit7.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
   	chKey4 = m_edit7.Mid(nStart,nLen-nStart);
	
	nLen = m_edit8.GetLength();
	nStart = 0;
	nPos = m_edit8.Find(",",nStart);
   	enKey1 = m_edit8.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit8.Find(",",nStart);
   	enKey2 = m_edit8.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit8.Find(",",nStart);
   	enKey3 = m_edit8.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
   	enKey4 = m_edit8.Mid(nStart,nLen-nStart);
   
	m_ThesisInfoSet.m_chkey1 = chKey1;
	m_ThesisInfoSet.m_chkey2 = chKey2;
	m_ThesisInfoSet.m_chkey3 = chKey3;
	m_ThesisInfoSet.m_chkey4 = chKey4;
	m_ThesisInfoSet.m_enkey1 = enKey1;
	m_ThesisInfoSet.m_enkey2 = enKey2;
	m_ThesisInfoSet.m_enkey3 = enKey3;
	m_ThesisInfoSet.m_enkey4 = enKey4;

		m_ThesisInfoSet.m_teacher = m_edit4;
		m_ThesisInfoSet.m_description = m_edit9;
		m_ThesisInfoSet.m_score = atof(m_edit6);
		m_ThesisInfoSet.Update();//更新记录
		m_ThesisInfoSet.Close();//关闭数据库,写入了一条新的记录



//	m_edit7 = m_ThesisInfoSet.m_chkey1 +"  "+ m_ThesisInfoSet.m_chkey2 +"  "+ m_ThesisInfoSet.m_chkey3 +"  "+ m_ThesisInfoSet.m_chkey4;
//	m_edit8 = m_ThesisInfoSet.m_enkey1 +"  "+ m_ThesisInfoSet.m_enkey2 +"  "+ m_ThesisInfoSet.m_enkey3 +"  "+ m_ThesisInfoSet.m_enkey4;
		break;
	case 1:
		UpdateData(true);
		m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
				if( m_StuInfoSet.IsEOF() )
				{
							m_StuInfoSet.Close();//关闭数据库
			break;
				}
		m_StuInfoSet.MoveFirst();
		do 
		{
			if( m_StuInfoSet.m_stuid == m_edit1 )
				break;
			m_StuInfoSet.MoveNext();
		}while(!m_StuInfoSet.IsEOF());
//	m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_StuInfoSet.Edit();
//	m_StuInfoSet.m_stuid = StuNo;
		m_StuInfoSet.m_stuname = m_edit3;
		m_StuInfoSet.m_gradeclass = m_edit2;
		m_StuInfoSet.Update();//更新记录
		m_StuInfoSet.Close();//关闭数据库,写入了一条新的记录

		m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_ThesisInfoSet.MoveFirst();
		do 
		{
			if(m_ThesisInfoSet.m_stuid == m_edit1)
				break;
			m_ThesisInfoSet.MoveNext();
		}while(!m_ThesisInfoSet.IsEOF());
//	m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_ThesisInfoSet.Edit();
 //   m_ThesisInfoSet.m_stuid = StuNo;
		m_ThesisInfoSet.m_name = m_edit5;
		m_ThesisInfoSet.m_type = m_edit10;
			nLen = m_edit7.GetLength();
	nPos = m_edit7.Find(",",nStart);
   	chKey1 = m_edit7.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit7.Find(",",nStart);
   	chKey2 = m_edit7.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit7.Find(",",nStart);
   	chKey3 = m_edit7.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
   	chKey4 = m_edit7.Mid(nStart,nLen-nStart);
	
	nLen = m_edit8.GetLength();
	nStart = 0;
	nPos = m_edit8.Find(",",nStart);
   	enKey1 = m_edit8.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit8.Find(",",nStart);
   	enKey2 = m_edit8.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
	nPos = m_edit8.Find(",",nStart);
   	enKey3 = m_edit8.Mid(nStart,nPos-nStart);
	nStart = nPos+1;
   	enKey4 = m_edit8.Mid(nStart,nLen-nStart);
   
	m_ThesisInfoSet.m_chkey1 = chKey1;
	m_ThesisInfoSet.m_chkey2 = chKey2;
	m_ThesisInfoSet.m_chkey3 = chKey3;
	m_ThesisInfoSet.m_chkey4 = chKey4;
	m_ThesisInfoSet.m_enkey1 = enKey1;
	m_ThesisInfoSet.m_enkey2 = enKey2;
	m_ThesisInfoSet.m_enkey3 = enKey3;
	m_ThesisInfoSet.m_enkey4 = enKey4;

/*	m_ThesisInfoSet.m_chkey1 = chKey1;
	m_ThesisInfoSet.m_chkey2 = chKey2;
	m_ThesisInfoSet.m_chkey3 = chKey3;
	m_ThesisInfoSet.m_chkey4 = chKey4;
	m_ThesisInfoSet.m_enkey1 = enKey1;
	m_ThesisInfoSet.m_enkey2 = enKey2;
	m_ThesisInfoSet.m_enkey3 = enKey3;
	m_ThesisInfoSet.m_enkey4 = enKey4; */
		m_ThesisInfoSet.m_teacher = m_edit4;
		m_ThesisInfoSet.m_description = m_edit9;
		m_ThesisInfoSet.m_score = atof(m_edit6);
		m_ThesisInfoSet.Update();//更新记录
		m_ThesisInfoSet.Close();//关闭数据库,写入了一条新的记录



//	m_edit7 = m_ThesisInfoSet.m_chkey1 +"  "+ m_ThesisInfoSet.m_chkey2 +"  "+ m_ThesisInfoSet.m_chkey3 +"  "+ m_ThesisInfoSet.m_chkey4;
//	m_edit8 = m_ThesisInfoSet.m_enkey1 +"  "+ m_ThesisInfoSet.m_enkey2 +"  "+ m_ThesisInfoSet.m_enkey3 +"  "+ m_ThesisInfoSet.m_enkey4;
		break;
	case 2:
		UpdateData(true);
		m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
				if( m_StuInfoSet.IsEOF() )
				{
							m_StuInfoSet.Close();//关闭数据库
			break;
				}
		m_StuInfoSet.MoveFirst();
		do 
		{
			if( m_StuInfoSet.m_stuid == m_edit1 )
				break;
			m_StuInfoSet.MoveNext();
		}while(!m_StuInfoSet.IsEOF());
		m_StuInfoSet.Delete();
		m_StuInfoSet.Close();//关闭数据库
		m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_ThesisInfoSet.MoveFirst();
		do 
		{
			if(m_ThesisInfoSet.m_stuid == m_edit1)
				break;
			m_ThesisInfoSet.MoveNext();
		}while(!m_ThesisInfoSet.IsEOF());
		m_ThesisInfoSet.Delete();
 		m_ThesisInfoSet.Close();//关闭数据库
		break;
	}
	
	CDialog::OnOK();
}

void CAddRecord::OnKillfocusEdit1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if( m_nFlag != 0 )
	{
		CString strScore;
		CString strKeyword1,strKeyword2;
		bool nHasRecord = false;

		m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		if( m_StuInfoSet.IsEOF() )
		{
			MessageBox( "没有此记录","警告",MB_OK);
			m_StuInfoSet.Close();//关闭数据库
			return;
		}
		m_StuInfoSet.MoveFirst();
		do 
		{
			if( m_StuInfoSet.m_stuid == m_edit1 )
			{
				nHasRecord = true;
				break;
			}
			m_StuInfoSet.MoveNext();
		}while(!m_StuInfoSet.IsEOF());
		if( nHasRecord == false )
		{
			MessageBox( "没有此记录","警告",MB_OK);
			m_StuInfoSet.Close();//关闭数据库
			return;
		}
		m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_ThesisInfoSet.MoveFirst();
		do 
		{
			if(m_ThesisInfoSet.m_stuid == m_edit1)
				break;
			m_ThesisInfoSet.MoveNext();
		}while(!m_ThesisInfoSet.IsEOF());
		m_edit1 = m_StuInfoSet.m_stuid;
		m_edit2 = m_StuInfoSet.m_gradeclass;
		m_edit3 = m_StuInfoSet.m_stuname;
		m_edit4 = m_ThesisInfoSet.m_teacher;
		m_edit5 = m_ThesisInfoSet.m_name;
		m_edit10 = m_ThesisInfoSet.m_type;
		strScore.Format("%d", m_ThesisInfoSet.m_score);
		m_edit6 = strScore; 
		m_edit7 = m_ThesisInfoSet.m_chkey1 +","+ m_ThesisInfoSet.m_chkey2 +","+ m_ThesisInfoSet.m_chkey3 +","+ m_ThesisInfoSet.m_chkey4;
		m_edit8 = m_ThesisInfoSet.m_enkey1 +","+ m_ThesisInfoSet.m_enkey2 +","+ m_ThesisInfoSet.m_enkey3 +","+ m_ThesisInfoSet.m_enkey4;
		m_edit9 = m_ThesisInfoSet.m_description;
		m_ThesisInfoSet.Close();
		m_StuInfoSet.Close();//关闭数据库
		UpdateData(false);
	}
	else
	{
		m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		if( m_StuInfoSet.IsEOF() )
		{
		m_StuInfoSet.Close();//关闭数据库
			return;
		}
		m_StuInfoSet.MoveFirst();
		do 
		{
			if( m_StuInfoSet.m_stuid == m_edit1 )
			{
				MessageBox( "已经存在此记录","出错",MB_OK);
				m_StuInfoSet.Close();//关闭数据库
				CDialog::OnOK();

				return;
			}
			m_StuInfoSet.MoveNext();
		}while(!m_StuInfoSet.IsEOF());
		m_StuInfoSet.Close();//关闭数据库
	//	CDialog::OnOK();

	}
}

⌨️ 快捷键说明

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