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

📄 booktoresidedlg.cpp

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

#include "stdafx.h"
#include "HotelManageSys.h"
#include "BookToResideDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// BookToResideDlg dialog


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


void BookToResideDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(BookToResideDlg)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_SERIALID, m_serialId);
	DDX_Control(pDX, IDC_roomID, m_roomId);
	DDX_Control(pDX, IDC_clientName, m_clientname);
	//}}AFX_DATA_MAP
    (CWnd *)GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);      //灰化"入住房间按钮"	
}


BEGIN_MESSAGE_MAP(BookToResideDlg, CDialog)
	//{{AFX_MSG_MAP(BookToResideDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnResideByRoomID)
	ON_BN_CLICKED(IDC_BUTTON3, OnResideBySerialId)
	ON_BN_CLICKED(IDC_ViewAllRoom, OnViewAllRoom)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// BookToResideDlg message handlers

void BookToResideDlg::OnResideByRoomID() 
{
	// TODO: Add your control notification handler code here
	CString roomId;
	m_roomId.GetWindowText(roomId);
	CString sql;
	
	if(roomId == "")
	{
		AfxMessageBox("请输入房间号!!!");
		return ;
	}
	C_Connection m_connection;
	m_connection.open("Hotel");              //数据库建立连接

	//获取book表相关信息
	sql.Format("SELECT * FROM book WHERE 房间号 = '%s' ;",roomId);
    m_connection.ExcuteSql(sql);
	if(m_connection.rs->IsEOF())
	{
		AfxMessageBox("房间号有误!!!");
		return  ;
	}

	CString serialID,resideDays,cash;
	int s1,s2;
    //更新 room 表
	sql.Format("UPDATE room SET 房间状态='已住' where  房间号 = '%s' ;",roomId);
	m_connection.WriteSql(sql);
	
	//获取book表中的信息
	sql.Format("SELECT * FROM book WHERE 房间号 = '%s';",roomId);
    m_connection.ExcuteSql(sql);
    m_connection.rs->GetFieldValue("客户流水号",serialID);
	m_connection.rs->GetFieldValue("定金支付",cash);
	m_connection.rs->GetFieldValue("订房天数",resideDays);

    //算出应付金额
	s2 = atoi(cash)*9;
	CString str ;
	str.Format("%d",s2);
	//弹出缴费对话框
	AfxMessageBox("缴纳金额:"+str);
	s1 = atoi(resideDays);

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

    COleDateTime date1,date2;
	CString str1,str2;
	CTime time ;
	//获取当前日期
	time = CTime::GetCurrentTime();
	str1.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());
	//记录当前日期
    date1.ParseDateTime(str1); 
	date2 = date1;
	//记录截止日期
	date2 += s1;
	str2.Format("%d/%d/%d",date2.GetMonth(),date2.GetDay(),date2.GetYear());
	//更新register表
	sql.Format("INSERT INTO register \
			(房间号,客户流水号,住房日期,截止日期,支付金额) \
			VALUES ('%s','%s','%s','%s',%d) ",roomId,serialID,str1,str2,s2/9*10);
    m_connection.WriteSql(sql);

	CString ID,ss;
	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_connection.close();
}

void BookToResideDlg::OnResideBySerialId() 
{
	// TODO: Add your control notification handler code here
	CString serialID,resideDays,cash,sql;
	int s1,s2;
	int i = -1 ;
    if(roomNumber == 0)
	{
		AfxMessageBox("没有此用户的预约房间!!!");
		return ;
	}
	C_Connection m_connection;
	m_connection.open("Hotel");              //数据库建立连接
	while(++i<roomNumber)
	{
		//更新 room 表
		sql.Format("UPDATE room SET 房间状态='已住' where  房间号 = '%s' ;",roomID[i]);
		m_connection.WriteSql(sql);
		
		//获取book表中的信息
		sql.Format("SELECT * FROM book WHERE 房间号 = '%s';",roomID[i]);
		m_connection.ExcuteSql(sql);
		m_connection.rs->GetFieldValue("客户流水号",serialID);
		m_connection.rs->GetFieldValue("定金支付",cash);
		m_connection.rs->GetFieldValue("订房天数",resideDays);
		
		//算出应付金额
		s2 = atoi(cash)*9;
		//得到要订房天数
		s1 = atoi(resideDays);
		
		//更新book表
		sql.Format("DELETE FROM BOOK WHERE 房间号 = '%s'", roomID[i]);
		m_connection.WriteSql(sql);
		
		COleDateTime date1,date2;
		CString str1,str2;
		CTime time ;
		//获取当前日期
		time = CTime::GetCurrentTime();
		str1.Format("%d/%d/%d",time.GetMonth(),time.GetDay(),time.GetYear());
		//记录当前日期
		date1.ParseDateTime(str1); 
		date2 = date1;
		//记录截止日期
		date2 += s1;
		str2.Format("%d/%d/%d",date2.GetMonth(),date2.GetDay(),date2.GetYear());
		//更新register表
		sql.Format("INSERT INTO register \
				(房间号,客户流水号,住房日期,截止日期,支付金额) \
				VALUES ('%s','%s','%s','%s',%d) ",roomID[i],serialID,str1,str2,s2/9*10);
		m_connection.WriteSql(sql);
		
		CString ID,ss;
		CHotelManageSysDlg  *dlg;     
		dlg   =   (CHotelManageSysDlg*)(AfxGetApp()->m_pMainWnd);     //获取主对话框句柄
		dlg->m_ID.GetWindowText(ID);                                  //获取主对话框的“用户名”
		//更新log表
		sql.Format("INSERT INTO log \
				(房间号,用户名,操作类型,操作日期) \
				VALUES ('%s','%s','预约用户住房','%s') ",roomID[i],ID,str1);
		m_connection.WriteSql(sql);
	}
	m_connection.close() ;
    (CWnd *)GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);      //灰化"入住房间按钮"	
	(CWnd *)GetDlgItem(IDC_ViewAllRoom)->EnableWindow(TRUE);   //亮化"查看预约的房间"
} 

void BookToResideDlg::clear()
{
	m_clientname.SetWindowText("");
	m_serialId.SetWindowText("");
	m_roomId.SetWindowText("");
	m_list.ResetContent();
}

void BookToResideDlg::OnViewAllRoom() 
{
	// TODO: Add your control notification handler code here
	CString clientname,serialID;
	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();

    sql.Format("SELECT * FROM book WHERE 客户流水号 = '%s' ",serialID);
    m_connection.ExcuteSql(sql);               //获取book表的相关信息

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

	m_connection.close();
    (CWnd *)GetDlgItem(IDC_ViewAllRoom)->EnableWindow(FALSE);  // 灰化"查看预约的房间"
    (CWnd *)GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);       // 亮化"入住房间按钮"	
}

⌨️ 快捷键说明

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