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

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

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

=$$2) AND (Path.time=$$3)";

prepSql.Replace("$$1",toString(Station1));

prepSql.Replace("$$2",toString(Station2));

prepSql.Replace("$$3",toString(atoi(newValue)));

if(!isUnique(prepSql,"[path_ID]&"))return;

// >>>

CString insertSql="INSERT INTO Path ([start/end station_ID],[end/start station_ID],[time]) Values($$1,$$2,$$3)";

insertSql.Replace("$$1",toString(Station1));

insertSql.Replace("$$2",toString(Station2));

insertSql.Replace("$$3",toString(atoi(newValue)));

DB.ExecuteSQL(insertSql);

Load_List_Pathes();

pEdit_pathTime->SetWindowText("");

// :::

RS=new CMyRecordset(&DB);

CString getNewIdSql="SELECT Path.path_ID FROM Path WHERE Path.[start/end station_ID]=$$1 AND Path.[end/start station_ID]=$$2 AND Path.time=$$3";

getNewIdSql.Replace("$$1",toString(Station1));

getNewIdSql.Replace("$$2",toString(Station2));

getNewIdSql.Replace("$$3",toString(atoi(newValue)));

RS->Open(getNewIdSql,"[path_ID]&");

RS->MoveFirst();

long newId=RS->fieldsValue[0].m_lVal;

RS->Close();

delete RS;

setCurSel_PathStations(newId);}

 

void CPathForm::EditPath_onClick(){

if(!IsSelected_List_Pathes())return;

// >>>

CString newValue;

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

sqlFilter(&newValue);

if(!IsSelected_PathStations())return;

// >>>;

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

sqlFilter(&newValue);

// >>>

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

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

long cID=pList_Pathes_indexes[pList_Pathes->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]=$$2) AND (Path.time=$$3);";

prepSql.Replace("$$1",toString(Station1));

prepSql.Replace("$$2",toString(Station2));

prepSql.Replace("$$3",toString(atoi(newValue)));

if(!isUnique(prepSql,"[path_ID]&"))return;

// >>>

CString updateSql="UPDATE Path SET Path.[start/end station_ID]=$$1, Path.[end/start station_ID]=$$2, Path.[time]=$$3 WHERE Path.path_ID=$$4";

updateSql.Replace("$$1",toString(Station1));

updateSql.Replace("$$2",toString(Station2));

updateSql.Replace("$$3",newValue);

updateSql.Replace("$$4",toString(cID));

DB.ExecuteSQL(updateSql);

Load_List_Pathes();

pEdit_pathTime->SetWindowText("");

setCurSel_PathStations(cID);}

 

void CPathForm::DeletePath_onClick(){

if(!IsSelected_List_Pathes())return;

// >>>

long cID=pList_Pathes_indexes[pList_Pathes->GetCurSel()];

// >>>

CString relateTestSql="SELECT [Race items].race_ID FROM [Race items] WHERE [Race items].path_ID=$$$";

relateTestSql.Replace("$$$",toString(cID));

if(isRelate(relateTestSql,"[race_ID]&"))return;

// >>>

CString deleteSql="DELETE Path.* FROM Path WHERE Path.path_ID=$$$";

deleteSql.Replace("$$$",toString(cID));

DB.ExecuteSQL(deleteSql);

long oldSel=pList_Pathes->GetCurSel();

Load_List_Pathes();

// :::

pList_Pathes->SetCurSel(oldSel>pList_Pathes->GetCount()-1?pList_Pathes->GetCount()-1:oldSel);}

 

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

=== OnInitDialog OnClose ===

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

 

void CPathForm::OK_onClick(){SendMessage(WM_CLOSE,0,0);}

 

BOOL CPathForm::OnInitDialog(){CDialog::OnInitDialog();

// >>>

pList_Pathes=(CListBox*)GetDlgItem(List_Pathes);

pComboBox_Station1=(CComboBox*)GetDlgItem(ComboBox_Station1);

pComboBox_Station2=(CComboBox*)GetDlgItem(ComboBox_Station2);

pEdit_pathTime=(CEdit*)GetDlgItem(Edit_pathTime);

// >>>

Load_ComboBox_Stations();

Load_List_Pathes();

// >>>

return TRUE;}

 

