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

📄 tracfficdlg.cpp

📁 一个好的旅游管理系统,分享一下.不错的啊 .
💻 CPP
字号:
// TRACFFICDLG.cpp : implementation file
//

#include "stdafx.h"
#include "常州旅游管理系统.h"
#include "TRACFFICDLG.h"
#include "TracfficDlgSet.h"
#include "GongJiaoDlg.h"
#include "常州旅游管理系统View.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// TRACFFICDLG dialog


TRACFFICDLG::TRACFFICDLG(CWnd* pParent /*=NULL*/)
	: CDialog(TRACFFICDLG::IDD, pParent)
{
	//{{AFX_DATA_INIT(TRACFFICDLG)
	m_address = _T("");
	m_resname = _T("");
	m_trac = _T("");
	m_id = 0;
	isAdd=FALSE;
	isEdit=FALSE;
	//}}AFX_DATA_INIT
}


void TRACFFICDLG::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(TRACFFICDLG)
	DDX_Control(pDX, IDOK, m_ok);
	DDX_Control(pDX, IDC_PRE, m_pre);
	DDX_Control(pDX, IDC_NEXT, m_next);
	DDX_Control(pDX, IDC_LAST, m_last);
	DDX_Control(pDX, IDC_GONGJIAO, m_gongjiao);
	DDX_Control(pDX, IDC_FIRST, m_first);
	DDX_Control(pDX, IDC_EDIT, m_edit);
	DDX_Control(pDX, IDC_DEL, m_del);
	DDX_Control(pDX, IDC_ADD, m_add);
	DDX_Text(pDX, IDC_ADDRESS, m_address);
	DDX_Text(pDX, IDC_RESNAME, m_resname);
	DDX_Text(pDX, IDC_TRAC, m_trac);
	DDX_Text(pDX, IDC_ID, m_id);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(TRACFFICDLG, CDialog)
	//{{AFX_MSG_MAP(TRACFFICDLG)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_PRE, OnPre)
	ON_BN_CLICKED(IDC_NEXT, OnNext)
	ON_BN_CLICKED(IDC_GONGJIAO, OnGongjiao)
	ON_BN_CLICKED(IDC_LAST, OnLast)
	ON_BN_CLICKED(IDC_FIRST, OnFirst)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	ON_BN_CLICKED(IDC_EDIT, OnEdit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// TRACFFICDLG message handlers

HBRUSH TRACFFICDLG::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
		pDC->SetTextColor(RGB(0,0,225));
    if (nCtlColor != CTLCOLOR_EDIT && nCtlColor != CTLCOLOR_LISTBOX) {
   		pDC->SetBkMode(TRANSPARENT);
     	HBRUSH B = CreateSolidBrush(RGB(128, 184, 223)); 
      //  HBRUSH B = CreateSolidBrush(RGB(0,170,170)); 
		return (HBRUSH) B;}
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
    // TODO: Return a different brush if the default is not desired
	return hbr;
}

BOOL TRACFFICDLG::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
    m_database=new CDatabase;
    CString strSQL="select * from 交通信息";
    m_database->Open("景点管理",FALSE,FALSE,"ODBC;UID=sa;PWD=",TRUE);
    m_pSet=new TracfficDlgSet(m_database);
    m_pSet->Open(CRecordset::snapshot,strSQL);
    
    
    
    getdata(); 
    m_pSet->MoveFirst();//第一条记录开始

  ////////////////////////////////////////
  CRect rectsize;
  //GetClientRect(rectsize);
  CMyApp *pcpp=(CMyApp*)AfxGetApp();
  CMainFrame *pfrm=(CMainFrame*)(pcpp->m_pMainWnd);
  CMyView* pview=(CMyView*)pfrm->m_splitter.GetPane(0,1);
  rectsize=pview->viewrect;	 
  SetWindowPos(NULL,rectsize.Width()/3+46,63,rectsize.Width(),rectsize.Height(),TRUE);
////////////////////////////////////////

