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

📄 pricesettingview.cpp

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

#include "stdafx.h"
#include "StationManage.h"
#include "PricesettingView.h"
#include "RouteSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPricesettingView

IMPLEMENT_DYNCREATE(CPricesettingView, CRecordView)

CPricesettingView::CPricesettingView()
	: CRecordView(CPricesettingView::IDD)
{
	//{{AFX_DATA_INIT(CPricesettingView)
	m_pSet = NULL;
	m_addpercent = 0.0;
	m_price = 0.0;
	m_reducepercent = 0.0;
	//}}AFX_DATA_INIT
	curiItem = 0;
	operation = 0;
}

CPricesettingView::~CPricesettingView()
{
	if (!((CStationManageApp*)AfxGetApp())->m_pricesettingcontrol)
	{
		((CStationManageApp*)AfxGetApp())->m_pricesetting=0;
	}
	if (m_pSet)
		delete m_pSet;
}

void CPricesettingView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPricesettingView)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Text(pDX, IDC_ADD, m_addpercent);
	DDX_Text(pDX, IDC_SETEDIT, m_price);
	DDX_Text(pDX, IDC_REDUCE, m_reducepercent);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPricesettingView, CRecordView)
	//{{AFX_MSG_MAP(CPricesettingView)
	ON_BN_CLICKED(IDC_ADDBYPERCENT, OnAddbypercent)
	ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
	ON_BN_CLICKED(IDC_RETURN, OnReturn)
	ON_BN_CLICKED(IDC_REDUCEBYPERCENT, OnReducebypercent)
	ON_BN_CLICKED(IDC_SET, OnSet)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_REFURBISH, OnRefurbish)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPricesettingView diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CPricesettingView message handlers

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

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

	return m_pSet;
}

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

void CPricesettingView::OnInitialUpdate()
{
	BeginWaitCursor();
	GetRecordset();
	CRecordView::OnInitialUpdate();
	GetDocument()->SetTitle("票价调整");
	GetParent()->SetWindowText("票价调整");
	EndWaitCursor();
	EnableView(true);
	RECT rectlist;
	m_list.GetWindowRect(&rectlist);
	int listwidth=rectlist.right-rectlist.left;
	DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_FULLROWSELECT;
	m_list.SetExtendedStyle(dwExtendedStyle);
	m_list.InsertColumn(0,"站点ID",LVCFMT_LEFT,listwidth/3-20);
	m_list.InsertColumn(1,"终点站",LVCFMT_LEFT,listwidth/3);
	m_list.InsertColumn(2,"价格",LVCFMT_LEFT,listwidth/3);	
	Showlist();
	curiItem = 0;
	m_list.SetItemState(curiItem,LVIS_SELECTED,LVIS_SELECTED);	
}
void CPricesettingView::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_station_id);
			m_list.SetItemText(nCount,0,strValue);
			m_pSet->m_station_name.TrimRight();
			m_list.SetItemText(nCount,1,m_pSet->m_station_name);
			strValue.Format("%10.2lf",m_pSet->m_price);
			m_list.SetItemText(nCount,2,strValue);
			m_pSet->MoveNext();
		}
	}
}

void CPricesettingView::EnableView(bool b)
{
	GetDlgItem(IDC_ADDBYPERCENT)->EnableWindow(b);
	GetDlgItem(IDC_REDUCEBYPERCENT)->EnableWindow(b);
	GetDlgItem(IDC_SET)->EnableWindow(b);
	GetDlgItem(IDC_SAVE)->EnableWindow(!b);
	GetDlgItem(IDC_RETURN)->EnableWindow(!b);
	GetDlgItem(IDC_ADD)->EnableWindow(!b);
	GetDlgItem(IDC_REDUCE)->EnableWindow(!b);
	GetDlgItem(IDC_SETEDIT)->EnableWindow(!b);
}

void CPricesettingView::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)   
	{   
		EnableView(true);
		operation=0;
		m_addpercent = 0.0;
		m_reducepercent = 0.0;
		m_price = 0.0;
	}
	UpdateData(FALSE); 
	*pResult = 0;
}
void CPricesettingView::OnAddbypercent() 
{
	// TODO: Add your control notification handler code here
	EnableView(FALSE);
	GetDlgItem(IDC_REDUCE)->EnableWindow(FALSE);
	GetDlgItem(IDC_SETEDIT)->EnableWindow(FALSE);
	operation = 1;
}