void CPathForm::OnClose(){CDialog::OnClose();

ClearIndexes_pComboBox_Stations_indexes();

ClearIndexes_pList_Pathes_indexes();}

CPathForm.h

#if !defined(AFX_CPATHFORM_H__ADDA99DE_4EF9_466B_8617_713613F3161E__INCLUDED_)

#define AFX_CPATHFORM_H__ADDA99DE_4EF9_466B_8617_713613F3161E__INCLUDED_

 

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

// CPathForm.h : header file

//

 

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

// CPathForm dialog

 

class CPathForm : public CDialog

{

// Construction

public:

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

 

// Dialog Data

//{{AFX_DATA(CPathForm)

enum { IDD = PathForm };

// NOTE: the ClassWizard will add data members here

//}}AFX_DATA

 

 

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CPathForm)

protected:

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

//}}AFX_VIRTUAL

 

// Implementation

protected:

 

// Generated message map functions

//{{AFX_MSG(CPathForm)

afx_msg void AddPath_onClick();

afx_msg void EditPath_onClick();

afx_msg void DeletePath_onClick();

afx_msg void OK_onClick();

virtual BOOL OnInitDialog();

afx_msg void OnClose();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

 

//{{AFX_INSERT_LOCATION}}

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

 

#endif // !defined(AFX_CPATHFORM_H__ADDA99DE_4EF9_466B_8617_713613F3161E__INCLUDED_)

CRaceForm.cpp

#include "stdafx.h"

#include "../main.h"

#include "CRaceForm.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);

void Load_List(CString sql,CString fields,CListBox* ctrl,void clearIdxFunc(void),void initIdxFunc(int),void setIdxFunc(int,int));

 

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

//{{AFX_DATA_INIT(CRaceForm)

//}}AFX_DATA_INIT

}

 

void CRaceForm::DoDataExchange(CDataExchange* pDX){

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CRaceForm)

//}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CRaceForm, CDialog)

//{{AFX_MSG_MAP(CRaceForm)

ON_BN_CLICKED(Button_AddRace, AddRace_onClick)

ON_BN_CLICKED(Button_EditRace, EditRace_onClick)

ON_BN_CLICKED(Button_DeleteRace, DeleteRace_onClick)

ON_BN_CLICKED(IDOK, OK_onClick)

ON_WM_CLOSE()

ON_BN_CLICKED(Button_toAcceptPath, toAcceptPath_onCLick)

ON_BN_CLICKED(Button_toFreePath, toFreePath_onClick)

ON_LBN_SELCHANGE(Race_List, SelchangeList_onSelectChange)

ON_LBN_SELCHANGE(List_AcceptPath, AcceptPath_onSelchange)

ON_LBN_SELCHANGE(List_FreePath, FreePath_onSelchange)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

 

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

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

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

 

CListBox* pRace_List;

CEdit* pEdit_race;

 

CListBox* pList_AcceptPath;

CListBox* pList_FreePath;

 

extern CDatabase DB;

extern CMyRecordset* RS;

 

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

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

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

 

int* pRace_List_indexes;

int* pRLiLen;

 

void ClearIndexes_pRace_List_indexes(){

if(pRace_List_indexes){

delete []pRace_List_indexes,pRLiLen;

pRace_List_indexes=pRLiLen=NULL;}}

 

void InitIndexes_pRace_List_indexes(int len){

pRace_List_indexes=new int[len];

*(pRLiLen=new int)=len;}

 

int* pList_AcceptPath_indexes;

int* pLAPiLen;

 

void ClearIndexes_pList_AcceptPath_indexes(){

if(pList_AcceptPath_indexes){

delete []pList_AcceptPath_indexes,pLAPiLen;

pList_AcceptPath_indexes=pLAPiLen=NULL;}}

 

void InitIndexes_pList_AcceptPath_indexes(int len){

pList_AcceptPath_indexes=new int[len];

*(pLAPiLen=new int)=len;}

 

void SetIndexes_pList_AcceptPath_indexes(int idx,int value){