⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bustypedlg.cpp

📁 一个简单的公交查询管理系统
💻 CPP
字号:
// BustypeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BusQuery.h"
#include "BustypeDlg.h"
#include "DB_Func.h"

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

extern SQLHENV henv;
extern SQLHDBC hdbc;
extern SQLHSTMT hstmt;

/////////////////////////////////////////////////////////////////////////////
// CBustypeDlg dialog


CBustypeDlg::CBustypeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBustypeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBustypeDlg)
	m_String_StationName = _T("");
	m_String_BusName = _T("");
	m_BusSign = -1;
	//}}AFX_DATA_INIT
}


void CBustypeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBustypeDlg)
	DDX_Control(pDX, IDC_BUS_TYPE_LIST_STATION, m_ListBox_Station);
	DDX_Control(pDX, IDC_BUS_TYPE_LIST_BUS, m_ListBox_Bus);
	DDX_Text(pDX, IDC_BUS_TYPE_EDIT_STATION, m_String_StationName);
	DDX_Text(pDX, IDC_BUS_TYPE_EDIT_BUS, m_String_BusName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBustypeDlg, CDialog)
	//{{AFX_MSG_MAP(CBustypeDlg)
	ON_BN_CLICKED(IDC_BUS_TYPE_BUS_ADD, OnBusTypeBusAdd)
	ON_BN_CLICKED(IDC_BUS_TYPE_BUS_DELETE, OnBusTypeBusDelete)
	ON_BN_CLICKED(IDC_BUS_TYPE_BUS_DELETE_ALL, OnBusTypeBusDeleteAll)
	ON_BN_CLICKED(IDC_BUS_TYPE_BUS_MODIFY, OnBusTypeBusModify)
	ON_BN_CLICKED(IDC_BUS_TYPE_STATION_ADD, OnBusTypeStationAdd)
	ON_BN_CLICKED(IDC_BUS_TYPE_STATION_DELETE, OnBusTypeStationDelete)
	ON_BN_CLICKED(IDC_BUS_TYPE_STATION_DELETE_ALL, OnBusTypeStationDeleteAll)
	ON_BN_CLICKED(IDC_BUS_TYPE_STATION_MODIFY, OnBusTypeStationModify)
	ON_BN_CLICKED(IDC_BUS_TYPE_STATION_CLEAR, OnBusTypeStationClear)
	ON_BN_CLICKED(IDC_BUS_TYPE_BUS_CLEAR, OnBusTypeBusClear)
	ON_LBN_SELCHANGE(IDC_BUS_TYPE_LIST_BUS, OnSelchangeBusTypeListBus)
	ON_LBN_SELCHANGE(IDC_BUS_TYPE_LIST_STATION, OnSelchangeBusTypeListStation)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBustypeDlg message handlers

