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

📄 booktoabandlg.cpp

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

#include "stdafx.h"

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

/////////////////////////////////////////////////////////////////////////////
// BookToAbanDlg dialog


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


void BookToAbanDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(BookToAbanDlg)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_clientName, m_clientName);
	DDX_Control(pDX, IDC_roomID, m_roomID);
	DDX_Control(pDX, IDC_SERIALID, m_serialId);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(BookToAbanDlg, CDialog)
	//{{AFX_MSG_MAP(BookToAbanDlg)
	ON_BN_CLICKED(IDC_abandonBook, OnabandonBook)
	ON_BN_CLICKED(IDC_View, OnView)
	ON_BN_CLICKED(IDC_AbanBook, OnAbanBook)
	ON_BN_CLICKED(IDC_cancel, Oncancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// BookToAbanDlg message handlers

void BookToAbanDlg::clear()
{
	m_list.ResetContent();
	m_clientName.SetWindowText("");
	m_serialId.SetWindowText("");
	(CWnd *)GetDlgItem(IDC_View)->EnableWindow(TRUE);            // 亮化"查看"
    (CWnd *)GetDlgItem(IDC_cancel)->EnableWindow(FALSE);         // 灰化"取消"
	(CWnd *)GetDlgItem(IDC_AbanBook)->EnableWindow(FALSE);       // 灰化"退订"
}

void BookToAbanDlg::OnabandonBook() 
{
	// TODO: Add your control notification handler code here
	//获取房间号
	CString roomID;
	m_roomID.GetWindowText(roomID);
	//建立数据库连接
	C_Connection m_connection;
	m_connection.open("Hotel");        
	//获取book表中信息
	CString sql;
	sql.Format("SELECT * FROM book WHERE 房间号 = '%s';",roomID);
	m_connection.ExcuteSql(sql);
	//检查有没该房间的记录
	if(m_connection.rs->IsEOF())
	{
		AfxMessageBox("无此记录,房间号输入有误!!!");
        return ;
	}
    m_connection.rs->GetFieldValue("客户流水号",serialID);
	//关闭记录集
	m_connection.rs->Close();
	//获取client 中房间数信息
	int cc;
	CString num ;
	sql.Format("SELECT 房间数 FROM client WHERE 客户流水号 = '%s';",serialID);    
	m_connection.ExcuteSql(sql);
	m_connection.rs->GetFieldValue("房间数",num);
	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);         
	}
	//获取room表中信息
	sql.Format("SELECT 定金支付 FROM book  WHERE 房间号 = '%s';",roomID);
    m_connection.ExcuteSql(sql);
	CString cash;
	m_connection.rs->GetFieldValue("定金支付",cash);
	m_connection.rs->Close();
    AfxMessageBox("退钱:"+cash);
	//更新room表
    sql.Format("UPDATE room  SET 房间状态 = '空' WHERE 房间号 = '%s';",roomID);
	m_connection.WriteSql(sql);
	//更新book表
	sql.Format("DELETE FROM BOOK WHERE 房间号 = '%s';",roomID);
	m_connection.WriteSql(sql);

    //获取当前日期
	CTime time;
	time = CTime::GetCurrentTime();                
	CString ID,ss,str1;
	str1.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());
	CHotelManageSysDlg  *dlg;   
	//获取主对话框句柄  
	dlg   =   (CHotelManageSysDlg*)(AfxGetApp()->m_pMainWnd);  
	//获取主对话框的“用户名”  
	dlg->m_ID.GetWindowText(ID);                                 
    //登记log表(用户名,操作类型,房间号,操作日期)
	sql.Format("INSERT INTO log \
		(房间号,用户名,操作类型,操作日期) \
		VALUES ('%s','%s','预约用户退房','%s') ;",roomID,ID,str1);
	m_connection.WriteSql(sql);
	m_roomID.SetWindowText("");
    //关闭数据库连接
    m_connection.close();               
}
void BookToAbanDlg::OnView() 
{
	// TODO: Add your control notification handler code here
	CString clientname;
	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);
	if(m_connection.rs->IsEOF())
	{          
		AfxMessageBox("无此记录!!") ;
		return ;
	}
    m_connection.rs->GetFieldValue("客户名",clientname);
	//给客户文本框赋值
	m_clientName.SetWindowText(clientname);     
    m_connection.rs->Close();
    //获取book表的相关信息
    sql.Format("SELECT * FROM book WHERE 客户流水号 = '%s' ;",serialID);
    m_connection.ExcuteSql(sql);               

    int i = 0;
	CString cash;
	total = 0;
	while(!m_connection.rs->IsEOF())
	{
		m_connection.rs->GetFieldValue("房间号",roomID[i]);
		m_connection.rs->GetFieldValue("定金支付",cash);
		total += atoi(cash);                  //计算总金额
		m_list.AddString(roomID[i]);          //给列表框赋值	
		m_connection.rs->MoveNext();
		i++;
	}
	roomNumber = i;

	m_connection.close();
    (CWnd *)GetDlgItem(IDC_View)->EnableWindow(FALSE);          // 灰化"查看"
    (CWnd *)GetDlgItem(IDC_AbanBook)->EnableWindow(TRUE);       // 亮化"退订"	
    (CWnd *)GetDlgItem(IDC_cancel)->EnableWindow(TRUE);         // 亮化"取消"
}

void BookToAbanDlg::OnAbanBook() 
{
	// TODO: Add your control notification handler code here
	//显示退还余额
	CString str,sql;
    str.Format("%d",total);
	AfxMessageBox("退还余额:"+str);
	//建立数据库连接
	C_Connection m_connection;
	m_connection.open("Hotel");    

	//更新book表
	sql.Format("DELETE FROM book WHERE 客户流水号 = '%s';",serialID);
	m_connection.WriteSql(sql);
	
    int i = -1;
	CString ID;
	CHotelManageSysDlg  *dlg;     
	dlg   =   (CHotelManageSysDlg*)(AfxGetApp()->m_pMainWnd);     //获取主对话框句柄
	dlg->m_ID.GetWindowText(ID);                                  //获取主对话框的“用户名”
	CTime  time = CTime::GetCurrentTime();
	str.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());
	while(++i<roomNumber)
	{
		//更新room表
		sql.Format("UPDATE room SET 房间状态 = '空' WHERE 房间号 = '%s' ;",roomID[i]);
        m_connection.WriteSql(sql);
        //更新log表
		sql.Format("INSERT INTO log \
			(房间号,用户名,操作类型,操作日期) \
			 VALUES ('%s','%s','预约用户退房','%s') ",roomID[i],ID,str);
		m_connection.WriteSql(sql);
	}
	//获取client 中房间数信息
	int cc;
	CString num ;
	sql.Format("SELECT 房间数 FROM client WHERE 客户流水号 = '%s';",serialID);    
	m_connection.ExcuteSql(sql);
	m_connection.rs->GetFieldValue("房间数",num);
	if((atoi(num))==roomNumber)
	{
		//更新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);	
	}
   (CWnd *)GetDlgItem(IDC_AbanBook)->EnableWindow(FALSE);       // 灰化"退订"
	m_connection.close();
}

void BookToAbanDlg::Oncancel() 
{
	// TODO: Add your control notification handler code here
    clear()	;
}

⌨️ 快捷键说明

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