用C++ MFC做一个管理系统,要文件来储存数据 功能实现增删查改就行
增加和查找已经好了,求修改和删除voidCRestaurantDlg::OnInput(){//TODO:Addyourcontrolnotificationhandle...
增加和查找已经好了,求修改和删除
void CRestaurantDlg::OnInput()
{
// TODO: Add your control notification handler code here
CStdioFile file;
BOOL bFlags=file.Open("D:\\test.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
if(bFlags==FALSE)
{
MessageBox("文件打开失败!");
return;
}
UpdateData(TRUE);
CString strLine=m_strName+" "+m_strBookingTime+" "+m_strMealTime+" "+m_strMoney+" "+m_strTableNumber+" "+m_strMenuNumber+" "+m_strPhone+" "+m_strPeopleNumber+" "+m_strRemark+"\n";
file.SeekToEnd();
file.WriteString(strLine);
file.Close();
}
void CRestaurantDlg::OnQuery()
{
// TODO: Add your control notification handler code here
CStdioFile file;
CString strLine="";
CString strName="";
CString strBookingTime="";
CString strMealTime="";
CString strMoney="";
CString strTableNumber="";
CString strMenuNumber="";
CString strPhone="";
CString strPeopleNumber="";
CString strRemark="";
BOOL bFlags=file.Open("D:\\test.txt",CFile::modeRead);
if(bFlags==FALSE)
{
MessageBox("文件打开失败!");
return;
}
file.Seek(m_dwPos,CFile::begin);
if(file.ReadString(strLine)!=FALSE)
{
m_dwPos=file.GetPosition();
m_strName=strtok(strLine.GetBuffer(0)," ");
m_strBookingTime=strtok(NULL," ");
m_strMealTime=strtok(NULL," ");
m_strMoney=strtok(NULL," ");
m_strTableNumber=strtok(NULL," ");
m_strMenuNumber=strtok(NULL," ");
m_strPhone=strtok(NULL," ");
m_strPeopleNumber=strtok(NULL," ");
m_strRemark=strtok(NULL," ");
UpdateData(FALSE);
}
else
{
MessageBox("当前为最后一条记录!");
}
}
void CRestaurantDlg::OnModify()
{
// TODO: Add your control notification handler code here
CStdioFile file;
BOOL bFlags=file.Open("D:\\test.txt",CFile::modeWrite);
if(bFlags==FALSE)
{
MessageBox("文件打开失败!");
return;
} 展开
void CRestaurantDlg::OnInput()
{
// TODO: Add your control notification handler code here
CStdioFile file;
BOOL bFlags=file.Open("D:\\test.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
if(bFlags==FALSE)
{
MessageBox("文件打开失败!");
return;
}
UpdateData(TRUE);
CString strLine=m_strName+" "+m_strBookingTime+" "+m_strMealTime+" "+m_strMoney+" "+m_strTableNumber+" "+m_strMenuNumber+" "+m_strPhone+" "+m_strPeopleNumber+" "+m_strRemark+"\n";
file.SeekToEnd();
file.WriteString(strLine);
file.Close();
}
void CRestaurantDlg::OnQuery()
{
// TODO: Add your control notification handler code here
CStdioFile file;
CString strLine="";
CString strName="";
CString strBookingTime="";
CString strMealTime="";
CString strMoney="";
CString strTableNumber="";
CString strMenuNumber="";
CString strPhone="";
CString strPeopleNumber="";
CString strRemark="";
BOOL bFlags=file.Open("D:\\test.txt",CFile::modeRead);
if(bFlags==FALSE)
{
MessageBox("文件打开失败!");
return;
}
file.Seek(m_dwPos,CFile::begin);
if(file.ReadString(strLine)!=FALSE)
{
m_dwPos=file.GetPosition();
m_strName=strtok(strLine.GetBuffer(0)," ");
m_strBookingTime=strtok(NULL," ");
m_strMealTime=strtok(NULL," ");
m_strMoney=strtok(NULL," ");
m_strTableNumber=strtok(NULL," ");
m_strMenuNumber=strtok(NULL," ");
m_strPhone=strtok(NULL," ");
m_strPeopleNumber=strtok(NULL," ");
m_strRemark=strtok(NULL," ");
UpdateData(FALSE);
}
else
{
MessageBox("当前为最后一条记录!");
}
}
void CRestaurantDlg::OnModify()
{
// TODO: Add your control notification handler code here
CStdioFile file;
BOOL bFlags=file.Open("D:\\test.txt",CFile::modeWrite);
if(bFlags==FALSE)
{
MessageBox("文件打开失败!");
return;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询