All pastes #638544 Raw Edit

Unnamed

public text v1 · immutable
#638544 ·published 2007-07-29 22:41 UTC
rendered paste body
// sregister.cpp : implementation file
//

#include "stdafx.h"
#include "Students.h"
#include "Student.h"
#include "register.h"
#include "common.h"
#include <cstring>
#include <string>
#include <vector>
#include "StudentsDlg.h"
#include "Course.h"

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

/////////////////////////////////////////////////////////////////////////////
// sregister dialog


sregister::sregister(CWnd* pParent /*=NULL*/)
	: CDialog(sregister::IDD, pParent)
{
	//{{AFX_DATA_INIT(sregister)
	m_sid = _T("");
	m_lname = _T("");
	m_fname = _T("");
	m_deg = _T("");
	m_courseids = _T("");
	//}}AFX_DATA_INIT
}

void sregister::setStudent(CString id, CString lname, CString fname, CString deg,int nc, double f, std::vector<CString> c)
{
	tstudent=new Student(id,lname,fname,deg,nc,f,c);
}

Student* sregister::getStudent()
{
	return tstudent;
}

void sregister::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(sregister)
	DDX_Control(pDX, IDCSELECTED, m_selected);
	DDX_Control(pDX, IDC_LISTCOURSES, m_listcourses);
	DDX_Text(pDX, IDC_EDIT1, m_sid);
	DDX_Text(pDX, IDC_EDIT2, m_lname);
	DDX_Text(pDX, IDC_EDIT3, m_fname);
	DDX_Text(pDX, IDC_EDIT4, m_deg);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(sregister, CDialog)
	//{{AFX_MSG_MAP(sregister)
	ON_LBN_DBLCLK(IDC_LISTCOURSES, OnDblclkListcourses)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_REMOVE, OnRemove)
	ON_LBN_DBLCLK(IDCSELECTED, OnDblclkCselected)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// sregister message handlers
void sregister :: setCourseArrayPointer(std::vector<course*> &courseArrayPointer)
{
coursearraypointer = courseArrayPointer;
}


void sregister::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL sregister::OnInitDialog() 
{
	CDialog::OnInitDialog();
//	m_listcourses.AddString("Foo");
//	m_listcourses.AddString("Bar");
	if (coursearraypointer.size()==0)
		MessageBox("No course is being offered yet.");
	else
	{
		for (int i=0;i<coursearraypointer.size();i++)
			m_listcourses.AddString(coursearraypointer[i]->getCourseID());
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void sregister::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(true);
	if ((strlen(m_sid) == 0) || (strlen(m_lname) == 0) || (strlen(m_fname) == 0) || (strlen(m_deg)==0))
{
AfxMessageBox("Please fill in all fields.");
}
else
{
	int count=m_selected.GetCount();
	bool maxed=false;
	double f=0;
	UpdateData(false);
	int nc=count;
	std::vector<CString> c;
	if (nc>10)
		MessageBox("You have chose more than 10 courses.  You will only registered in your first 10 available courses.");
	int coursecount=0;
	
		for (int index = 0; index < nc; ++index)
		{
			for (int index1 = 0; index1 < coursearraypointer.size();index1++)
			{
				CString temp2;
				m_selected.GetText(index,temp2);
				if (coursearraypointer[index1]->getCourseID()==temp2)
				{
					int tempr;
					tempr=coursearraypointer[index1]->getCoursereg();
					if ((tempr+1)>coursearraypointer[index1]->getCoursemax())
					{
						CString full;
						full.Format("Sorry, course %s is full.  You will not be registered in this course.  Skipped.",coursearraypointer[index1]->getCourseID());
						MessageBox(full); 

						
					}
					else
					{

					if (coursecount<=10)
					{
					coursearraypointer[index1]->setCoursereg(tempr+1);
					f+=coursearraypointer[index1]->getCoursefee();
					c.push_back(coursearraypointer[index1]->getCoursename());
					coursecount++;
					
					}
				}
			}
		
			

	setStudent(m_sid,m_lname,m_fname,m_deg, nc, f,c);

	CDialog::OnOK();
	
	}
}
}


}



void sregister::OnDblclkListcourses() 
{
	UpdateData(true);
	if (m_listcourses.GetCount()>0)
	{
	CString temp;
m_listcourses.GetText(m_listcourses.GetCurSel(), temp);
m_selected.AddString(temp);
m_listcourses.DeleteString(m_listcourses.GetCurSel());
    UpdateData(FALSE);		
	}
}

void sregister::OnAdd() 
{
	if (m_listcourses.GetCount()>0)
	{
	UpdateData(true);
	CString temp;
m_listcourses.GetText(m_listcourses.GetCurSel(), temp);
m_selected.AddString(temp);
m_listcourses.DeleteString(m_listcourses.GetCurSel());
    UpdateData(FALSE);	
	}
}


void sregister::OnRemove() 
{
	if (m_selected.GetCount()>0)
	{
	UpdateData(true);
		CString temp;
m_selected.GetText(m_selected.GetCurSel(), temp);
m_listcourses.AddString(temp);
m_selected.DeleteString(m_selected.GetCurSel());
    UpdateData(FALSE);	
	}
	
}

void sregister::OnDblclkCselected() 
{
	if (m_selected.GetCount()>0)
	{
	UpdateData(true);
		CString temp;
m_selected.GetText(m_selected.GetCurSel(), temp);
m_listcourses.AddString(temp);
m_selected.DeleteString(m_selected.GetCurSel());
    UpdateData(FALSE);	
	}
	
}