Скачиваний:
91
Добавлен:
01.05.2014
Размер:
2.36 Кб
Скачать
// DlgAddRoom.cpp : implementation file
//

#include "stdafx.h"
#include "kurs.h"
#include "DlgAddRoom.h"
#include "DlgRooms.h"

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

/////////////////////////////////////////////////////////////////////////////
// DlgAddRoom dialog


DlgAddRoom::DlgAddRoom(CWnd* pParent /*=NULL*/)
	: CDialog(DlgAddRoom::IDD, pParent)
{
	//{{AFX_DATA_INIT(DlgAddRoom)
	m_num = _T("");
	m_type = _T("");
	m_price = _T("");
	//}}AFX_DATA_INIT
}


void DlgAddRoom::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DlgAddRoom)
	DDX_Text(pDX, IDC_NUMBER, m_num);
	DDX_CBString(pDX, IDC_TYPER, m_type);
	DDX_Text(pDX, IDC_PRICE, m_price);
	DDV_MaxChars(pDX, m_price, 5);
	//}}AFX_DATA_MAP
	fstream File("Rooms.txt",ios::in);
	CString str("");
	CString str1("");
	CRoom R;
	int i;
	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();


}


BEGIN_MESSAGE_MAP(DlgAddRoom, CDialog)
	//{{AFX_MSG_MAP(DlgAddRoom)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DlgAddRoom message handlers


void DlgAddRoom::OnOK() 
{
	UINT len;
	bool b = true;

	CElem<CRoom> *buf = LR.beg;
	UpdateData(true);

	if(!m_num.IsEmpty() && (!m_type.IsEmpty())){
			len = m_num.GetLength();
			while (len<5){
				m_num+=' ';
				len = m_num.GetLength();
			}
			len = m_type.GetLength();
			while (len<5){
				m_type+=' ';
				len = m_type.GetLength();
			}
			len = m_price.GetLength();
			while (len<5){
				m_price+=' ';
				len = m_price.GetLength();
			}
			while (buf!=0){
				if (buf->inf.GetNumber() == m_num)
					b = false;
				buf=buf->next;
			}
			if (!b)
				AfxMessageBox("Данный номер уже существует!");
			if (!(atoi(m_type)>0))
				AfxMessageBox("Тип должен быть положительным числом!");
			if (atoi(m_type)>0 && b){
				UpdateData(false);
				CDialog::OnOK();
			}
		}
		else{
			AfxMessageBox("Заполнены не все поля!");
		}
}
Соседние файлы в папке kurs