///////////////////////////////////////////////////   
    bool flag;	
	flag=pcpp->flagapp;

  	if(!flag)
	{
		GetDlgItem(IDC_ADD)->ShowWindow(SW_HIDE);
	    GetDlgItem(IDC_DEL)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_EDIT)->ShowWindow(SW_HIDE); 
	}
	     
	else
	{
		GetDlgItem(IDC_ADD)->ShowWindow(SW_SHOW);
        GetDlgItem(IDC_DEL)->ShowWindow(SW_SHOW);
		GetDlgItem(IDC_EDIT)->ShowWindow(SW_SHOW);
	}
///////////////////////////////////////////////////  
   //将交通记录设置为不能更改
	SetEdit(TRUE);



	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void TRACFFICDLG::OnPre() 
{
	m_pSet->MovePrev();
	getdata();
	SetButtonState();	

}

void TRACFFICDLG::OnNext() 
{
    m_pSet->MoveNext();
	getdata();
	SetButtonState();
	
}

void TRACFFICDLG::OnGongjiao() 
{
   GongJiaoDlg dlg;
   dlg.DoModal();
}

void TRACFFICDLG::OnLast() 
{
    m_pSet->MoveLast();
	OnNext();

	
}

void TRACFFICDLG::OnFirst() 
{
     m_pSet->MoveFirst();
	 OnPre();
	

}
void TRACFFICDLG::SetButtonState()
{
    if(IsFirstRecord())
	{
		GetDlgItem(IDC_FIRST)->EnableWindow(FALSE);
	    GetDlgItem(IDC_PRE)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_FIRST)->EnableWindow(TRUE);
	    GetDlgItem(IDC_PRE)->EnableWindow(TRUE);

	}

	if(IsLastRecord())
	{	
		GetDlgItem(IDC_NEXT)->EnableWindow(FALSE);
	    GetDlgItem(IDC_LAST)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_NEXT)->EnableWindow(TRUE);
		GetDlgItem(IDC_LAST)->EnableWindow(TRUE);
	}
}
 
BOOL TRACFFICDLG::IsFirstRecord()
{
	if(m_pSet->IsBOF()&&m_pSet->IsEOF())
	{
		return TRUE;
	}
	else if(m_pSet->IsBOF())
	{
		m_pSet->MoveFirst();
		return TRUE;
	}
	else
		return FALSE;
}

BOOL TRACFFICDLG::IsLastRecord()
{
	if(m_pSet->IsBOF()&&m_pSet->IsEOF())
	{
		return TRUE;
	}
	else if(m_pSet->IsEOF())
	{
		m_pSet->MoveLast();
		return TRUE;
	}
	else
		return FALSE;
}
void TRACFFICDLG::SetEdit(bool bFlag)
{
    CEdit *pedit1=(CEdit*)GetDlgItem(IDC_ID);
	pedit1->SetReadOnly(bFlag);
	CEdit *pedit2=(CEdit*)GetDlgItem(IDC_RESNAME);
	pedit2->SetReadOnly(bFlag);
	CEdit *pedit3=(CEdit*)GetDlgItem(IDC_TRAC);
	pedit3->SetReadOnly(bFlag);
	CEdit *pedit4=(CEdit*)GetDlgItem(IDC_ADDRESS);
	pedit4->SetReadOnly(bFlag);
	
}

void TRACFFICDLG::getdata()
{
   
   m_id=m_pSet->m_column1;
   m_resname=m_pSet->m_column2;
   m_trac=m_pSet->m_column3;
   m_address=m_pSet->m_column4;
   UpdateData(FALSE);

}
void TRACFFICDLG::SetValue()
{
	UpdateData(TRUE);
	m_pSet->m_column1=m_id;
	m_pSet->m_column2=m_resname;
    m_pSet->m_column3=m_trac;
    m_pSet->m_column4= m_address;
    
}
void TRACFFICDLG::Clear()
{
	m_id=0;
	m_resname=_T("");
	m_trac=_T("");
    m_address=_T("");
	UpdateData(FALSE);

}


