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

📄 mydlg1.cpp

📁 适用于高校的自动排课系统 MFC编程 实现教务半自动化
💻 CPP
字号:
// MyDlg1.cpp : implementation file
//

#include "stdafx.h"
#include "Arranger.h"
#include "MyDlg1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyDlg1 dialog


CMyDlg1::CMyDlg1(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg1::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg1)
	m_name = _T("");
	m_num = 0;
	//}}AFX_DATA_INIT
}


void CMyDlg1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg1)
	DDX_Text(pDX, IDC_EDITname, m_name);
	DDX_Text(pDX, IDC_EDITnum, m_num);
	DDV_MinMaxInt(pDX, m_num, 0, 9999);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyDlg1, CDialog)
	//{{AFX_MSG_MAP(CMyDlg1)
	ON_BN_CLICKED(IDC_BUTTONfin, OnBUTTONfin)
	ON_BN_CLICKED(IDC_BUTTONadd, OnBUTTONadd)
	ON_BN_CLICKED(IDC_BUTTONbefore, OnBUTTONbefore)
	ON_BN_CLICKED(IDC_BUTTONshow, OnBUTTONshow)
	ON_BN_CLICKED(IDC_BUTTONnext, OnBUTTONnext)
	ON_BN_CLICKED(IDC_BUTTONmod, OnBUTTONmod)
	ON_BN_CLICKED(IDC_BUTTONadd2, OnBUTTONrefresh)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg1 message handlers

void CMyDlg1::OnBUTTONfin() 
{
	// TODO: Add your control notification handler code here
	OnOK();
}

BOOL CMyDlg1::OnInitDialog()
{

correct=0;
return TRUE;
}

void CMyDlg1::OnBUTTONadd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFile writeList;
	int counter=0;

	if (m_name=="" || m_num==0 || m_num>5 || m_num<0)
	{
        MessageBox("请输入正确的课程信息!", "错误");

	} //检验信息正确性
	else
	{
		writeList.Open("list.dat",CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
	
        if ( writeList.GetLength()==0 )
		{
			CArchive arCount( &writeList, CArchive::store );

			arCount << counter;		
			arCount.Close();
		} 
			writeList.SeekToBegin();
			Lesson LesSum[50];
			int sum=0;
			CArchive arGetcount( &writeList, CArchive::load);
			arGetcount >> counter;
			arGetcount.Close();
   			CArchive arRead( &writeList, CArchive::load );
			for ( int i=0; i < counter; i++)
			{   
			    arRead >> LesSum[i].no;
			 	arRead >> LesSum[i].name;
			 	arRead >> LesSum[i].num;
                sum+=LesSum[i].num;
			}
			arRead.Close();
	
			if(sum+m_num>45)
			{
				MessageBox("课程数量超过上限!", "错误");
				writeList.Close();
			}
			else{

			
		
		writeList.SeekToBegin();
		CArchive arGetCount( &writeList, CArchive::load );
		arGetCount >> counter;
		arGetCount.Close();

	    
		CArchive arWrite(&writeList,CArchive::store);
		writeList.SeekToEnd();
		arWrite << counter+1 << m_name << m_num ;
		arWrite.Close();

		CArchive arGivecount( &writeList, CArchive::store);
		writeList.SeekToBegin();
		++counter;
		arGivecount << counter;
		arGivecount.Close();
	    
		writeList.Close();
		MessageBox("已储存!","提示");
			


		m_name="";
		m_num=0;
	    UpdateData(FALSE); //点确定后初始化屏幕
        correct=0;
			}
		
	}
	
	

}

void CMyDlg1::OnBUTTONbefore() 
{
	// TODO: Add your control notification handler code here
	
	CFile readList;
	if(!readList.Open("list.dat", CFile::modeReadWrite)||readList.GetLength()==0)
    {
 		MessageBox("读取信息出错!","错误");
 
    }

	else{int counter;
	CArchive arGetcount( &readList, CArchive::load);
	arGetcount >> counter;
	arGetcount.Close();

    
	if(correct==0)
	{
		MessageBox("请先点“查看”按钮","注意");
	}
	
	else if(checkb >=0)
	{

    	m_name=LessonArray[checkb].name;
	    m_num=LessonArray[checkb].num;
		checkn=checkb+1;
		--checkb;
		UpdateData(FALSE);

	}
	else
	{
		MessageBox("已经是首记录了","注意");

	}
	}


}

