changenamedialog.cpp

来自「全国交通咨询系统源代码」· C++ 代码 · 共 197 行

CPP
197
字号
// ChangeNameDialog.cpp : implementation file
//

#include "stdafx.h"
#include "map.h"
#include "ChangeNameDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChangeNameDialog dialog


CChangeNameDialog::CChangeNameDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CChangeNameDialog::IDD, pParent),m_pgraph(NULL)
{
	posname=_T("");
	//{{AFX_DATA_INIT(CChangeNameDialog)
	m_changedit = _T("");
	m_showedit = _T("");
	//}}AFX_DATA_INIT
}


void CChangeNameDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChangeNameDialog)
	DDX_Text(pDX, IDC_CHANG_EDIT, m_changedit);
	DDV_MaxChars(pDX, m_changedit, 15);
	DDX_Text(pDX, IDC_SHOW_EDIT, m_showedit);
	DDV_MaxChars(pDX, m_showedit, 15);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChangeNameDialog, CDialog)
	//{{AFX_MSG_MAP(CChangeNameDialog)
	ON_EN_KILLFOCUS(IDC_SHOW_EDIT, OnKillfocusShowEdit)
	ON_BN_CLICKED(IDC_PREV_BUTTON, OnPrevButton)
	ON_BN_CLICKED(IDC_NEXT_BUTTON, OnNextButton)
	ON_BN_CLICKED(ID_ACCEPT, OnAccept)
	ON_BN_CLICKED(IDC_YES, OnYes)
	ON_BN_CLICKED(IDCANCEL, OnCa)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChangeNameDialog message handlers

void CChangeNameDialog::SetALGraph(ALGraph * temp)
{
	m_pgraph=temp;
}

void CChangeNameDialog::OnKillfocusShowEdit() 
{
	// TODO: Add your control notification handler code here
	posname=m_showedit;
	UpdateData(true);//m_showedit改为新值
	NameNode temp;
	temp.GetNamenext()=m_showedit;
	if(m_templist.Find(temp)==NULL) 
	{
		AfxMessageBox("你输入的城市不存在!");
		m_showedit=posname;
		UpdateData(false);
		return;
	}
	posname=m_showedit;
}

BOOL CChangeNameDialog::OnInitDialog()
{
	if(m_pgraph!=NULL&&m_pgraph->m_vexnum) 
	{
		for(int i=0;i<m_pgraph->m_vexnum;i++)
		{
			NameNode temp;
			temp.GetNamenext()=temp.GetNameprev()=(m_pgraph->m_vertices)[i].GetCityName();
			m_templist.AddTail(temp);
		}
	}
	posname=m_showedit=m_templist.GetHead().GetNameprev();
	return CDialog::OnInitDialog();
}

void CChangeNameDialog::OnPrevButton() 
{
	// TODO: Add your control notification handler code here
	if(m_pgraph->m_vexnum==0) return;
	if(posname.Find(" ")!=-1) return;
	POSITION pos;
	NameNode temp;
	temp.GetNamenext()=posname;
	if((pos=m_templist.Find(temp))==NULL) return;
	m_templist.GetPrev(pos);
	if(pos==NULL) return;
	temp=m_templist.GetAt(pos);
	m_showedit=posname=temp.GetNamenext();
	UpdateData(false);
}

//DEL CString CChangeNameDialog::posname()
//DEL {
//DEL 
//DEL }

void CChangeNameDialog::OnNextButton() 
{
	// TODO: Add your control notification handler code here
	if(m_pgraph->m_vexnum==0) return;
	if(posname.Find(" ")!=-1) return;
	POSITION pos;
	NameNode temp;
	temp.GetNamenext()=posname;
	if((pos=m_templist.Find(temp))==NULL) return;
	m_templist.GetNext(pos);
	if(pos==NULL) return;
	temp=m_templist.GetAt(pos);
	m_showedit=posname=temp.GetNamenext();
	UpdateData(false);
}

//DEL void CChangeNameDialog::OnKillfocusChangEdit() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	if(m_pgraph->m_vexnum==0) return;
//DEL 	UpdateData(true);
//DEL 	if(m_changedit.Find(" ")!=-1) {AfxMessageBox("输入不能带空格!");return;}
//DEL 	if(m_pgraph->CityLocal(m_changedit)) {AfxMessageBox("你输入的城市已经存在!");return;}
//DEL 	int i;
//DEL 	if(!m_pgraph->CityLocal(m_showedit,i)) {AfxMessageBox("内部错误,发生在查找m_showedit时出错!");return;}
//DEL 	posname=m_showedit=(m_pgraph->m_vertices)[i].GetCityName()=m_changedit;
//DEL 	m_changedit=_T("");
//DEL 	UpdateData(false);
//DEL }

void CChangeNameDialog::OnAccept() 
{
	// TODO: Add your control notification handler code here
	if(m_pgraph->m_vexnum==0) return;
 	UpdateData(true);
 	if(m_changedit.Find(" ")!=-1) {AfxMessageBox("输入不能带空格!");m_changedit=_T("");UpdateData(false);return;}
 	NameNode temp;
	temp.GetNamenext()=m_changedit;
	if(m_templist.Find(temp)!=NULL) {AfxMessageBox("你输入的城市已经存在!");m_changedit=_T("");UpdateData(false);return;}
 	POSITION pos;
	temp.GetNamenext()=m_showedit;
	if((pos=m_templist.Find(temp))==NULL) {AfxMessageBox("error");return;}
	m_templist.GetAt(pos).GetNamenext()=m_changedit;
	posname=m_showedit=m_changedit;
 	m_changedit=_T("");
 	UpdateData(false);
}

//DEL void CChangeNameDialog::OnOK()
//DEL {
//DEL 
//DEL }

void CChangeNameDialog::OnYes() 
{
	// TODO: Add your control notification handler code here
	int num;
	num=m_templist.GetCount();
	POSITION pos=m_templist.GetHeadPosition();
	for(int i=1;i<=num;i++)
	{
		int state=-1;
		if(!(m_pgraph->CityLocal(m_templist.GetAt(pos).GetNameprev(),state))) return;
		(m_pgraph->m_vertices)[state].GetCityName()=m_templist.GetAt(pos).GetNamenext();
		m_templist.GetNext(pos);
	}
	EndDialog(IDC_YES);
}

void CChangeNameDialog::OnCa() 
{
	// TODO: Add your control notification handler code here
	EndDialog(IDCANCEL);
}

void CChangeNameDialog::OnOK()
{
	OnAccept();
}

void CChangeNameDialog::OnCancel()
{

}

⌨️ 快捷键说明

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