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

📄 abandonroom.cpp

📁 酒店管理系统的毕业设计,用VC编的,功能有限
💻 CPP
字号:
// AbandonRoom.cpp : implementation file
//

#include "stdafx.h"
#include "HotelManageSys.h"
#include "AbandonRoom.h"

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

/////////////////////////////////////////////////////////////////////////////
// AbandonRoom dialog


AbandonRoom::AbandonRoom(CWnd* pParent /*=NULL*/)
	: CDialog(AbandonRoom::IDD, pParent)
{
	//{{AFX_DATA_INIT(AbandonRoom)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void AbandonRoom::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(AbandonRoom)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_clientName, m_clientname);
	DDX_Control(pDX, IDC_SERIALID, m_serialID);
	DDX_Control(pDX, IDC_roomID, m_roomID);
	//}}AFX_DATA_MAP
	(CWnd *)GetDlgItem(IDC_QUITROOM)->EnableWindow(FALSE); 	//灰化查看订的房间按钮
}


BEGIN_MESSAGE_MAP(AbandonRoom, CDialog)
	//{{AFX_MSG_MAP(AbandonRoom)
	ON_BN_CLICKED(IDC_ABANDONROOM, OnAbandonroom)
	ON_BN_CLICKED(IDC_EXAMINEROOM, OnExamineroom)
	ON_BN_CLICKED(IDC_QUITROOM, OnQuitroom)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// AbandonRoom message handlers
void AbandonRoom::clear()
{
	m_clientname.SetWindowText("");
	m_serialID.SetWindowText("");
	m_roomID.SetWindowText("");
	m_list.ResetContent();
}

//按房间号退房
void AbandonRoom::OnAbandonroom() 
{
	// TODO: Add your control notification handler code here
    CString roomID;
	m_roomID.GetWindowText(roomID);
	if(roomID=="")
	{
		AfxMessageBox("请输入房间号");
        return ;
	}
	CString sql;
    sql.Format("SELECT *  FROM room WHERE 房间号 = '%s' AND 房间状态 = '已住'",roomID);
	C_Connection m_connection;
	m_connection.open("Hotel");              //数据库建立连接
    m_connection.ExcuteSql(sql);
	if(m_connection.rs->IsEOF())
	{
		AfxMessageBox("房间号有误!!!");
		return ;
	}
    sql.Format("UPDATE room SET 房间状态 = '空' WHERE 房间号 = '%s'",roomID);   //更新ROOM表
	m_connection.WriteSql(sql);
	
	CString serialID,cash,uptoDate,beginDate;
    COleDateTime date1,date2,date3;
	CTime   time;
	int payment ,unit_price,priceDifference;                       //获取相关信息以便判断缴费信息
	sql.Format("SELECT 客户流水号,住房日期,截止日期,支付金额 FROM register WHERE 房间号 = '%s'",roomID); 
    m_connection.ExcuteSql(sql);
    m_connection.rs->GetFieldValue("客户流水号",serialID);
    m_connection.rs->GetFieldValue("住房日期",beginDate);
	m_connection.rs->GetFieldValue("截止日期",uptoDate);
	m_connection.rs->GetFieldValue("支付金额",cash);
    m_connection.rs->Close();
    date1.ParseDateTime(beginDate);
	date2.ParseDateTime(uptoDate);
    payment = atoi(cash);
    unit_price = payment/(int)(date2-date1) ;                    //获取房间单价
    time = CTime::GetCurrentTime();
	CString str ;
	str.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());
	date3.ParseDateTime(str);
    priceDifference = payment-(int)(date3-date1)*unit_price ;          //获取房间差价
	BOOL SIGN = FALSE ;
	if(priceDifference<0)
	{
		//缴费对话框
		CString ss;
		ss.Format("%d",-priceDifference);
		AfxMessageBox("您须缴费:"+ss);
		SIGN = TRUE ;
	}
	else
	{
		//找零对话框
		CString ss;
		ss.Format("%d",priceDifference);
		AfxMessageBox("找零:"+ss);	
        SIGN = TRUE ;
	}
    
	if(SIGN) //缴费或找零成功               
	{
		CString  num;
		//更新register表
		sql.Format("DELETE FROM register WHERE 房间号 = '%s'",roomID);        
		m_connection.WriteSql(sql);
		//获取client 中房间数信息
		sql.Format("SELECT 房间数 FROM client WHERE 客户流水号 = '%s'",serialID);    
        m_connection.ExcuteSql(sql);
		m_connection.rs->GetFieldValue("房间数",num);
		int cc ;
		if((cc=atoi(num))<=1)
		{
			//更新client表
			sql.Format("DELETE FROM client WHERE 客户流水号 = '%s'",serialID);      
			m_connection.WriteSql(sql); 
			//更新serialID表
		    sql.Format("UPDATE serialID SET 状态 = '可用' WHERE 客户流水号 = '%s' ;" ,serialID);
			m_connection.WriteSql(sql); 
		}    
		else
		{
			//更新client 表
			cc -= 1;
			sql.Format("UPDATE client SET 房间数 = %d WHERE   客户流水号 = '%s'",cc,serialID);      
			m_connection.WriteSql(sql);         
		}
	    CString ID;
		CHotelManageSysDlg  *dlg;                                          
        dlg   =   (CHotelManageSysDlg*)(AfxGetApp()->m_pMainWnd);     //获取主对话框句柄
		dlg->m_ID.GetWindowText(ID);                                  //获取主对话框的“用户名”
        //更新log表   
        sql.Format("INSERT INTO log (房间号,用户名,操作类型,操作日期) \
			VALUES ('%s','%s','退房','%s') ",roomID,ID,str); 
		m_connection.WriteSql(sql);
	}
    m_connection.close();                        //数据库关闭
	m_roomID.SetWindowText("");
}


