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

📄 bustypesetview.cpp

📁 汽车站售票管理系统,源代码完整无错
💻 CPP
字号:
// BustypesetView.cpp : implementation file
//

#include "stdafx.h"
#include "StationManage.h"
#include "BustypesetView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBustypesetView

IMPLEMENT_DYNCREATE(CBustypesetView, CRecordView)

CBustypesetView::CBustypesetView()
	: CRecordView(CBustypesetView::IDD)
{
	//{{AFX_DATA_INIT(CBustypesetView)
	m_pSet = NULL;
	m_bustype = _T("");
	m_bustypeid = 0;
	m_seattotals = 0;
	//}}AFX_DATA_INIT
}

CBustypesetView::~CBustypesetView()
{
	if (!((CStationManageApp*)AfxGetApp())->m_bustypesettingcontrol)
	{
		((CStationManageApp*)AfxGetApp())->m_bustypesetting=0;
	}
	if (m_pSet)
		delete m_pSet;
}

void CBustypesetView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBustypesetView)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Text(pDX, IDC_BUSTYPE, m_bustype);
	DDX_Text(pDX, IDC_BUSTYPEID, m_bustypeid);
	DDX_Text(pDX, IDC_SEATTOTALS, m_seattotals);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBustypesetView, CRecordView)
	//{{AFX_MSG_MAP(CBustypesetView)
	ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_CHANGE, OnChange)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_RETURN, OnReturn)
	ON_BN_CLICKED(IDC_REFURBISH, OnRefurbish)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBustypesetView diagnostics

#ifdef _DEBUG
void CBustypesetView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CBustypesetView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBustypesetView message handlers

CRecordset* CBustypesetView::OnGetRecordset()
{
	if (m_pSet != NULL)
		return m_pSet;

	m_pSet = new CBustypeSet(NULL);
	m_pSet->Open();

	return m_pSet;
}

CBustypeSet* CBustypesetView::GetRecordset()
{
	CBustypeSet* pData = (CBustypeSet*) OnGetRecordset();
	ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CBustypeSet)));
	return pData;
}

void CBustypesetView::OnInitialUpdate()
{
	BeginWaitCursor();
	GetRecordset();
	CRecordView::OnInitialUpdate();
	GetDocument()->SetTitle("车型管理");
	GetParent()->SetWindowText("车型管理");
	EndWaitCursor();
	RECT rectlist;
	m_list.GetWindowRect(&rectlist);
	int listwidth=rectlist.right-rectlist.left;
	DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
	m_list.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
	m_list.InsertColumn(0,"车辆ID",LVCFMT_LEFT,listwidth/3-5);
	m_list.InsertColumn(1,"车辆类型",LVCFMT_LEFT,listwidth/3-5);
	m_list.InsertColumn(2,"座位个数",LVCFMT_LEFT,listwidth/3-5);
	Showlist();	
	curiItem=0;
	operation = 0;
	Getvalue();
	m_list.SetItemState(curiItem,LVIS_SELECTED,LVIS_SELECTED);
	EnableView(true);
	UpdateData(FALSE);
}

void CBustypesetView::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;  
	curiItem = pNMListView->iItem;
	if(curiItem != -1)   
	{   
		Getvalue();
		EnableView(true);
		operation = 0;
	}
	UpdateData(FALSE); 
	*pResult = 0;
}

void CBustypesetView::Getvalue()
{
	m_bustypeid=atoi(m_list.GetItemText(curiItem,0));
	m_bustype=m_list.GetItemText(curiItem,1);
	m_seattotals=atoi(m_list.GetItemText(curiItem,2));
	UpdateData(FALSE);
}

void CBustypesetView::Showlist()
{
	if (m_pSet->IsOpen())
	{
		m_pSet->Close();
	}	
	m_pSet->Open();
	m_list.DeleteAllItems();
	m_pSet->MoveFirst();
	if (!m_pSet->IsEOF())
	{
		while(!m_pSet->IsEOF())
			m_pSet->MoveNext();
		int cout=m_pSet->GetRecordCount();
		m_pSet->MoveFirst();
		while(!m_pSet->IsEOF())
		{	
			CString strValue;
			int nCount=m_list.GetItemCount();
			m_list.InsertItem(nCount,strValue);
			strValue.Format("%d",m_pSet->m_bustype_id);
			m_list.SetItemText(nCount,0,strValue);	
			m_pSet->m_bustype.TrimRight();
			m_list.SetItemText(nCount,1,m_pSet->m_bustype);			
			strValue.Format("%d",m_pSet->m_seat_total);			
			m_list.SetItemText(nCount,2,strValue);
			m_pSet->MoveNext();
		}
	}
}

