📄 do2.cpp
字号:
// DO2.cpp : implementation file
//
#include "stdafx.h"
#include "lib.h"
#include "stdlib.h"
#include "DO.h"
#include "DO2.h"
#include "fstream.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DO2 dialog
DO2::DO2(CWnd* pParent /*=NULL*/)
: CDialog(DO2::IDD, pParent)
{
//{{AFX_DATA_INIT(DO2)
m_edit21 = _T("");
m_edit22 = _T("");
m_text21 = _T("");
//}}AFX_DATA_INIT
}
void DO2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DO2)
DDX_Text(pDX, IDC_LAB21, m_edit21);
DDX_Text(pDX, IDC_LAB22, m_edit22);
DDX_Text(pDX, IDC_EDIT1, m_text21);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DO2, CDialog)
//{{AFX_MSG_MAP(DO2)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DO2 message handlers
void DO2::OnButton1()
{ ofstream fileout;
ifstream filein;
ofstream fileout2;
ifstream filein2;
int maxbook=100;
int i=0,work=0;
CString ok;
CString strbookid;
CString strbookname;
CString yj="(已借出)";
CString wj="(未借出)";
CString shuh="图书编号:";
CString shum="图书名称:";
CString yj2=" 已借书号:";
CString wj2="(未借书)";
CString shuh2="读者编号:";
CString shum2="读者姓名:";
CString temp;
char str[80];
const maxrow=300;
CString text[maxrow];
CString text2[maxrow];
filein.open("book.dat");
for ( i=0;i<maxrow;i++)
{
filein.getline(str,80);
text[i]=str;
}
filein.close();
filein2.open("reader.dat");
for ( i=0;i<maxrow;i++)
{
filein2.getline(str,80);
text2[i]=str;
}
filein2.close();
GetDlgItem(IDC_EDIT1)->GetWindowText(strbookid);
switch(choice)
{
case 3:
{
fileout.open("book.dat",ios::out|ios::trunc);
ofstream out("book.dat");
for ( i=0;i<maxrow-1;i++)
{
if( text[i].Compare(strbookid)==0 && strbookid!="")
{
i=i+2;
work=1;
continue;
}
if(text[i]!="")fileout<<text[i]<<endl;
}
CDialog::OnOK();
if(work){ MessageBox("删除图书成功");work=0;}
else MessageBox("查无此书");
break;
}
case 4:
{
for ( i=0;i<maxrow-1;i++)
{
if( text[i].Compare(strbookid)==0 && strbookid!="")
{ work=1;
if(text[i+2]=="0")temp=shuh+strbookid+" "+shum+text[i+1]+wj;
else if(text[i+2]=="1")temp=shuh+strbookid+" "+shum+text[i+1]+yj;
}
}
CDialog::OnOK();
if(work) {MessageBox(temp);work=0;}
else MessageBox("查无此书");
break;
}
case 6:
{ GetDlgItem(IDC_EDIT1)->GetWindowText(ok);
if(ok=="ok")
{
fileout.open("book.dat",ios::out|ios::trunc);
MessageBox("全删操作成功");break;
}
else MessageBox("操作没有成功");
break;
}
case 13:
{
fileout2.open("reader.dat",ios::out|ios::trunc);
ofstream out("reader.dat");
for ( i=0;i<maxrow-1;i++)
{
if( text2[i].Compare(strbookid)==0 && strbookid!="")
{
i=i+2;
work=1;
continue;
}
if(text2[i]!="")fileout2<<text2[i]<<endl;
}
CDialog::OnOK();
if(work){ MessageBox("删除读者成功");work=0;}
else MessageBox("查无此读者");
break;
}
case 14:
{
for ( i=0;i<maxrow-1;i++)
{
if( text2[i].Compare(strbookid)==0 && strbookid!="")
{ work=1;
if(text2[i+2]=="0")temp=shuh2+strbookid+" "+shum2+text2[i+1]+wj2;
else temp=shuh2+strbookid+" "+shum2+text2[i+1]+yj2+text2[i+2];
}
}
CDialog::OnOK();
if(work) {MessageBox(temp);work=0;}
else MessageBox("查无此读者");
break;
}
case 16:
{ GetDlgItem(IDC_EDIT1)->GetWindowText(ok);
if(ok=="ok")
{
fileout2.open("reader.dat",ios::out|ios::trunc);
MessageBox("全删操作成功");break;
}
else MessageBox("操作没有成功");
break;
}
}
fileout.close();
filein.close();
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -