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

📄 shujukudlg.cpp

📁 这是一个简单的酒店管理系统
💻 CPP
字号:
// ShuJuKuDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ShuJuKu.h"
#include "ShuJuKuDlg.h"
#include "YuDing.h"
#include "INSERTCUSTOMER.h"
#include "IisertHotel.h"
#include "YuDing.h"

#include <time.h> 

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShuJuKuDlg dialog

CShuJuKuDlg::CShuJuKuDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShuJuKuDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShuJuKuDlg)
	m_CustomerID = _T("");
	m_CustomerName = _T("");
	m_HotelName = _T("");
	m_PriceFrom = _T("");
	m_PriceTo = _T("");
	m_ShowHouse = _T("");
	m_ShowHouse2 = _T("");
	m_STime = COleDateTime::GetCurrentTime();
	m_ETime = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
		


	//return TRUE;
}

CShuJuKuDlg::~CShuJuKuDlg()
{
	dbAgent.Close();
}

void CShuJuKuDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShuJuKuDlg)
	DDX_Control(pDX, IDC_RoomPrice, m_RoomPrice);
	DDX_Control(pDX, IDC_Result, m_Result);
	DDX_Control(pDX, IDC_HotelCity, m_HotelCity);
	DDX_Text(pDX, IDC_CustomerID, m_CustomerID);
	DDX_Text(pDX, IDC_CustomerName, m_CustomerName);
	DDX_Text(pDX, IDC_HotelName, m_HotelName);
	DDX_Text(pDX, IDC_PriceFrom, m_PriceFrom);
	DDX_Text(pDX, IDC_PriceTo, m_PriceTo);
	DDX_Text(pDX, IDC_ShowHouse, m_ShowHouse);
	DDX_Text(pDX, IDC_ShowHouse2, m_ShowHouse2);
//	DDX_DateTimeCtrl(pDX, IDC_StartDATETIME, m_STime);
//	DDX_DateTimeCtrl(pDX, IDC_EndDATETIME, m_ETime);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CShuJuKuDlg, CDialog)
	//{{AFX_MSG_MAP(CShuJuKuDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_CustomerID, OnChangeCustomerID)
	ON_BN_CLICKED(IDC_ChaXun, OnChaXun)
	ON_NOTIFY(NM_DBLCLK, IDC_Result, OnDblclkResult)
	ON_BN_CLICKED(IDC_quedingfangxing, Onquedingfangxing)
	ON_CBN_SELCHANGE(IDC_RoomPrice, OnSelchangeRoomPrice)
	ON_BN_CLICKED(IDC_BUTTON3, OnYuDing)
	ON_BN_CLICKED(IDC_InsertCustomer, OnInsertCustomer)
	ON_BN_CLICKED(IDC_InsertCustomer2, OnInsertHotel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShuJuKuDlg message handlers

BOOL CShuJuKuDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_Result.SetExtendedStyle(LVS_EX_FULLROWSELECT);//选整行

//	this->m_STime= CTime::GetCurrentTime();
//	this->m_ETime= CTime::GetCurrentTime();

	m_Result.InsertColumn(0,_TEXT("序号"),LVCFMT_LEFT,50);
	m_Result.InsertColumn(1,_TEXT("名称"),LVCFMT_LEFT,100);
	m_Result.InsertColumn(2,_TEXT("地址"),LVCFMT_LEFT,100);
	m_Result.InsertColumn(3,_TEXT("距车站距离"),LVCFMT_LEFT,80);
	m_Result.InsertColumn(4,_TEXT("星级"),LVCFMT_LEFT,50);

	try
	{
		dbAgent.Open("HotelDB");
	}
	catch(CException e)
	{
		e.ReportError();
	}

	CString city;
	CRecordset reAgent(&dbAgent);

	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT Name FROM TCity",CRecordset::readOnly);	
	}
	catch(CException e)
	{
		e.ReportError();
	}

	while(!reAgent.IsEOF())
	{
		reAgent.GetFieldValue("Name",city);
		m_HotelCity.AddString(city);
		reAgent.MoveNext();
	}
	reAgent.Close();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CShuJuKuDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CShuJuKuDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CShuJuKuDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CShuJuKuDlg::OnChangeCustomerID() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here

	this->UpdateData(true);
	if(m_CustomerID.GetLength() < 11)
	{
		m_CustomerName="";
		UpdateData(false);
		return;
	}
	if(m_CustomerID.GetLength() > 11)
	{
		m_CustomerID=temp;
		UpdateData(false);
		return;
	}

	temp=m_CustomerID;
	CRecordset reAgent(&dbAgent);

	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT Name FROM TCustomer WHERE ID ='"  + m_CustomerID + "'  ",CRecordset::readOnly);
	}
	catch(CException e)
	{
		e.ReportError();
	}