void CBustypesetView::EnableView(bool b)
{
	GetDlgItem(IDC_ADD)->EnableWindow(b);
	GetDlgItem(IDC_CHANGE)->EnableWindow(b);
	GetDlgItem(IDC_DELETE)->EnableWindow(b);
	GetDlgItem(IDC_SAVE)->EnableWindow(!b);
	GetDlgItem(IDC_RETURN)->EnableWindow(!b);
	GetDlgItem(IDC_BUSTYPEID)->EnableWindow(!b);
	GetDlgItem(IDC_BUSTYPE)->EnableWindow(!b);
	GetDlgItem(IDC_SEATTOTALS)->EnableWindow(!b);
	UpdateData(FALSE);
}

void CBustypesetView::OnAdd() 
{
	// TODO: Add your control notification handler code here
	EnableView(false);
	m_bustypeid=0;
	m_bustype.Empty();
	m_seattotals=0;	
	UpdateData(FALSE);
	operation = 1;
	curiItem=m_list.GetItemCount();
}

void CBustypesetView::OnChange() 
{
	// TODO: Add your control notification handler code here
	if (curiItem==m_list.GetItemCount())
	{
		MessageBox("请选择您要修改的行!","警告",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	EnableView(FALSE);
	operation = 2;
}

void CBustypesetView::OnDelete() 
{
	// TODO: Add your control notification handler code here
	if (curiItem==m_list.GetItemCount())
	{
		MessageBox("请选择您要删除的行!","警告",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	if (IDOK==MessageBox("确认删除?","提示",MB_OKCANCEL|MB_ICONQUESTION))
	{
		if (!m_pSet->IsOpen())
		{
			m_pSet->Open();
		}
		m_pSet->MoveFirst();
		m_pSet->Move(curiItem);
		m_pSet->Delete();
		m_pSet->Requery();		
		m_list.DeleteItem(curiItem);
		curiItem=0;
		Getvalue();
		MessageBox("该数据已经删除!","删除成功",MB_OK|MB_ICONINFORMATION);
		UpdateData(FALSE);
	}
}

void CBustypesetView::OnSave() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if (m_bustypeid==0 || m_bustype == "" || m_seattotals == 0)
	{
		MessageBox("请输入正确的数据!","警告",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	if (operation==0)
	{
		return;
	}
	if (operation == 1)
	{
		if (!m_pSet->IsOpen())
		{
			m_pSet->Open();
		}
		m_pSet->AddNew();   //在表的末尾添加新记录
		m_pSet->m_bustype_id = m_bustypeid;
		m_pSet->m_bustype = m_bustype;
		m_pSet->m_seat_total = m_seattotals;
		m_pSet->Update();
		m_pSet->Requery();	
		Showlist();
		MessageBox("增加成功!","增加成功",MB_OK|MB_ICONINFORMATION);
		EnableView(true);
		operation = 0;
		return;
	}
	else
	{
		if (!m_pSet->IsOpen())
		{
			m_pSet->Open();
		}
		m_pSet->MoveFirst();
		m_pSet->Move(curiItem);
		m_pSet->Edit();
		m_pSet->m_bustype_id = m_bustypeid;
		m_pSet->m_bustype = m_bustype;
		m_pSet->m_seat_total = m_seattotals;
		m_pSet->Update();
		m_pSet->Requery();	
		Showlist();
		MessageBox("修改成功!","修改成功",MB_OK|MB_ICONINFORMATION);
		EnableView(true);
		operation = 0;
		return;
	}
}

void CBustypesetView::OnReturn() 
{
	// TODO: Add your control notification handler code here
	EnableView(TRUE);
}

void CBustypesetView::OnRefurbish() 
{
	// TODO: Add your control notification handler code here
	EnableView(TRUE);
	Showlist();
}

⌨️ 快捷键说明

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