void TRACFFICDLG::SetNavButtonVisible(int isVisible)
{ 
	
		GetDlgItem(IDC_FIRST)->ShowWindow(isVisible);
	    GetDlgItem(IDC_PRE)->ShowWindow(isVisible);
		GetDlgItem(IDC_NEXT)->ShowWindow(isVisible);
		GetDlgItem(IDC_LAST)->ShowWindow(isVisible);
		GetDlgItem(IDOK)->ShowWindow(isVisible);
}
void TRACFFICDLG::SetButtonText(BOOL blSet)
{
	if(blSet)
	{
		GetDlgItem(IDC_EDIT)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_ADD)->SetWindowText(_T("确  定"));
		GetDlgItem(IDC_DEL)->SetWindowText(_T("取  消"));
	}
	else
	{
		GetDlgItem(IDC_EDIT)->ShowWindow(SW_SHOW);
		GetDlgItem(IDC_ADD)->SetWindowText(_T("添加"));
		GetDlgItem(IDC_DEL)->SetWindowText(_T("删除"));
	}

}

void TRACFFICDLG::SetNoRecordBtnState()
{	
	GetDlgItem(IDC_FIRST)->EnableWindow(FALSE);
	GetDlgItem(IDC_PRE)->EnableWindow(FALSE);
	GetDlgItem(IDC_NEXT)->EnableWindow(FALSE);
	GetDlgItem(IDC_LAST)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT)->EnableWindow(FALSE);
	GetDlgItem(IDC_DEL)->EnableWindow(FALSE);
	Clear();
}



void TRACFFICDLG::OnAdd() 
{   
  	if(isAdd||isEdit)
	{
		try
		{   if(!UpdateData(TRUE)) return;
		    if(m_id==0)
			{ 
				MessageBox("[景点编号] 字段不能为零!","注意",MB_ICONINFORMATION|MB_OK);
			    return;
			}
            
			SetValue();
			m_pSet->Update();

			if(isAdd) 
			{
				m_pSet->Requery();
				m_pSet->MoveLast();
			}
			SetNavButtonVisible(SW_SHOW);  
			SetButtonText(FALSE);
			SetEdit(TRUE);
			isAdd=FALSE;
			isEdit=FALSE;

			getdata();
			SetButtonState();

		}
		catch(CDBException* pEx)
		{
			pEx->ReportError();
		}
	}
	else
	{
		if(m_pSet->CanAppend())
		{
			SetNavButtonVisible(SW_HIDE);  
			SetButtonText(TRUE);
			m_pSet->AddNew();
			if(isEmpty())
			{
				GetDlgItem(IDC_EDIT)->EnableWindow(TRUE);
				GetDlgItem(IDC_DEL)->EnableWindow(TRUE);
			}
			SetEdit(FALSE);
			Clear();
			isAdd=TRUE;
        	
		}
		else
		{
			AfxMessageBox("Can't Append New Record");
		}

	}
	
}

void TRACFFICDLG::OnDel() 
{
	if(isAdd||isEdit)
	{
		m_pSet->CancelUpdate();
	    SetNavButtonVisible(SW_SHOW);  
		SetButtonText(FALSE);
		SetEdit(TRUE);

		if(isEmpty()) 
		   SetNoRecordBtnState();
		else
			getdata();

		isEdit=FALSE;
		isAdd=FALSE;
	}
	else
	    
	    if(MessageBox("确定要删除这条记录吗?","删除记录",MB_YESNO|MB_ICONINFORMATION) == IDYES)
		{
			m_pSet->Delete();
			try
			{
				OnNext();
				if(isEmpty())
				{
				SetNoRecordBtnState();
					return;
				}
				
				SetButtonState();
				getdata();
				
			}
			catch(CDBException* pEx)
			{
				pEx->ReportError();
			}

		}
	
}


BOOL TRACFFICDLG::isEmpty()
{
	if(m_pSet->IsBOF() && m_pSet->IsEOF())
	{
		
		return TRUE;
	}
	else
		return FALSE;

}

void TRACFFICDLG::OnEdit() 
{
	 if(m_pSet->CanAppend())
	{
        SetNavButtonVisible(SW_HIDE);  
		SetButtonText(TRUE);
		SetEdit(FALSE);
      	m_pSet->Edit();
		isEdit=TRUE;
	
	}
	else
	{
		AfxMessageBox("Can't Modify the Record");
	}
}

void TRACFFICDLG::OnOK() 
{
	new	CFaderWnd(this,600);//实现渐隐效果
	EndDialog(IDOK);//关闭对话框	
}

⌨️ 快捷键说明

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