/*	while(!reAgent.IsEOF())
	{
		reAgent.GetFieldValue("Name",m_CustomerName);
		reAgent.MoveNext();
	}*/

	if(reAgent.IsEOF())
	{
		reAgent.Close();
		return;
	}
	reAgent.GetFieldValue("Name",m_CustomerName);


	CusName=m_CustomerName;	//传递人名

	reAgent.Close();
	this->UpdateData(false);
//	MessageBox(CusName);
	
}

void CShuJuKuDlg::OnChaXun() 
{
	// TODO: Add your control notification handler code here


	this->m_Result.DeleteAllItems();

	CRecordset reAgent(&dbAgent);

	CString sqlStmt;
	CString conditionName;
	CString conditionCity;
	CString conditionFrom;
	CString conditionTo;
	this->UpdateData(true);

	CString city;
	m_HotelCity.GetWindowText(city);


	conditionName = "Name = (SELECT Name FROM THotel WHERE Name ='" + m_HotelName + "')";
	conditionCity = "CityID = (SELECT ID FROM TCity WHERE name ='" + city + "')";
	conditionFrom=" ID in (select HotelID from TRoomType where price > " + m_PriceFrom + ")";
	conditionTo=" ID in (select HotelID from TRoomType where price < " + m_PriceTo + ")";
	sqlStmt="select * from THotel";

	m_HotelName.TrimLeft();//找酒店名字
	m_HotelName.TrimRight();
	if(m_HotelName!="")
	{
		if(sqlStmt.Find("where")>=0)
		{
			sqlStmt=sqlStmt+" and "+conditionName;
		}
		else
		{
			sqlStmt=sqlStmt+" where "+conditionName;
		}
		
	}

	city.TrimLeft();
	city.TrimRight();
	if(city!="")
	{
		if(sqlStmt.Find("where")>=0)
		{
			sqlStmt=sqlStmt+" and "+conditionCity;
		}
		else
		{
			sqlStmt=sqlStmt+" where "+conditionCity;
		}
	}

	m_PriceFrom.TrimLeft();
	m_PriceFrom.TrimRight();
	if(m_PriceFrom!="")
	{
		if(sqlStmt.Find("where")>=0)
		{
			sqlStmt=sqlStmt+" and "+conditionFrom;
		}
		else
		{
			sqlStmt=sqlStmt+" where "+conditionFrom;
		}
	}

	m_PriceTo.TrimLeft();
	m_PriceTo.TrimRight();
	if(m_PriceTo!="")
	{
		if(sqlStmt.Find("where")>=0)
		{
			sqlStmt=sqlStmt+" and "+conditionTo;
		}
		else
		{
			sqlStmt=sqlStmt+" where "+conditionTo;
		}
	}

	CRecordset rsAgent(&dbAgent);


//	MessageBox(sqlStmt);

	try
	{
		rsAgent.Open(CRecordset::forwardOnly,sqlStmt);
	}
	catch(CException e)
	{
		e.ReportError();
	}


//	MessageBox(Address);

	int i=0;//显示到第几个
	
	CString tmphotel;
	CString tmphotelid;
	CString tmpadd;
	CString tmptostat;
	CString tmpstar;

	while(!rsAgent.IsEOF())
	{
		rsAgent.GetFieldValue("ID",tmphotelid);
		rsAgent.GetFieldValue("Name",tmphotel);
		rsAgent.GetFieldValue("Address",tmpadd);
		rsAgent.GetFieldValue("toStation",tmptostat);
		rsAgent.GetFieldValue("star",tmpstar);

		tmphotel.TrimRight();
		m_Result.InsertItem(i,tmphotelid);

/*		m_Result.InsertItem(i,tmphotel);
		m_Result.InsertItem(i,tmpadd);
		m_Result.InsertItem(i,tmptostat);
		m_Result.InsertItem(i,tmpstar);*/
		
		tmpadd.TrimRight();
		tmpstar.TrimRight();

		m_Result.SetItemText(i,1,TEXT(tmphotel));
		m_Result.SetItemText(i,2,TEXT(tmpadd));
		m_Result.SetItemText(i,3,TEXT(tmptostat));
		m_Result.SetItemText(i,4,TEXT(tmpstar));

//		MessageBox(sqlStmt);
		rsAgent.MoveNext();
		i++;
	}
	

/*	while(!reAgent.IsEOF())
	{
		
		reAgent.GetFieldValue("Name",conditionName);
		conditionName.TrimLeft();
		conditionName.TrimRight();

		m_Result.InsertItem(i,conditionName);

		reAgent.MoveNext();
		UpdateData(false);
		i++;
	}*/
	reAgent.Close();


}


