?? mydlg1.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("請輸入正確的課程信息!", "錯(cuò)誤");
} //檢驗(yàn)信息正確性
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("課程數(shù)量超過上限!", "錯(cuò)誤");
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); //點(diǎn)確定后初始化屏幕
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("讀取信息出錯(cuò)!","錯(cuò)誤");
}
else{int counter;
CArchive arGetcount( &readList, CArchive::load);
arGetcount >> counter;
arGetcount.Close();
if(correct==0)
{
MessageBox("請先點(diǎn)“查看”按鈕","注意");
}
else if(checkb >=0)
{
m_name=LessonArray[checkb].name;
m_num=LessonArray[checkb].num;
checkn=checkb+1;
--checkb;
UpdateData(FALSE);
}
else
{
MessageBox("已經(jīng)是首記錄了","注意");
}
}
}
void CMyDlg1::OnBUTTONshow()
{
// TODO: Add your control notification handler code here
CFile readList;
if(!readList.Open("list.dat", CFile::modeReadWrite)||readList.GetLength()==0)
{
MessageBox("讀取信息出錯(cuò)!","錯(cuò)誤");
}
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("讀取信息出錯(cuò)!","錯(cuò)誤");
}
else{
int counter;
CArchive arGetcount( &readList, CArchive::load);
arGetcount >> counter;
arGetcount.Close();
if(correct==0)
{
MessageBox("請先點(diǎn)“查看”按鈕","注意");
}
else if(checkn<counter)
{
m_name=LessonArray[checkn].name;
m_num=LessonArray[checkn].num;
checkb=checkn-1;
++checkn;
UpdateData(FALSE);
}
else
{
MessageBox("已經(jīng)是末記錄了","注意");
}
}
}
void CMyDlg1::OnBUTTONmod()
{
// TODO: Add your control notification handler code here
if(correct==0)
{
MessageBox("請先點(diǎn)“查看”按鈕","注意");
}
else{
UpdateData(TRUE);
CFile correctList;
if (m_name=="" || m_num==0 || m_num>5 || m_num<0)
{
MessageBox("請輸入正確的課程信息!", "錯(cuò)誤");
} //檢驗(yàn)信息正確性
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("課程數(shù)量超過上限!", "錯(cuò)誤");
}
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("課程信息已經(jīng)清除!", "提示");
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -