Объектно-ориентированное программирование Автобусы и маршруты
Реферат - Компьютеры, программирование
Другие рефераты по предмету Компьютеры, программирование
g::OnClose();
ClearIndexes_pList_Time_indexes();
ClearIndexes_pComboBox_BusList_indexes();}
void CTimeForm::SelchangeBusList_onChange(){
Load_List_Time(pComboBox_BusList_indexes[pComboBox_BusList->GetCurSel()]);}
CTimeForm.h
#if !defined(AFX_CTIMEFORM_H__3FEEABA8_85EA_4B93_9813_A60092BB9ED8__INCLUDED_)
#define AFX_CTIMEFORM_H__3FEEABA8_85EA_4B93_9813_A60092BB9ED8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CTimeForm.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CTimeForm dialog
class CTimeForm : public CDialog
{
// Construction
public:
CTimeForm(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTimeForm)
enum { IDD = TimeForm };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTimeForm)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CTimeForm)
afx_msg void timesHelp_onClick();
afx_msg void AddTime_onClick();
afx_msg void EditTime_onClick();
afx_msg void DeleteTime_onClick();
afx_msg void OK_onClick();
virtual BOOL OnInitDialog();
afx_msg void OnClose();
afx_msg void SelchangeBusList_onChange();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CTIMEFORM_H__3FEEABA8_85EA_4B93_9813_A60092BB9ED8__INCLUDED_)
CTypeForm.cpp
#include "stdafx.h"
#include "../main.h"
#include "CTypeForm.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);
CTypeForm::CTypeForm(CWnd* pParent):CDialog(CTypeForm::IDD,pParent){
//{{AFX_DATA_INIT(CTypeForm)
//}}AFX_DATA_INIT
}
void CTypeForm::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTypeForm)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTypeForm, CDialog)
//{{AFX_MSG_MAP(CTypeForm)
ON_WM_CLOSE()
ON_BN_CLICKED(IDOK, OK_onClick)
ON_BN_CLICKED(Button_AddBusType, AddBusType_onClick)
ON_BN_CLICKED(Button_EditBusType, EditBusType_onClick)
ON_BN_CLICKED(Button_DeleteBusType, DeleteBusType_onClick)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/* ============================
===== User realization =====
============================ */
CListBox* pList_BusType;
CEdit* pEdit_busType;
extern CDatabase DB;
extern CMyRecordset* RS;
/* ============================
====== indexes & Funcn =====
============================ */
int* pList_BusType_indexes;
int* pLBTiLen;
void ClearIndexes_pList_BusType_indexes(){
if(pList_BusType_indexes){
delete []pList_BusType_indexes,pLBTiLen;
pList_BusType_indexes=pLBTiLen=NULL;}}
void InitIndexes_pList_BusType_indexes(int len){
pList_BusType_indexes=new int[len];
*(pLBTiLen=new int)=len;}
/* ============================
====== ............... =====
============================ */
void Load_List_BusType(){
pList_BusType->ResetContent();
RS=new CMyRecordset(&DB);
RS->Open("SELECT * FROM Type ORDER BY name","[busType_ID]&,[name]$");
RS->DefineRealCount();
ClearIndexes_pList_BusType_indexes();
if(RS->Count){
InitIndexes_pList_BusType_indexes(RS->Count);
for(int i=0;iCount;i++){
pList_BusType_indexes[i]=RS->fieldsValue[0].m_lVal;
pList_BusType->InsertString(i,RS->fieldsValue[1].m_cstring);
RS->MoveNext();}}
RS->Close();
delete RS;}
void setCurSel_TypeForm(int fictionIndex){
for(int i=0;i<*pLBTiLen;i++)
if(pList_BusType_indexes[i]==fictionIndex){
pList_BusType->SetCurSel(i);
return;}}
bool IsSelected_TypeForm(){
if(pList_BusType->GetCurSel()==-1){
AfxMessageBox("Nothing selected!");
return 0;}
return 1;}
/* ============================
====== Add Edit Remove =====
============================ */
void CTypeForm::AddBusType_onClick(){
CString newValue;
if((newValue=IsEmpty_CEdit(pEdit_busType))=="") return;
sqlFilter(&newValue);
// >>>
CString prepSql="SELECT name From Type WHERE name='$$$'";
prepSql.Replace("$$$",newValue);
if(!isUnique(prepSql,"[name]$"))return;
// >>>
CString insertSql="INSERT INTO Type (name) Values('$$$')";
insertSql.Replace("$$$",newValue);
DB.ExecuteSQL(insertSql);
Load_List_BusType();
pEdit_busType->SetWindowText("");
// :::
RS=new CMyRecordset(&DB);
CString getNewIdSql="SELECT busType_ID From Type WHERE name='$$$'";
getNewIdSql.Replace("$$$",newValue);
RS->Open(getNewIdSql,"[busType_ID]&");
RS->MoveFirst();
long newId=RS->fieldsValue[0].m_lVal;
RS->Close();
delete RS;
setCurSel_TypeForm(newId);}
void CTypeForm::EditBusType_onClick(){
if(!IsSelected_TypeForm())return;
int cID=pList_BusType_indexes[pList_BusType->GetCurSel()];
// >>>
CString newValue;
if((newValue=IsEmpty_CEdit(pEdit_busType))=="") return;
sqlFilter(&newValue);
// >>>
CString prepSql="SELECT name From Type WHERE name='$$$'";
prepSql.Replace("$$$",newValue);
if(!isUnique(prepSql,"[name]$"))return;
// >>>
CString updateSql="UPDATE Type SET Type.name = '$$1' WHERE busType_ID=$$2";
updateSql.Replace("$$1",newValue);
updateSql.Replace("$$2",toString(cID));
DB.ExecuteSQL(updateSql);
Load_List_BusType();
pEdit_busType->SetWindowText("");
// :::
setCurSel_TypeForm(cID);}
void CTypeForm::DeleteBusType_onClick(){
if(!IsSelected_TypeForm())return;
int cID=pList_BusType_indexes[pList_BusType->GetCurSel()];
// >>>
// >>>
CString relateTestSql="SELECT bus_ID FROM Bus WHERE busType_ID=$$$";
relateTestSql.Replace("$$$",toString(cID));
if(isRelate(relateTestSql,"[bus_ID]&"))return;
// >>>
CString deleteSql="DELETE * FROM Type WHERE busType_ID=";
deleteSql+=toString(cID);
DB.ExecuteSQL(deleteSql);
int oldSel=pList_BusType->GetCurSel();
Load_List_BusType();
// :::
pList_BusType->SetCurSel(oldSel>pList_BusType->GetCount()-1?pList_BusType->GetCount()-1:oldSel);}
/* ============================
=== OnInitDialog OnClose ===
============================ */
void CTypeForm::OK_onClick(){SendMessage(WM_CLOSE,0,0);}
BOOL CTypeForm::OnInitDialog(){CDialog::OnInitDialog();
// >>>
pList_BusType=(CListBox*)GetDlgItem(List_BusType);
pEdit_busType=(CEdit*)GetDlgItem(Edit_busType);
// >>>
Load_List_BusType();
return TRUE;}
void CTypeForm::OnClose(){CDialog::OnClose();
ClearIndexes_pList_BusType_indexes();}
CTypeForm.h
#if !defined(AFX_CTYPEFORM_H__7C58861A_0178_48E8_A650_7CB3A7C3C4D9__INCLUDED_)
#define AFX_CTYPEFORM_H__7C58861A_0178_48E8_A650_7CB3A7C3C4D9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CTypeForm.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CTypeForm dialog
class CTypeForm : public CDialog
{
// Construction
public:
CTypeForm(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTypeForm)
enum { IDD = TypeForm };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overri