void CShuJuKuDlg::OnDblclkResult(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int i = m_Result.GetSelectionMark();

	CString room;
	CString r;
	CRecordset reAgent(&dbAgent);

	r=m_Result.GetItemText(i,0);

	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT Name FROM TRoomType WHERE HotelID =" + r,CRecordset::readOnly);	
	}
	catch(CException e)
	{
		e.ReportError();
	}

	while(!reAgent.IsEOF())
	{
		reAgent.GetFieldValue("Name",room);
		room.TrimRight();
		m_RoomPrice.AddString(room);
		reAgent.MoveNext();
	}


	RoomName=room;//传递房间名

	reAgent.Close();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	CString HotelN;
	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT Name FROM THotel WHERE ID =" + r,CRecordset::readOnly);	
	}
	catch(CException e)
	{
		e.ReportError();
	}

	while(!reAgent.IsEOF())
	{
		reAgent.GetFieldValue("Name",HotelN);
		room.TrimRight();
//		m_RoomPrice.AddString(HotelN);
		reAgent.MoveNext();
	}
	HolName=HotelN;//找酒店名
	reAgent.Close();
//	MessageBox("SELECT Name FROM Name WHERE ID =" + r);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	*pResult = 0;
}

/*void CShuJuKuDlg::OnClickResult(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}*/

/*void CShuJuKuDlg::OnEditchangeRoomPrice() 
{
	// TODO: Add your control notification handler code here
		CRecordset reAgent(&dbAgent);

	m_RoomPrice.GetWindowText(temp1);
	MessageBox(temp1);

	CString p="SELECT leave FROM TRoomType WHERE Name ='" + temp1 +"' ";
	MessageBox(p);
		
	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT price FROM TRoomType WHERE Name ='" + temp1 +"' " ,CRecordset::readOnly);
	}
	catch(CException e)
	{
		e.ReportError();
	}

	reAgent.GetFieldValue("price",m_ShowHouse);
	m_ShowHouse=m_ShowHouse + " RMB/天";
	reAgent.Close();
	this->UpdateData(false);

	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT leave FROM TRoomType WHERE Name ='" + temp1 +"' " ,CRecordset::readOnly);
	}
	catch(CException e)
	{
		e.ReportError();
	}

	reAgent.GetFieldValue("leave",m_ShowHouse2);
	m_ShowHouse2="目前剩余"+m_ShowHouse2 + "间房";
	reAgent.Close();
	this->UpdateData(false);
}*/

void CShuJuKuDlg::Onquedingfangxing() 
{
	// TODO: Add your control notification handler code here
	CString roomnull;
	m_RoomPrice.GetWindowText(roomnull);

	if(!roomnull.IsEmpty())
	{
		CYuDing a;
		a.DoModal();
	}
	else
		MessageBox("请选择房型!");
}

void CShuJuKuDlg::OnSelchangeRoomPrice() 
{
	// TODO: Add your control notification handler code here

	CRecordset reAgent(&dbAgent);

//	this->UpdateData(true);
	m_RoomPrice.GetWindowText(temp1);
//	MessageBox(temp1);

	CString p="SELECT leave FROM TRoomType WHERE Name ='" + temp1 +"' ";
//	MessageBox(p);
		
	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT price FROM TRoomType WHERE Name ='" + temp1 +"' " ,CRecordset::readOnly);
	}
	catch(CException e)
	{
		e.ReportError();
	}

	reAgent.GetFieldValue("price",m_ShowHouse);
	m_ShowHouse=m_ShowHouse + " RMB/天";

	Price = atoi(m_ShowHouse);//字符型转换为整型  为了算总价钱

	reAgent.Close();
	this->UpdateData(false);

	try
	{
		reAgent.Open(CRecordset::forwardOnly,"SELECT leave FROM TRoomType WHERE Name ='" + temp1 +"' " ,CRecordset::readOnly);
	}
	catch(CException e)
	{
		e.ReportError();
	}

	reAgent.GetFieldValue("leave",m_ShowHouse2);
	m_ShowHouse2="目前剩余"+m_ShowHouse2 + "间房";
	reAgent.Close();
	this->UpdateData(false);
}



void CShuJuKuDlg::OnYuDing() 
{
	// TODO: Add your control notification handler code here
	this->m_STime;
	this->m_ETime;



//	CTime NowTime = CTime::GetCurrentTime();

//	if(m_STime.operator <(NowTime))
		MessageBox("ERROR!");
}

void CShuJuKuDlg::OnInsertCustomer() 
{
	// TODO: Add your control notification handler code here
	CINSERTCUSTOMER a;
	a.DoModal();
}

void CShuJuKuDlg::OnInsertHotel() 
{
	// TODO: Add your control notification handler code here
	CIisertHotel a;
	a.DoModal();
}

⌨️ 快捷键说明

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