Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовой проект1 / Wladimir / kurs / DlgClients
.cpp// DlgClients.cpp : implementation file
//
#include "stdafx.h"
#include "kurs.h"
#include "DlgClients.h"
#include "DlgAddClient.h"
#include "DlgRooms.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgClients dialog
DlgClients::DlgClients(CWnd* pParent /*=NULL*/)
: CDialog(DlgClients::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgClients)
m_listC = _T("");
//}}AFX_DATA_INIT
}
void DlgClients::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgClients)
DDX_LBString(pDX, IDC_LISTC, m_listC);
//}}AFX_DATA_MAP
CListBox* pLB=(CListBox*) GetDlgItem(IDC_LISTC);
pLB->ResetContent();
CString str("");
CString str1("");
CElem<CClient> *buf = LC.beg;
CTime ct1;
CTime ct2;
fstream File("Rooms.txt",ios::in);
CRoom R;
char ch[25];
while (!File.eof()){
File.getline(ch,25,'\n');
str=ch;
if (str!=""){
str1=str.Left(5);
R.SetNumber(str1);
str1=str.Mid(5,5);
R.SetCapasity(str1);
str1=str.Mid(10,5);
R.SetOccupy(str1);
str1=str.Right(5);
R.SetPrice(str1);
LR.AddEl(R);
}
}
File.close();
while (buf !=0){
ct1 = buf->inf.GetDataZ();
ct2 = buf->inf.GetDataV();
str1.Format(_T("%02d/%02d/%2d %02d/%02d/%2d"),ct1.GetDay(),ct1.GetMonth(),ct1.GetYear(),
ct2.GetDay(),ct2.GetMonth(),ct2.GetYear());
str = buf->inf.GetFio()+buf->inf.GetPassport()+buf->inf.GetRoom()+str1 ;
pLB->AddString(str);
buf = buf->next;
}
}
BEGIN_MESSAGE_MAP(DlgClients, CDialog)
//{{AFX_MSG_MAP(DlgClients)
ON_BN_CLICKED(IDC_AddCl, OnAddCl)
ON_BN_CLICKED(IDC_DelCl, OnDelCl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgClients message handlers
void DlgClients::OnAddCl()
{
DlgAddClient dlgAC;
CListBox* pLB=(CListBox*) GetDlgItem(IDC_LISTC);
int result = dlgAC.DoModal();
CString str("");
CElem<CRoom> *buf = LR.beg;
if(result==IDOK){
CClient C;
C.SetPassport(dlgAC.m_PassportClient);
C.SetRoom(dlgAC.m_number);
C.SetDataZ(dlgAC.m_Data1);
C.SetDataV(dlgAC.m_Data2);
C.SetFio(dlgAC.m_fio);
LC.AddEl(C);
CString str1("");
int i;
fstream FileInfo("Information.txt",ios::app);
CTime ct1;
CTime ct2;
ct1 = C.GetDataZ();
ct2 = C.GetDataV();
str1.Format(_T("%02d/%02d/%2d %02d/%02d/%2d"),ct1.GetDay(),ct1.GetMonth(),ct1.GetYear(),
ct2.GetDay(),ct2.GetMonth(),ct2.GetYear());
str = C.GetRoom()+str1+' '+C.GetFio()+C.GetPassport()+"\n";
i = str.GetLength();
FileInfo.write(str,i);
FileInfo.close();
fstream File("Rooms.txt",ios::out);
File.clear();
buf = LR.beg;
while (buf->inf.GetNumber() !=dlgAC.m_number)
buf = buf->next;
buf->inf.SetOccupyUp();
buf = LR.beg;
while(buf != 0){
str = buf->inf.GetNumber()+buf->inf.GetCapasity()+buf->inf.GetOccupy()+buf->inf.GetPrice()+"\n";
i = str.GetLength();
File.write(str,i);
buf = buf->next;
}
File.close();
LR.DelAllElem();
// UpdateData(false);
}
LR.DelAllElem();
UpdateData(false);
}
void DlgClients::OnOK()
{
fstream File("Clients.txt",ios::out);
File.clear();
CString str("");
CElem<CClient> *buf = LC.beg;
int i;
CString str1("");
CTime ct1;
CTime ct2;
while(buf != 0){
ct1 = buf->inf.GetDataZ();
ct2 = buf->inf.GetDataV();
str1.Format(_T("%02d/%02d/%2d %02d/%02d/%2d"),ct1.GetDay(),ct1.GetMonth(),ct1.GetYear(),
ct2.GetDay(),ct2.GetMonth(),ct2.GetYear());
str = buf->inf.GetFio()+buf->inf.GetPassport()+buf->inf.GetRoom()+str1+"\n";
i = str.GetLength();
File.write(str,i);
buf = buf->next;
}
File.close();
LC.DelAllElem();
LR.DelAllElem();
CDialog::OnOK();
}
void DlgClients::OnDelCl()
{
CListBox* pLB=(CListBox*) GetDlgItem(IDC_LISTC);
CString str;
CString str1;
CString str2;
if (pLB->GetCurSel() !=-1){
pLB->GetText(pLB->GetCurSel(), str);
str1=str.Mid(15,11);
str2=str.Mid(26,5);
CElem<CClient> *buf = LC.beg;
CTime ct(atoi(str.Mid(37,4)),atoi(str.Mid(34,2)),atoi(str.Mid(31,2)),0,0,0);
CTime ct2(atoi(str.Mid(49,4)),atoi(str.Mid(46,2)),atoi(str.Mid(43,2)),0,0,0);
while(buf != 0){
if ( (buf->inf.GetPassport()==str1) && (buf->inf.GetRoom()==str2)
&& (buf->inf.GetDataZ().GetYear()==ct.GetYear())
&& (buf->inf.GetDataZ().GetDay()==ct.GetDay())
&& (buf->inf.GetDataZ().GetMonth()==ct.GetMonth())
&& (buf->inf.GetDataV().GetYear()==ct2.GetYear())
&& (buf->inf.GetDataV().GetDay()==ct2.GetDay())
&& (buf->inf.GetDataV().GetMonth()==ct2.GetMonth())){
break;
} else
buf = buf->next;
}
CElem<CRoom> *bufR = LR.beg;
while((bufR!= 0) && (bufR->inf.GetNumber()!=buf->inf.GetRoom()))
bufR = bufR->next;
bool b;
b=bufR->inf.SetOccupyDown();
if(!b)
AfxMessageBox("Выселение невозможно!");
if(b){
LC.DelEl(buf);
fstream File("Rooms.txt",ios::out);
File.clear();
CString str("");
int i;
bufR = LR.beg;
while(bufR != 0){
str = bufR->inf.GetNumber()+bufR->inf.GetCapasity()+bufR->inf.GetOccupy()+bufR->inf.GetPrice()+"\n";
i = str.GetLength();
File.write(str,i);
bufR = bufR->next;
}
File.close();
LR.DelAllElem();
UpdateData(false);
}
}
else
AfxMessageBox("Проживающий не выбран!");
}
Соседние файлы в папке kurs