📄 busrouteupdatedlg.cpp
字号:
// BusRouteUpdateDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BusQuery.h"
#include "BusRouteUpdateDlg.h"
#include "DB_Func.h"
#include <math.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;
extern LVITEM Item;
/////////////////////////////////////////////////////////////////////////////
// CBusRouteUpdateDlg dialog
CBusRouteUpdateDlg::CBusRouteUpdateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBusRouteUpdateDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBusRouteUpdateDlg)
m_String_Remark = _T(" ");
m_String_BusType = _T("");
m_Int_BusNumber = 0;
//}}AFX_DATA_INIT
}
void CBusRouteUpdateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBusRouteUpdateDlg)
DDX_Control(pDX, IDC_ROUTE_UPDATE_COMBO_TYPE, m_ComboBox_BusType);
DDX_Control(pDX, IDC_ROUTE_UPDATE_TICKET, m_Button_Ticket);
DDX_Control(pDX, IDC_ROUTE_UPDATE_LIST, m_ListCtrl_Route);
DDX_Control(pDX, IDC_ROUTE_UPDATE_LISTBOX_STATION, m_ListBox_Station);
DDX_Control(pDX, IDC_ROUTE_UPDATE_LISTBOX_ROUTE, m_ListBox_Route);
DDX_Text(pDX, IDC_ROUTE_UPDATE_REMARK, m_String_Remark);
DDX_CBString(pDX, IDC_ROUTE_UPDATE_COMBO_TYPE, m_String_BusType);
DDX_Text(pDX, IDC_ROUTE_UPDATE_NUMBER, m_Int_BusNumber);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBusRouteUpdateDlg, CDialog)
//{{AFX_MSG_MAP(CBusRouteUpdateDlg)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_LISTBOX_INSERT, OnRouteUpdateListboxInsert)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_CLEAR, OnRouteUpdateClear)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_ADD, OnRouteUpdateAdd)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_DELETE, OnRouteUpdateDelete)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_MODIFY, OnRouteUpdateModify)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_LISTBOX_ADD, OnRouteUpdateListboxAdd)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_LISTBOX_CLEAR, OnRouteUpdateListboxClear)
ON_BN_CLICKED(IDC_ROUTE_UPDATE_LISTBOX_DELETE, OnRouteUpdateListboxDelete)
ON_NOTIFY(NM_CLICK, IDC_ROUTE_UPDATE_LIST, OnClickRouteUpdateList)
ON_LBN_SELCHANGE(IDC_ROUTE_UPDATE_LISTBOX_STATION, OnSelchangeRouteUpdateListboxStation)
ON_LBN_SELCHANGE(IDC_ROUTE_UPDATE_LISTBOX_ROUTE, OnSelchangeRouteUpdateListboxRoute)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBusRouteUpdateDlg message handlers
BOOL CBusRouteUpdateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rc(0, 0, 0, 0);
GetParent()->GetClientRect(&rc);
((CTabCtrl*)GetParent())->AdjustRect(false, &rc);
MoveWindow(&rc);
//////////////////////////////////////////////////////////////////////////
// 初始化
nRouteCount = 0;
m_list_hanghao = -1;
m_listbox_route_hanghao = -1;
m_listbox_station_hanghao = -1;
// 添加单元格
HWND h=GetDlgItem(IDC_ROUTE_UPDATE_LIST)->m_hWnd;
DWORD dwExStyle=ListView_GetExtendedListViewStyle(h);
dwExStyle |= LVS_EX_FULLROWSELECT|LVS_LIST|LVS_NOLABELWRAP;
ListView_SetExtendedListViewStyle(h,dwExStyle);
m_ListCtrl_Route.SetBkColor(RGB(240,247,233));
m_ListCtrl_Route.SetTextBkColor(RGB(240,247,233));
// 添加列:
LV_COLUMN lc;
lc.mask = LVCF_FMT | LVCF_WIDTH |
LVCF_TEXT | LVCF_SUBITEM;
lc.fmt = LVCFMT_LEFT;
lc.cx = 32;
lc.iSubItem = 0;
lc.pszText = "序号";
m_ListCtrl_Route.InsertColumn(0, &lc);
lc.cx = 44;
lc.iSubItem = 1;
lc.pszText = "路线号";
m_ListCtrl_Route.InsertColumn(1, &lc);
lc.cx = 60;
lc.iSubItem = 2;
lc.pszText = "类型说明";
m_ListCtrl_Route.InsertColumn(2, &lc);
lc.cx = 32;
lc.iSubItem = 3;
lc.pszText = "月票";
m_ListCtrl_Route.InsertColumn(3, &lc);
lc.cx = 175;
lc.iSubItem = 4;
lc.pszText = "详细线路";
m_ListCtrl_Route.InsertColumn(4, &lc);
lc.cx = 45;
lc.iSubItem = 5;
lc.pszText = "备注";
m_ListCtrl_Route.InsertColumn(5, &lc);
//--------------
// 初始化站点列表
CBusRouteUpdateDlg::StationInforQuery();
// 初始化路线类型
CBusRouteUpdateDlg::StationTypeQuery();
// 初始化路线列表
CBusRouteUpdateDlg::RouteInforQuery();
//-----------------
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBusRouteUpdateDlg::OnOK()
{
// TODO: Add your message handler code here and/or call default
return;
}
void CBusRouteUpdateDlg::OnCancel()
{
// TODO: Add your message handler code here and/or call default
return;
}
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CBusRouteUpdateDlg::StationInforQuery()
{
// TODO: Add your message handler code here and/or call default
//---------------- 查询站点信息 ----------------//
//初始化变量
STATION_INFOR station_infor;
STATION_INFOR *station_infor_head;
station_infor_head = new STATION_INFOR;
memset(&station_infor, 0, sizeof(STATION_INFOR));
memset(station_infor_head,0, sizeof(STATION_INFOR));
//查询信息
int rv;
rv = DB_STATION_INFOR_Query(hstmt,&station_infor,station_infor_head);
if( rv != 0 )
{
AfxMessageBox("数据库中无信息,请添加信息!");
delete station_infor_head;
return ;
}
// 列表显示
m_ListBox_Station.ResetContent();
STATION_INFOR *pTemp_staiton;
while( station_infor_head != NULL )
{
pTemp_staiton = station_infor_head;
m_ListBox_Station.AddString(pTemp_staiton->Station_Name);
station_infor_head = station_infor_head->next;
delete pTemp_staiton;
}
return;
}
void CBusRouteUpdateDlg::StationTypeQuery()
{
//-------查询所有车次类型 --------//
// 初始化变量
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 ;
}
// 列表显示
m_ComboBox_BusType.ResetContent();
BUS_TYPE *pTemp_bus;
while( bus_type_head != NULL )
{
pTemp_bus = bus_type_head;
m_ComboBox_BusType.AddString(pTemp_bus->Bus_Type_Name);
bus_type_head = bus_type_head->next;
delete pTemp_bus;
}
}
void CBusRouteUpdateDlg::RouteInforQuery()
{
// TODO: Add your message handler code here and/or call default
//---------------- 查询所有线路信息信息 ----------------//
//初始化变量
BUS_INFOR bus_infor;
BUS_INFOR *bus_infor_head;
bus_infor_head = new BUS_INFOR;
memset(&bus_infor, 0, sizeof(BUS_INFOR));
memset(bus_infor_head, 0, sizeof(BUS_INFOR));
//查询信息
int rv;
rv = DB_BUS_INFOR_Query(hstmt,&bus_infor,bus_infor_head);
if( rv != 0 )
{
//AfxMessageBox("数据库中无信息,请添加信息!");
delete bus_infor_head;
return ;
}
//--------显示信息
m_ListCtrl_Route.DeleteAllItems();
BUS_INFOR *p;
CString str;
char temp[8];
int j = 0;
while ( bus_infor_head != NULL )
{
p = bus_infor_head;
//
j = j+1;
itoa(j,temp,10);
str = temp;
if( j < 10 )
{
str = "00"+str;
}
if( (10 <= j) && (j < 100) )
{
str = "0"+str;
}
Item.mask=LVIF_IMAGE|LVIF_TEXT;
Item.pszText=str.GetBuffer(str.GetLength());
m_ListCtrl_Route.InsertItem(&Item);
//
j = j-1;
//
itoa(p->Bus_Number,temp,10);
str = temp;
m_ListCtrl_Route.SetItemText(j,1,str);
str = p->Bus_Type_Name;
m_ListCtrl_Route.SetItemText(j,2,str);
if( p->Bus_Ticket == 0 )
{
str = "有";
}
else
{
str = "无";
}
m_ListCtrl_Route.SetItemText(j,3,str);
str = p->Bus_Route;
m_ListCtrl_Route.SetItemText(j,4,str);
str = p->Bus_Remark;
m_ListCtrl_Route.SetItemText(j,5,str);
//
bus_infor_head = bus_infor_head->next;
delete p;
j = j+1;
}
m_list_all = j;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CBusRouteUpdateDlg::OnRouteUpdateListboxInsert()
{
// TODO: Add your control notification handler code here
if( m_listbox_station_hanghao < 0 )
{
AfxMessageBox("请先在“站点列表”内选定要插入的站点");
return;
}
if( m_listbox_route_hanghao < 0 )
{
AfxMessageBox("请先在选定要插入的位置");
return;
}
CString str;
m_ListBox_Station.GetText(m_listbox_station_hanghao, str);
m_ListBox_Route.InsertString(m_listbox_route_hanghao, str);
//
nRouteCount = nRouteCount+1;
}
void CBusRouteUpdateDlg::OnRouteUpdateListboxAdd()
{
// TODO: Add your control notification handler code here
if( m_listbox_station_hanghao < 0 )
{
AfxMessageBox("请先在“站点列表”内选定要添加的站点");
return;
}
CString str;
m_ListBox_Station.GetText(m_listbox_station_hanghao,str);
m_ListBox_Route.AddString(str);
nRouteCount = nRouteCount+1;
}
void CBusRouteUpdateDlg::OnRouteUpdateListboxClear()
{
// TODO: Add your control notification handler code here
if( MessageBox("是否真的清空路线信息,这样将会丢失信息","清空确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
{
return;
}
m_ListBox_Route.ResetContent();
m_listbox_route_hanghao = -1;
nRouteCount = 0;
}
void CBusRouteUpdateDlg::OnRouteUpdateListboxDelete()
{
// TODO: Add your control notification handler code here
if( m_listbox_route_hanghao < 0 )
{
AfxMessageBox("请先在选定要删除的站点");
return;
}
m_ListBox_Route.DeleteString(m_listbox_route_hanghao);
m_listbox_route_hanghao = -1;
nRouteCount = nRouteCount-1;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CBusRouteUpdateDlg::OnRouteUpdateClear()
{
// TODO: Add your control notification handler code here
if( MessageBox("是否真的删除全部线路信息,这样将会丢失全部站点信息","删除确认",MB_YESNO|MB_ICONQUESTION) != IDYES )
{
return;
}
//---- 删除全部线路信息型
// 删除信息
int rv;
rv = DB_BUS_INFOR_Delete_All(hstmt);
if( rv != 0)
{
AfxMessageBox("无法删除信息,请“刷新”界面,确认数据是否存在数据!");
return;
}
else
{
AfxMessageBox("删除信息成功!");
}
//重新初始化窗口信息
m_ListCtrl_Route.DeleteAllItems();
m_list_hanghao = -1;
m_list_all = -1;
m_Int_BusNumber = 0;
m_String_Remark = _T(" ");
m_String_BusType = _T("");
m_Button_Ticket.SetCheck(0);
m_ListBox_Route.ResetContent();
nRouteCount = 0;
UpdateData(FALSE);
}
void CBusRouteUpdateDlg::OnRouteUpdateAdd()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//-----判断输入信息是否符合条件
if( (m_Int_BusNumber < 0) || (m_Int_BusNumber >= 128) )
{
AfxMessageBox("车次范围【0-128】!");
return;
}
int num = m_ComboBox_BusType.GetCurSel();
if( num < 0 )
{
AfxMessageBox("请先选定路线类型!");
return;
}
if( nRouteCount <= 0)
{
AfxMessageBox("路线列表为空,你还未设置该线路的车行路线,不能存入!");
return;
}
//---------添加信息---------//
//---赋值
BUS_INFOR bus_infor;
memset(&bus_infor, 0, sizeof(BUS_INFOR));
strcpy(bus_infor.Bus_Type_Name, m_String_BusType);
strcpy(bus_infor.Bus_Remark, m_String_Remark);
bus_infor.Bus_Number = m_Int_BusNumber;
// 判断数据是否存在
int rv;
rv = DB_BUS_INFOR_Query_IsTrue(hstmt, bus_infor.Bus_Number, bus_infor.Bus_Type_Name);
if(rv == 0)
{
AfxMessageBox("此路线公交车已存在,不能添加!");
return;
}
int nButtonSign = m_Button_Ticket.GetCheck();
if( nButtonSign == 1 )
{
bus_infor.Bus_Ticket = 0;
}
else
{
bus_infor.Bus_Ticket = -1;
}
// 路线转化
CString strStation;
CString strRoute = "";
for( int i=0; i<nRouteCount-1; i++ ) // 读取Listbox
{
m_ListBox_Route.GetText(i, strStation);
rv = UpdateStationInfor(strStation, bus_infor.Bus_Number, 1); // 更新站点信息
if(rv != 0)
{
return;
}
strRoute = strRoute+strStation+"->";
}
m_ListBox_Route.GetText(nRouteCount-1, strStation);
rv = UpdateStationInfor(strStation, bus_infor.Bus_Number, 1); // 更新站点信息
if(rv != 0)
{
return;
}
strRoute = strRoute+strStation;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -