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

#include "stdafx.h"
#include "kurs.h"
#include "DlgEmpl.h"
#include "DlgAddEmpl.h"
//#include "ListEmpl.h"
//#include "Person.h"

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

/////////////////////////////////////////////////////////////////////////////
// DlgEmpl dialog

//CList<CEmpl> LE;

DlgEmpl::DlgEmpl(CWnd* pParent /*=NULL*/)
	: CDialog(DlgEmpl::IDD, pParent)
{
	//{{AFX_DATA_INIT(DlgEmpl)
	m_listE = _T("");
	//}}AFX_DATA_INIT
}


void DlgEmpl::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DlgEmpl)
	DDX_LBString(pDX, IDC_lstEmpl, m_listE);
	//}}AFX_DATA_MAP
	
	CListBox* pLB=(CListBox*) GetDlgItem(IDC_lstEmpl);
	pLB->ResetContent();
	CString str("");
	CElem<CEmpl> *buf = LE.beg;
	while (buf !=0){
		str = buf->inf.GetFio()+buf->inf.GetPassport()+buf->inf.GetPost();
		pLB->AddString(str);
		buf = buf->next;
	}

}


BEGIN_MESSAGE_MAP(DlgEmpl, CDialog)
	//{{AFX_MSG_MAP(DlgEmpl)
	ON_BN_CLICKED(IDC_AddE, OnAddE)
	ON_BN_CLICKED(IDC_DelE, OnDelE)
	ON_LBN_DBLCLK(IDC_lstEmpl, OnDblclklstEmpl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DlgEmpl message handlers

void DlgEmpl::OnAddE() 
{
	DlgAddEmpl dlgAE;
	CEmpl E;
	CString str;
	int result = dlgAE.DoModal();
	if(result==IDOK){
			E.SetFio(dlgAE.m_fioe);
			E.SetPassport(dlgAE.m_passe);
			E.SetPost(dlgAE.m_post);
			LE.AddEl(E);
			UpdateData(false);
		}
}

void DlgEmpl::OnDelE() 
{
	CListBox* pLB=(CListBox*) GetDlgItem(IDC_lstEmpl);
	CString str;
	CString str1;
	try{
		if (pLB->GetCurSel() ==-1)
			throw "Служащий не выбран";
		pLB->GetText(pLB->GetCurSel(), str);
		str1=str.Mid(15,11);
		int i = str.Find(" ");
		str=str.Mid(i+1);
		i=str.Find(" ");
		str=str.Left(i);
		CElem<CEmpl> *buf = LE.beg;
		while((buf != 0) && (buf->inf.GetPassport()!=str1))
			buf = buf->next;
		LE.DelEl(buf);
		UpdateData(false);		
	}
	catch(const char *p){
		AfxMessageBox(p);
	}


}

void DlgEmpl::OnOK() 
{
	fstream File("Employeer.txt",ios::out);
	CString str("");
	CElem<CEmpl> *buf = LE.beg;
	int i;
	while(buf != 0){
		str = buf->inf.GetFio()+buf->inf.GetPassport()+buf->inf.GetPost()+"\n";
		i = str.GetLength();
		File.write(str,i);
		buf = buf->next;
	}
	File.close();
	LE.DelAllElem();
	UpdateData(false);
	CDialog::OnOK();
}


void DlgEmpl::OnDblclklstEmpl() 
{
	DlgAddEmpl dlgAE;
	CString str;
	CListBox* pLB=(CListBox*) GetDlgItem(IDC_lstEmpl);
	pLB->GetText(pLB->GetCurSel(), str);
	UINT len;
	str=str.Mid(15,11);
	CElem<CEmpl> *buf = LE.beg;
	while((buf != 0) && (buf->inf.GetPassport()!=str))
		buf = buf->next;
	dlgAE.m_fioe = buf->inf.GetFio();
	dlgAE.m_passe = buf->inf.GetPassport();
	dlgAE.m_post = buf->inf.GetPost();;
	int result = dlgAE.DoModal();
	if(result==IDOK){
		if (!dlgAE.m_fioe.IsEmpty() && !dlgAE.m_passe.IsEmpty() && !dlgAE.m_post.IsEmpty()){
			len = dlgAE.m_fioe.GetLength();
			if (len>15) {dlgAE.m_fioe=dlgAE.m_fioe.Left(15);}
			else
				while (len<15){
					dlgAE.m_fioe+=' ';
					len = dlgAE.m_fioe.GetLength();
				}
			len = dlgAE.m_passe.GetLength();
			if (len>11) {dlgAE.m_passe=dlgAE.m_passe.Left(11);}
			else
			while (len<11){
				dlgAE.m_passe+=' ';
				len = dlgAE.m_passe.GetLength();
			}
			len = dlgAE.m_post.GetLength();
			if (len>10) {dlgAE.m_post=dlgAE.m_post.Left(10);}
			else
			while (len<10){
				dlgAE.m_post+=' ';
				len = dlgAE.m_post.GetLength();
			};
			buf->inf.SetFio(dlgAE.m_fioe);
			buf->inf.SetPassport(dlgAE.m_passe);
			buf->inf.SetPost(dlgAE.m_post);
       		UpdateData(false);		
		}else
		AfxMessageBox("Заполнены не все поля!");

	}
}


void DlgEmpl::OnCancel() 
{
	LE.DelAllElem();	
	CDialog::OnCancel();
}

Соседние файлы в папке kurs