Объектно-ориентированное программирование Автобусы и маршруты

Реферат - Компьютеры, программирование

Другие рефераты по предмету Компьютеры, программирование

DATA_INIT(CMainForm)

//}}AFX_DATA_INIT

}

 

void CMainForm::DoDataExchange(CDataExchange* pDX){

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CMainForm)

//}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CMainForm, CDialog)

//{{AFX_MSG_MAP(CMainForm)

ON_BN_CLICKED(Button_showTime, showTime_onClick)

ON_BN_CLICKED(Button_showStation, showStation_onClick)

ON_BN_CLICKED(Button_showPath, showPath_onClick)

ON_BN_CLICKED(Button_showAbout, showAbout_onClick)

ON_BN_CLICKED(Button_showRace, showRace_onClick)

ON_BN_CLICKED(Button_showBus, showBus_onClick)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

 

/* ============================

===== User realization =====

============================ */

 

void CMainForm::showTime_onClick(){

CTimeForm timeForm;

timeForm.DoModal();}

 

void CMainForm::showStation_onClick(){

CStationForm stationForm;

stationForm.DoModal();}

 

void CMainForm::showPath_onClick(){

CPathForm pathForm;

pathForm.DoModal();}

 

void CMainForm::showAbout_onClick(){

CAboutForm aboutForm;

aboutForm.DoModal();}

 

void CMainForm::showRace_onClick(){

CRaceForm raceForm;

raceForm.DoModal();}

 

void CMainForm::showBus_onClick(){

CBusForm busForm;

busForm.DoModal();}

 

BOOL CMainForm::OnInitDialog(){

CDialog::OnInitDialog();

// >>>

extern CDatabase DB;

try{

DB.Open("ODBC;DSN=");}

catch(CDBException *pError){

CString str;

str+=pError->m_strStateNativeOrigin; str+="\n"; str+=pError->m_strError;

AfxMessageBox(str);

pError->Delete();};

// >>>

return TRUE;}

CMainForm.h

#if !defined(AFX_CMAINFORM_H__43C7FDB1_2162_4824_BBAC_EAF31944B6FB__INCLUDED_)

#define AFX_CMAINFORM_H__43C7FDB1_2162_4824_BBAC_EAF31944B6FB__INCLUDED_

 

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

// CMainForm.h : header file

//

 

/////////////////////////////////////////////////////////////////////////////

// CMainForm dialog

 

class CMainForm : public CDialog

{

// Construction

public:

CMainForm(CWnd* pParent = NULL); // standard constructor

 

// Dialog Data

//{{AFX_DATA(CMainForm)

enum { IDD = MainForm };

// NOTE: the ClassWizard will add data members here

//}}AFX_DATA

 

 

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CMainForm)

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL

 

// Implementation

protected:

 

// Generated message map functions

//{{AFX_MSG(CMainForm)

afx_msg void showTime_onClick();

afx_msg void showStation_onClick();

afx_msg void showPath_onClick();

afx_msg void showAbout_onClick();

afx_msg void showRace_onClick();

afx_msg void showBus_onClick();

virtual BOOL OnInitDialog();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

 

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

 

#endif // !defined(AFX_CMAINFORM_H__43C7FDB1_2162_4824_BBAC_EAF31944B6FB__INCLUDED_)

CPathForm.cpp

#include "stdafx.h"

#include "../main.h"

#include "CPathForm.h"

#include "../ExLibrary/CMyRecordset.h"

char* toString(int value,int radix=10);

CString IsEmpty_CEdit(CEdit* ctrl);

void sqlFilter(CString* value);

bool isUnique(CString sql,CString fields);

bool isRelate(CString sql,CString fields);

 

CPathForm::CPathForm(CWnd* pParent):CDialog(CPathForm::IDD,pParent){

//{{AFX_DATA_INIT(CPathForm)

//}}AFX_DATA_INIT

}

 

void CPathForm::DoDataExchange(CDataExchange* pDX){

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CPathForm)

//}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CPathForm, CDialog)

//{{AFX_MSG_MAP(CPathForm)

ON_BN_CLICKED(Button_AddPath, AddPath_onClick)

ON_BN_CLICKED(Button_EditPath, EditPath_onClick)

ON_BN_CLICKED(Button_DeletePath, DeletePath_onClick)

ON_BN_CLICKED(IDOK, OK_onClick)

ON_WM_CLOSE()

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

 

/* ============================

===== User realization =====

============================ */

 

CListBox* pList_Pathes;

CComboBox* pComboBox_Station1;