//按流水号退房
void AbandonRoom::OnExamineroom() 
{
	// TODO: Add your control notification handler code here
	CString clientname;
	int i = 0;
	m_serialID.GetWindowText(serialID); 
	if(serialID=="")
	{
		AfxMessageBox("请输入序列号!!!!");
		return ;
	}
	CString sql;
	C_Connection m_connection;
	m_connection.open("Hotel");              //数据库建立连接
	sql.Format("SELECT 客户名 FROM client WHERE 客户流水号 = '%s' ",serialID);
    m_connection.ExcuteSql(sql);
    m_connection.rs->GetFieldValue("客户名",clientname);
	m_clientname.SetWindowText(clientname);     //给客户文本框赋值
    m_connection.rs->Close();

    sql.Format("SELECT * FROM register WHERE 客户流水号 = '%s' ",serialID);
    m_connection.ExcuteSql(sql);             //获取register表的相关信息
	if(m_connection.rs->IsEOF())
	{
		AfxMessageBox("无此记录!!") ;
		return ;
	}
	while(!m_connection.rs->IsEOF())
	{
		m_connection.rs->GetFieldValue("房间号",roomNum[i]);
		m_list.AddString(roomNum[i]);          //给列表框赋值	
		m_connection.rs->MoveNext();
		i++;
	}
	m_connection.rs->Close();
	count = i ;
	i = 0;
	CString cash,uptoDate,beginDate;
	COleDateTime date1,date2,date3;
	CTime   time;
	int payment ,unit_price,priceDifference;  
	total = 0;
	//获取相关信息以便判断缴费信息
	while(i<count)
	{
		sql.Format("SELECT 客户流水号,住房日期,截止日期,支付金额 FROM register WHERE 房间号 = '%s'",roomNum[i++]); 
		m_connection.ExcuteSql(sql);
		m_connection.rs->GetFieldValue("客户流水号",serialID);
		m_connection.rs->GetFieldValue("住房日期",beginDate);
		m_connection.rs->GetFieldValue("截止日期",uptoDate);
		m_connection.rs->GetFieldValue("支付金额",cash);
		m_connection.rs->Close();
		date1.ParseDateTime(beginDate);
		date2.ParseDateTime(uptoDate);
		payment = atoi(cash);
		unit_price = payment/(int)(date2-date1) ;                    //获取房间单价
		time = CTime::GetCurrentTime();
		CString str ;
		str.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());
		date3.ParseDateTime(str);
		priceDifference = payment-(int)(date3-date1)*unit_price ;          //获取房间差价
		total += priceDifference;
	}
	m_connection.close();
    (CWnd *)GetDlgItem(IDC_EXAMINEROOM)->EnableWindow(FALSE); 	//灰化查看订的房间按钮
	(CWnd *)GetDlgItem(IDC_QUITROOM)->EnableWindow(TRUE); 	    //亮化查看订的房间按钮
}

void AbandonRoom::OnQuitroom() 
{
	// TODO: Add your control notification handler code here
	CString list,sql;
	CTime   time;
    time = CTime::GetCurrentTime();                       //获取当前日期
	CString str ;
	str.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());

	C_Connection m_connection;
	m_connection.open("Hotel");                    //数据库建立连接
     
	if(count == 0)
	{
		AfxMessageBox("无此记录!!") ;
		return ;
	}
	int i = 0;
	CString ID;
	CHotelManageSysDlg  *dlg;  
	//获取主对话框句柄
	dlg   =   (CHotelManageSysDlg*)(AfxGetApp()->m_pMainWnd);    
	//获取主对话框的“用户名”
	dlg->m_ID.GetWindowText(ID);                                
	while(i<count)
	{   
		list = roomNum[i++];
		//更新ROOM表
		sql.Format("UPDATE room SET 房间状态 = '空' WHERE 房间号 = '%s'",list);   
		m_connection.WriteSql(sql);

        //更新register表
		sql.Format("DELETE FROM register WHERE 房间号 = '%s'",list);           
		m_connection.WriteSql(sql);

	    //更新log表                                                                 
		sql.Format("INSERT INTO log (房间号,用户名,操作类型,操作日期) \
			VALUES ('%s','%s','退房','%s') ",list,ID,str); 
		m_connection.WriteSql(sql);		
	}
	//获取client 中房间数信息
	CString num ;
	sql.Format("SELECT 房间数 FROM client WHERE 客户流水号 = '%s';",serialID);    
	m_connection.ExcuteSql(sql);
	m_connection.rs->GetFieldValue("房间数",num);
	if((atoi(num))==count)
	{
		//更新client表
		sql.Format("DELETE FROM client WHERE 客户流水号 = '%s';",serialID);
		m_connection.WriteSql(sql);
		//更新serialID表
		sql.Format("UPDATE serialID SET 状态 = '可用' WHERE 客户流水号 = '%s';",serialID);
		m_connection.WriteSql(sql);	
	}
	if(total>=0)
	{
		str.Format("%d",total);
		AfxMessageBox("找零:"+str);
	}
	else 
	{
		str.Format("%d",total);
		AfxMessageBox("您须缴费:"+str);		
	}
    m_connection.close();
	(CWnd *)GetDlgItem(IDC_QUITROOM)->EnableWindow(FALSE); 	//灰化查看订的房间按钮
}

⌨️ 快捷键说明

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