void CMyDlg1::OnBUTTONshow() 
{
	// TODO: Add your control notification handler code here
    CFile readList;
    if(!readList.Open("list.dat", CFile::modeReadWrite)||readList.GetLength()==0)
    {
 		MessageBox("读取信息出错!","错误");
 
    }
	else
	{
		int counter;
		CArchive arGetcount( &readList, CArchive::load);
		arGetcount >> counter;
		checkb=counter-1;//初始化before按钮
     	checkn=0;//初始化next按钮
		correct=counter;//初始化修改的按钮
		arGetcount.Close();
   		CArchive arRead( &readList, CArchive::load );
		for ( int i=0; i < counter; i++)
		{   
		    arRead >> LessonArray[i].no;
	     	arRead >> LessonArray[i].name;
	     	arRead >> LessonArray[i].num;

		}
        arRead.Close();
		readList.Close();

		
	}

}

void CMyDlg1::OnBUTTONnext() 
{
	// TODO: Add your control notification handler code here
	CFile readList;
	if(!readList.Open("list.dat", CFile::modeReadWrite)||readList.GetLength()==0)
    {
 		MessageBox("读取信息出错!","错误");

    }
	else{
	int counter;
	CArchive arGetcount( &readList, CArchive::load);
	arGetcount >> counter;
	arGetcount.Close();
	if(correct==0)
	{
		MessageBox("请先点“查看”按钮","注意");
	}
	else if(checkn<counter)
	{

 
	    m_name=LessonArray[checkn].name;
   	    m_num=LessonArray[checkn].num;
		checkb=checkn-1;
		++checkn;
		UpdateData(FALSE);


	}
	else
	{
		MessageBox("已经是末记录了","注意");
	

	}
	}
}

void CMyDlg1::OnBUTTONmod() 
{
	// TODO: Add your control notification handler code here
	if(correct==0)
	{
		MessageBox("请先点“查看”按钮","注意");
	}
	else{
	UpdateData(TRUE);

	CFile correctList;

	if (m_name=="" || m_num==0 || m_num>5 || m_num<0)
	{
        MessageBox("请输入正确的课程信息!", "错误");

	} //检验信息正确性
	else
	{
		    CFile readList;
			readList.Open("list.dat", CFile::modeReadWrite);
		


			Lesson LesSum[50];
			int sum=0;
			int counter;
			CArchive arGgetcount( &readList, CArchive::load);
			readList.SeekToBegin();
			arGgetcount >> counter;
			arGgetcount.Close();
   			CArchive arRread( &readList, CArchive::load );
			for ( int i=0; i < counter; i++)
			{   
			    arRread >> LesSum[i].no;
			 	arRread >> LesSum[i].name;
			 	arRread >> LesSum[i].num;
                sum+=LesSum[i].num;
			}
			arRread.Close();
			readList.Close();
			if(sum+m_num-LesSum[checkb+1].num>45)
			{
				MessageBox("课程数量超过上限!", "错误");

			}
	
			else{

				correctList.Open("list.dat",CFile::modeCreate | CFile::modeReadWrite);
				CArchive arGivecount(&correctList,CArchive::store);
				correctList.SeekToBegin();
				arGivecount << correct;
				arGivecount.Close();

				LessonArray[checkb+1].name=m_name;
				LessonArray[checkb+1].num=m_num;
				for (int j=0;j < correct;j++)
				{
	
	    			CArchive arCorrect(&correctList,CArchive::store);
					correctList.SeekToEnd();
					arCorrect <<  LessonArray[j].no << LessonArray[j].name << LessonArray[j].num ;
					arCorrect.Close();
				}
				MessageBox("修改成功!","注意");
			


  				CArchive arGetcount( &correctList, CArchive::load );
				correctList.SeekToBegin();
				arGetcount >> counter;
				arGetcount.Close();

   				CArchive arRead( &correctList, CArchive::load );
				for ( int i=0; i < counter; i++)
				{   
				    arRead >> LessonArray[i].no;
					arRead >> LessonArray[i].name;
				    arRead >> LessonArray[i].num;
				}
				arRead.Close();
			}
	
		}
	}
}

void CMyDlg1::OnBUTTONrefresh() 
{
	// TODO: Add your control notification handler code here
	CFile newList;
	newList.Open("list.dat",CFile::modeCreate | CFile::modeReadWrite);
	newList.Close();
    correct=0;
	MessageBox("课程信息已经清除!", "提示");
}

⌨️ 快捷键说明

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