CComboBox* pComboBox_Station2;

CEdit* pEdit_pathTime;

 

extern CDatabase DB;

extern CMyRecordset* RS;

 

/* ============================

====== indexes & Funcn =====

============================ */

 

int* pList_Pathes_indexes;

int* pLPiLen;

 

void ClearIndexes_pList_Pathes_indexes(){

if(pList_Pathes_indexes){

delete []pList_Pathes_indexes,pLPiLen;

pList_Pathes_indexes=pLPiLen=NULL;}}

 

void InitIndexes_pList_Pathes_indexes(int len){

pList_Pathes_indexes=new int[len];

*(pLPiLen=new int)=len;}

 

int* pComboBox_Stations_indexes;

int* pCBSiLen;

 

void ClearIndexes_pComboBox_Stations_indexes(){

if(pComboBox_Stations_indexes){

delete []pComboBox_Stations_indexes,pCBSiLen;

pComboBox_Stations_indexes=pCBSiLen=NULL;}}

 

void InitIndexes_pComboBox_Stations_indexes(int len){

pComboBox_Stations_indexes=new int[len];

*(pCBSiLen=new int)=len;}

 

/* ============================

====== ............... =====

============================ */

 

void Load_ComboBox_Stations(){

pComboBox_Station1->ResetContent();

pComboBox_Station2->ResetContent();

RS=new CMyRecordset(&DB);

RS->Open("SELECT Station.* FROM Station","[station_ID]&,[name]$");

RS->DefineRealCount();

ClearIndexes_pComboBox_Stations_indexes();

if(RS->Count){

InitIndexes_pComboBox_Stations_indexes(RS->Count);

for(int i=0;iCount;i++){

pComboBox_Stations_indexes[i]=RS->fieldsValue[0].m_lVal;

pComboBox_Station1->InsertString(i,RS->fieldsValue[1].m_cstring);

pComboBox_Station2->InsertString(i,RS->fieldsValue[1].m_cstring);

RS->MoveNext();}}

RS->Close();

delete RS;}

 

void Load_List_Pathes(){

pList_Pathes->ResetContent();

RS=new CMyRecordset(&DB);

RS->Open("SELECT Path.path_ID, Station_1.name+' '+Station_2.name+' - ('+Trim(Str(Path.time))+' min)' FROM Station AS Station_2 INNER JOIN (Station AS Station_1 INNER JOIN Path ON Station_1.station_ID = Path.[start/end station_ID]) ON Station_2.station_ID = Path.[end/start station_ID] ORDER BY Station_1.name,Station_2.name,Path.time","[path_ID]&,[Expr1001]$");

RS->DefineRealCount();

ClearIndexes_pList_Pathes_indexes();

if(RS->Count){

InitIndexes_pList_Pathes_indexes(RS->Count);

for(int i=0;iCount;i++){

pList_Pathes_indexes[i]=RS->fieldsValue[0].m_lVal;

pList_Pathes->InsertString(i,RS->fieldsValue[1].m_cstring);

RS->MoveNext();}}

RS->Close();

delete RS;}

 

bool IsSelected_PathStations(){

if(pComboBox_Station1->GetCurSel()==-1||

pComboBox_Station2->GetCurSel()==-1){

AfxMessageBox("Nothing selected!");

return 0;}

return 1;}

 

bool IsSelected_List_Pathes(){

if(pList_Pathes->GetCurSel()==-1){

AfxMessageBox("Nothing selected!");

return 0;}

return 1;}

 

void setCurSel_PathStations(int fictionIndex){

for(int i=0;i<*pLPiLen;i++)

if(pList_Pathes_indexes[i]==fictionIndex){

pList_Pathes->SetCurSel(i);

return;}}

 

/* ============================

====== Add Edit Remove =====

============================ */

 

void CPathForm::AddPath_onClick(){

CString newValue;

if((newValue=IsEmpty_CEdit(pEdit_pathTime))=="") return;

sqlFilter(&newValue);

if(!IsSelected_PathStations())return;

// >>>

long Station1=pComboBox_Stations_indexes[pComboBox_Station1->GetCurSel()];

long Station2=pComboBox_Stations_indexes[pComboBox_Station2->GetCurSel()];

// >>>

if(Station1==Station2){

AfxMessageBox("Path can't be cycled!");

return;}

// >>>

CString prepSql="SELECT Path.path_ID FROM Path WHERE (Path.[start/end station_ID]=$$1 OR Path.[start/end station_ID]=$$2) AND (Path.[end/start station_ID]=$$1 OR Path.[end/start station_ID]