void CPricesettingView::OnReducebypercent() 
{
	// TODO: Add your control notification handler code here
	EnableView(FALSE);
	GetDlgItem(IDC_ADD)->EnableWindow(FALSE);
	GetDlgItem(IDC_SETEDIT)->EnableWindow(FALSE);
	operation = 2;
}

void CPricesettingView::OnSet() 
{
	// TODO: Add your control notification handler code here
	EnableView(FALSE);
	GetDlgItem(IDC_ADD)->EnableWindow(FALSE);
	GetDlgItem(IDC_REDUCE)->EnableWindow(FALSE);
	operation = 3;
}

void CPricesettingView::OnSave() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString info;
	int stationid;
	CString stationname;
	CString strValue;
	CRouteSet routeset;
	if (operation==1)
	{
		m_pSet->MoveFirst();
		m_pSet->Move(curiItem);	
		stationid=m_pSet->m_station_id;
		stationname=m_pSet->m_station_name;
		m_pSet->Edit();
		m_pSet->m_price=(atof(m_list.GetItemText(curiItem,2)))*(1+m_addpercent/100);
		m_price=m_pSet->m_price;
		m_pSet->Update();
		m_pSet->Requery();

		routeset.Open();
		routeset.MoveFirst();
		routeset.Move(curiItem);
		routeset.Edit();
		routeset.m_price=m_price;
		routeset.Update();
		routeset.Requery();
		routeset.Close();

		strValue.Format("%10.2lf",m_price);
		m_list.SetItemText(curiItem,2,strValue);		
	}
	else
	{
		if (operation==2)
		{
			m_pSet->MoveFirst();
			m_pSet->Move(curiItem);
			stationid=m_pSet->m_station_id;
			stationname=m_pSet->m_station_name;
			m_pSet->Edit();
			m_pSet->m_price=(atof(m_list.GetItemText(curiItem,2)))*(1-m_reducepercent/100);
			m_price=m_pSet->m_price;
			m_pSet->Update();
			m_pSet->Requery();

			routeset.Open();
			routeset.MoveFirst();
			routeset.Move(curiItem);
			routeset.Edit();
			routeset.m_price=m_price;
			routeset.Update();
			routeset.Requery();
			routeset.Close();

			strValue.Format("%10.2lf",m_price);
			m_list.SetItemText(curiItem,2,strValue);

		}
		else
		{
			if (operation==3)
			{
				m_pSet->MoveFirst();
				m_pSet->Move(curiItem);
				stationid=m_pSet->m_station_id;
				stationname=m_pSet->m_station_name;
				m_pSet->Edit();
				m_pSet->m_price=m_price;
				m_pSet->Update();
				m_pSet->Requery();

				routeset.Open();
				routeset.MoveFirst();
				routeset.Move(curiItem);
				routeset.Edit();
				routeset.m_price=m_price;
				routeset.Update();
				routeset.Requery();
				routeset.Close();

				strValue.Format("%10.2lf",m_price);
				m_list.SetItemText(curiItem,2,strValue);
			}
			else
			{
				return;
			}
		}
	}
	info.Format("站点ID为%d,站点名为 %s的价格已经修改为%s元!",stationid,stationname,strValue);
	MessageBox(info,"价格修改成功!",MB_OK | MB_ICONINFORMATION);
	EnableView(TRUE);
	operation=0;
	m_addpercent = 0.0;
	m_reducepercent = 0.0;
	m_price = 0.0;
	UpdateData(FALSE);
}

void CPricesettingView::OnReturn() 
{
	// TODO: Add your control notification handler code here
	EnableView(TRUE);
	operation=0;
	m_addpercent = 0.0;
	m_reducepercent = 0.0;
	m_price = 0.0;
	UpdateData(FALSE);
}

void CPricesettingView::OnRefurbish() 
{
	// TODO: Add your control notification handler code here
	EnableView(TRUE);
	operation=0;
	m_addpercent = 0.0;
	m_reducepercent = 0.0;
	m_price = 0.0;
	UpdateData(FALSE);
	Showlist();
}

⌨️ 快捷键说明

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