BOOL CBustypeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//
	CRect rc(0, 0, 0, 0);	
	GetParent()->GetClientRect(&rc);
	((CTabCtrl*)GetParent())->AdjustRect(false, &rc); 
	MoveWindow(&rc);

	//////////////////////////////////////////////////////////////////////////
    
	//-------查询所有车次类型 --------//
	// 初始化变量
	BUS_TYPE bus_type;
	BUS_TYPE *bus_type_head;
	bus_type_head = new BUS_TYPE;
	memset(&bus_type,     0, sizeof(BUS_TYPE));
	memset(bus_type_head, 0, sizeof(BUS_TYPE));
	
	// 查询
	int rv;
	rv = DB_BUS_TYPE_Query(hstmt, &bus_type, bus_type_head);   
	if( rv != 0 )
	{
		delete bus_type_head;
		return FALSE;
	}
	// 列表显示
	m_ListBox_Bus.ResetContent();

    BUS_TYPE *pTemp_bus;
	CString str;
	
	while( bus_type_head != NULL )
    {
		pTemp_bus = bus_type_head;
		m_ListBox_Bus.AddString(pTemp_bus->Bus_Type_Name);
		bus_type_head = bus_type_head->next;
		delete pTemp_bus;		
    }

	//************* 查询所有站点类型 *************//
	// 初始化变量
	STATION_TYPE staiton_type;
	STATION_TYPE *staiton_type_head;
	staiton_type_head = new STATION_TYPE;
	memset(&staiton_type,     0, sizeof(STATION_TYPE));
	memset(staiton_type_head, 0, sizeof(STATION_TYPE));
	
	// 查询
	rv = DB_STATION_TYPE_Query(hstmt, &staiton_type, staiton_type_head);   
	if( rv != 0 )
	{
		delete staiton_type_head;
		return FALSE;
	}
	// 列表显示
	m_ListBox_Station.ResetContent();
	
    STATION_TYPE *pTemp_staiton;

	while( staiton_type_head != NULL )
    {
		pTemp_staiton = staiton_type_head;
		m_ListBox_Station.AddString(pTemp_staiton->Station_Type_Name);
		staiton_type_head = staiton_type_head->next;
		delete pTemp_staiton;		
    }
	//////////////////////////////////////////////////////////////////////////
	
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBustypeDlg::OnBusTypeBusAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_String_BusName.GetLength() <= 0)
	{
		AfxMessageBox("车次类型不能为空!");
		return;
	}
	if(m_String_BusName.GetLength() > 12)
	{
		AfxMessageBox("车次类型长度超过定义范围(《12字节)!");
		return;
	}

	//************* 添加车次类型 ************//
	// 初始化变量
	char bus_type[12];
	memset(bus_type, 0, 12);
	strcpy(bus_type, m_String_BusName);
	
	// 添加信息
	int rv;
	rv = DB_BUS_TYPE_Insert(hstmt, bus_type);
	if( rv != 0)
	{
		AfxMessageBox("此车次类型已经存在,无法添加数据,请确认!");
		return;
	}
	else
	{
		AfxMessageBox("添加信息成功!");
	}

	m_ListBox_Bus.AddString(m_String_BusName);
	m_String_BusName = _T("");
	m_BusSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeBusDelete() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if( m_BusSign < 0)
	{
		AfxMessageBox("请先选定要删除的选项?");
		return;
	}

	if( MessageBox("是否真的删除此车次类型","删除确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
	{
		return;
	}

	// 得到删除对象
	CString strBusType;
	m_ListBox_Bus.GetText(m_BusSign, strBusType);
	//************* 删除车次类型 ************//
	// 初始化变量
	char bus_type[12];
	memset(bus_type, 0, 12);
	strcpy(bus_type, strBusType);
	
	// 删除信息
	int rv;
	rv = DB_BUS_TYPE_Delete(hstmt, bus_type);
	if( rv != 0)
	{
		AfxMessageBox("无法删除信息,请“刷新”界面,确认数据是否存在数据!");
		return;
	}
	else
	{
		AfxMessageBox("删除信息成功!");
	}

	//
	m_ListBox_Bus.DeleteString(m_BusSign);
	m_String_BusName = _T("");
	m_BusSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeBusDeleteAll() 
{
	// TODO: Add your control notification handler code here
	if( MessageBox("是否真的删除全部车次类型","删除确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
	{
		return;
	}

	//************* 删除全部车次类型 ************//
	// 删除信息
	int rv;
	rv = DB_BUS_TYPE_Delete_All(hstmt);
	if( rv != 0)
	{
		AfxMessageBox("无法删除信息,请“刷新”界面,确认数据是否存在数据!");
		return;
	}
	else
	{
		AfxMessageBox("删除信息成功!");
	}
	
	m_ListBox_Bus.ResetContent();
	m_String_BusName = _T("");
	m_BusSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeBusModify() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if( m_BusSign < 0)
	{
		AfxMessageBox("请先选定要修改的选项?");
		return;
	}

	if(m_String_BusName.GetLength() <= 0)
	{
		AfxMessageBox("车次类型不能为空!");
		return;
	}

	if(m_String_BusName.GetLength() > 12)
	{
		AfxMessageBox("车次类型长度超过定义范围(《12字节)!");
		return;
	}

	
	if( MessageBox("是否真的修改此车次类型","修改确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
	{
		return;
	}
	
	// 得到原数据
	CString oldBusType;
	m_ListBox_Bus.GetText(m_BusSign, oldBusType);
	//************* 删除车次类型 ************//
	// 初始化变量
	char old_bus_type[12];
	char new_bus_type[12];
	memset(old_bus_type, 0, 12);
	memset(new_bus_type, 0, 12);
	strcpy(old_bus_type, oldBusType);
	strcpy(new_bus_type, m_String_BusName);
	
	// 删除信息
	int rv;
	rv = DB_BUS_TYPE_Modify(hstmt, old_bus_type, new_bus_type);	
	if( rv != 0)
	{
		AfxMessageBox("无法修改信息,请“刷新”界面,确认数据是否存在数据!");
		return;
	}
	else
	{
		AfxMessageBox("修改信息成功!");
	}
	
	//
	m_ListBox_Bus.DeleteString(m_BusSign);
	m_ListBox_Bus.AddString(m_String_BusName);
	m_String_BusName = _T("");
	m_BusSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeStationAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_String_StationName.GetLength() <= 0)
	{
		AfxMessageBox("站点类型不能为空!");
		return;
	}
	if(m_String_StationName.GetLength() > 24)
	{
		AfxMessageBox("车站类型长度超过定义范围(《24字节)!");
		return;
	}
	
	//************* 添加站点类型 ************//
	// 初始化变量
	char station_type[24];
	memset(station_type, 0, 24);
	strcpy(station_type, m_String_StationName);
	
	// 添加信息
	int rv;
	rv = DB_STATION_TYPE_Insert(hstmt, station_type);
	if( rv != 0)
	{
		AfxMessageBox("此站点类型已经存在,无法添加数据,请确认!");
		return;
	}
	else
	{
		AfxMessageBox("添加信息成功!");
	}

	/////
	m_ListBox_Station.AddString(m_String_StationName);

	m_String_StationName = _T("");
	m_StationSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeStationDelete() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if( m_StationSign < 0)
	{
		AfxMessageBox("请先选定要删除的选项?");
		return;
	}

	if( MessageBox("是否真的删除此站点类型","删除确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
	{
		return;
	}

	// 得到删除对象
	CString strStationType;
	m_ListBox_Station.GetText(m_StationSign, strStationType);

	//************* 删除站点类型 ************//
	// 初始化变量
	char station_type[24];
	memset(station_type, 0, 24);
	strcpy(station_type, strStationType);
	
	// 删除信息
	int rv;
	rv = DB_STATION_TYPE_Delete(hstmt, station_type);
	if( rv != 0)
	{
		AfxMessageBox("无法删除信息,请“刷新”界面,确认数据是否存在数据!");
		return;
	}
	else
	{
		AfxMessageBox("删除信息成功!");
	}

	/////
	m_ListBox_Station.DeleteString(m_StationSign);
	m_String_StationName = _T("");
	m_StationSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeStationDeleteAll() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your control notification handler code here
	if( MessageBox("是否真的删除全部站点类型","删除确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
	{
		return;
	}
	
	//************* 删除全部站点类型 ************//
	// 删除信息
	int rv;
	rv = DB_STATION_TYPE_Delete_All(hstmt);
	if( rv != 0)
	{
		AfxMessageBox("无法删除信息,请“刷新”界面,确认数据是否存在数据!");
		return;
	}
	else
	{
		AfxMessageBox("删除信息成功!");
	}

	m_ListBox_Station.ResetContent();
	m_String_StationName = _T("");
	m_StationSign = -1;
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeStationModify() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if( m_StationSign < 0)
	{
		AfxMessageBox("请先选定要修改的选项?");
		return;
	}
	
	if(m_String_StationName.GetLength() <= 0)
	{
		AfxMessageBox("站点类型不能为空!");
		return;
	}
	
	if(m_String_StationName.GetLength() > 24)
	{
		AfxMessageBox("站点类型长度超过定义范围(《24字节)!");
		return;
	}
	
	
	if( MessageBox("是否真的修改此站点类型","修改确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
	{
		return;
	}
	
	// 得到原数据
	CString oldStationType;
	m_ListBox_Station.GetText(m_StationSign, oldStationType);
	//************* 删除站点类型 ************//
	// 初始化变量
	char old_station_type[24];
	char new_station_type[24];
	memset(old_station_type, 0, 24);
	memset(new_station_type, 0, 24);
	strcpy(old_station_type, oldStationType);
	strcpy(new_station_type, m_String_StationName);
	
	// 删除信息
	int rv;
	rv = DB_STATION_TYPE_Modify(hstmt, old_station_type, new_station_type);
	if( rv != 0)
	{
		AfxMessageBox("无法修改信息,请“刷新”界面,确认数据是否存在数据!");
		return;
	}
	else
	{
		AfxMessageBox("修改信息成功!");
	}
	
	//
	m_ListBox_Station.DeleteString(m_StationSign);
	m_ListBox_Station.AddString(m_String_StationName);
	m_String_StationName = _T("");
	m_StationSign = -1;
	UpdateData(FALSE);
}



void CBustypeDlg::OnBusTypeStationClear() 
{
	// TODO: Add your control notification handler code here
	m_String_StationName = _T("");
	UpdateData(FALSE);
}

void CBustypeDlg::OnBusTypeBusClear() 
{
	// TODO: Add your control notification handler code here
	m_String_BusName = _T("");
	UpdateData(FALSE);
}

void CBustypeDlg::OnSelchangeBusTypeListBus() 
{
	// TODO: Add your control notification handler code here
	m_BusSign = m_ListBox_Bus.GetCurSel();
	m_ListBox_Bus.GetText(m_BusSign, m_String_BusName);
	UpdateData(FALSE);
}

void CBustypeDlg::OnSelchangeBusTypeListStation() 
{
	// TODO: Add your control notification handler code here
	m_StationSign = m_ListBox_Station.GetCurSel();
	m_ListBox_Station.GetText(m_StationSign, m_String_StationName);
	UpdateData(FALSE);
}

void CBustypeDlg::OnCancel() 
{
	// TODO: Add your message handler code here and/or call default
	return;
}

void CBustypeDlg::OnOK() 
{
	// TODO: Add your message handler code here and/or call default
	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -