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

📄 bookdlg.cpp

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

#include "stdafx.h"

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

/////////////////////////////////////////////////////////////////////////////
// BookDlg dialog


BookDlg::BookDlg(CWnd* pParent /*=NULL*/)
	: CDialog(BookDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(BookDlg)
	m_bookdays = 0;
	//}}AFX_DATA_INIT
}


void BookDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(BookDlg)
	DDX_Control(pDX, IDC_bookDate, m_bookdate);
	DDX_Control(pDX, IDC_clientName, m_clientname);
	DDX_Control(pDX, IDC_roomNumber, m_roomnumber);
	DDX_Control(pDX, IDC_Serial, m_serial);
	DDX_Control(pDX, IDC_COMBO1, m_combox);
	DDX_Control(pDX, IDC_LIST2, m_listOut);
	DDX_Control(pDX, IDC_LIST1, m_listIn);
	DDX_Control(pDX, IDC_roomType, m_roomtype);
	DDX_Control(pDX, IDC_BOOKID, m_bookid);
	DDX_Text(pDX, IDC_bookDays, m_bookdays);
	//}}AFX_DATA_MAP
	m_combox.AddString("单人间");
    m_combox.AddString("双人间");
	m_combox.AddString("普通套房");
	m_combox.AddString("高级套房");
	m_combox.SetCurSel(0);
	roomType = "单人间";
	(CWnd *)GetDlgItem(IDC_BOOKROOM)->EnableWindow(FALSE);     //灰化确定订房按钮
	(CWnd *)GetDlgItem(IDC_DEFRAYEARNEST)->EnableWindow(FALSE); //亮化支付定金按钮
	(CWnd *)GetDlgItem(IDC_CANCELBOOK)->EnableWindow(FALSE);    //亮化取消订房按钮
}


BEGIN_MESSAGE_MAP(BookDlg, CDialog)
	//{{AFX_MSG_MAP(BookDlg)
	ON_BN_CLICKED(IDC_BUTTONIN, OnButtonin)
	ON_BN_CLICKED(IDC_INQUIRE, OnInquire)
	ON_BN_CLICKED(IDC_BUTTONOUT, OnButtonout)
	ON_BN_CLICKED(IDC_BOOKROOM, OnBookroom)
	ON_BN_CLICKED(IDC_CANCELBOOK, OnCancelbook)
	ON_BN_CLICKED(IDC_DEFRAYEARNEST, OnDefrayearnest)
	ON_BN_CLICKED(IDC_newClient, OnnewClient)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// BookDlg message handlers

void BookDlg::OnButtonin() 
{
	// TODO: Add your control notification handler code here
	CString  str ;
	int cursel;
	if((cursel=m_listIn.GetCurSel())!=-1)
	{
		m_listIn.GetText(cursel,str);
		m_listIn.DeleteString(cursel);
		m_listOut.AddString(str);
	}	
}

void BookDlg::OnInquire() 
{
	// TODO: Add your control notification handler code here
	C_Connection m_connection;
	m_connection.open("Hotel");        //数据库建立连接
    CString str;
    m_listIn.ResetContent();
    m_listOut.ResetContent();
	m_combox.GetLBText(m_combox.GetCurSel(),roomType);
	m_roomtype.SetWindowText(roomType);
	str.Format("SELECT 房间号 FROM room WHERE 房间类型='%s' AND 房间状态 ='空';",roomType);
	m_connection.ExcuteSql(str);
	if(m_connection.rs->IsEOF())                         //判断记录是否为空
	{
		AfxMessageBox("没有此种类型的房间");
	}
    while(!m_connection.rs->IsEOF())
	{
    	m_connection.rs->GetFieldValue("房间号",str);
		m_listIn.AddString(str);
		m_connection.rs->MoveNext();
	}	
   m_connection.close();	
}

void BookDlg::OnButtonout() 
{
	// TODO: Add your control notification handler code here
	CString  str ;
	int cursel;
	if((cursel=m_listOut.GetCurSel())!=-1)
	{
		m_listOut.GetText(cursel,str);
		m_listOut.DeleteString(cursel);
		m_listIn.AddString(str);
	}	
}

void BookDlg::OnBookroom() 
{
	// TODO: Add your control notification handler code here
	CString t,str;                                  //暂存变量
	m_clientname.GetWindowText(str);                //获取用户名
	if(str == "")
	{
		AfxMessageBox("请输入用户名!!!!!");
		return ;
	}
    
	GetDlgItem(IDC_bookDays)->GetWindowText(t);     //获取入住天数
	if((bookDay=atoi(t))==0)                        //将所得字符串转化为整数
	{
		AfxMessageBox("请输入入住天数!!!!!");
		return ;
	}
    
	int  j;                //获取列表框字符串的数目
	roomtotal = m_listOut.GetCount();
    if(roomtotal == 0)
	{
		AfxMessageBox("请输入房间号!!!!!");
		return ;
	}
	j = 0;
    while(j<roomtotal)
	{
		m_listOut.GetText(j,roomNum[j]); 	    
		j++;
	}
    
	CString str1;
	for(j=0;j<roomtotal;j++)
	{
		str1+=roomNum[j]+"   ";
	}
    m_roomnumber.SetWindowText(str1);
	//获取房间类型
	m_roomtype.GetWindowText(str);   
	
	//获取当前日期
	CTime time;
	time = CTime::GetCurrentTime();                
	int year,month,day;
	year = time.GetYear();
    month = time.GetMonth();
	day = time.GetDay();

    //数据库建立连接
	C_Connection m_connection;
	m_connection.open("Hotel");  
	CString sql ;
    //获取流水号
    sql.Format("SELECT 客户流水号 FROM serialID where 状态 = '可用';");
    m_connection.ExcuteSql(sql);
	if(m_connection.rs->IsEOF())
	{
		AfxMessageBox("客户流水号没有可用的!!!");
		return ;
	}
	m_connection.rs->GetFieldValue("客户流水号",serial);
    m_connection.rs->Close();
	m_serial.SetWindowText(serial); 

	bookDate.SetDate(year,month,day);                 //存储系统当前日期
    str.Format("%d-%d-%d",time.GetYear(),time.GetMonth(),time.GetDay()); 
	m_bookdate.SetWindowText(str);

	m_serial.SetWindowText(serial); 

	str.Format("SELECT 房间价格 FROM roomPrice WHERE 房间类型='%s';",roomType);
	m_connection.ExcuteSql(str);
    str = "";
    m_connection.rs->GetFieldValue("房间价格",str);
	roomPrice = atoi(str);
	totalCash = roomtotal*roomPrice*bookDay/10;
	m_connection.close();	
	(CWnd *)GetDlgItem(IDC_BOOKROOM)->EnableWindow(FALSE);     //灰化确定订房按钮
	(CWnd *)GetDlgItem(IDC_DEFRAYEARNEST)->EnableWindow(TRUE); //亮化支付定金按钮
	(CWnd *)GetDlgItem(IDC_CANCELBOOK)->EnableWindow(TRUE);    //亮化取消订房按钮
    (CWnd *)GetDlgItem(IDC_newClient)->EnableWindow(FALSE);    //灰化新用户订房按钮
}

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

void BookDlg::clear()
{
	m_listOut.ResetContent();
    m_listIn.ResetContent();
	GetDlgItem(IDC_bookDays)->SetWindowText("");
	GetDlgItem(IDC_bookDate)->SetWindowText("");
	GetDlgItem(IDC_roomType)->SetWindowText("");
	GetDlgItem(IDC_roomNumber)->SetWindowText("");
    GetDlgItem(IDC_Serial)->SetWindowText("");
    GetDlgItem(IDC_clientName)->SetWindowText("");
    (CWnd *)GetDlgItem(IDC_BOOKROOM)->EnableWindow(TRUE);       //亮化确定订房按钮	
    (CWnd *)GetDlgItem(IDC_DEFRAYEARNEST)->EnableWindow(FALSE); //灰化支付定金按钮
    (CWnd *)GetDlgItem(IDC_CANCELBOOK)->EnableWindow(FALSE);    //灰化取消订房按钮
	(CWnd *)GetDlgItem(IDC_newClient)->EnableWindow(TRUE);      //亮化新用户订房按钮
}

void BookDlg::OnDefrayearnest() 
{
	// TODO: Add your control notification handler code here
   cashDlg	  dlg;
	dlg.init(roomNum,totalCash,roomtotal);       //缴费对话框初始化
	if(dlg.DoModal()==IDOK)
	{	
		C_Connection m_connection;
		m_connection.open("Hotel");              //数据库建立连接

		CString sql; 
		for(int i=0;i<roomtotal;i++)             //从room表中将入住的房间改为“已住”
		{
			sql.Format("UPDATE room SET 房间状态='预约' where 房间类型 = '%s' AND 房间号 = '%s' ;",roomType,roomNum[i]);
            m_connection.WriteSql(sql);
		}

		CString str1,str2,str3;
		COleDateTime date2;
        date2 = bookDate;
		date2 += 7;                              //预约截止日期 (一般最多提前一个星期预约)
		str1.Format("%d/%d/%d",bookDate.GetMonth(),bookDate.GetDay(),bookDate.GetYear());
        str2.Format("%d/%d/%d",date2.GetMonth(),date2.GetDay(),date2.GetYear());
		int price = roomPrice*bookDay/10;        //定金为 房间价格*订房天数/10
        for(i=0;i<roomtotal;i++)                 //登记book表(房间号,客户流水号,订房日期,截止日期,定金支付)
		{                                  
			sql.Format("INSERT INTO book \
				(房间号,客户流水号,订房日期,截止日期,定金支付,订房天数) \
				VALUES ('%s','%s','%s','%s',%d,%d) ",roomNum[i],serial,str1,str2,price,bookDay);
            m_connection.WriteSql(sql);
		}

		CString ID;
		CHotelManageSysDlg  *dlg;     
        dlg   =   (CHotelManageSysDlg*)(AfxGetApp()->m_pMainWnd);     //获取主对话框句柄
		dlg->m_ID.GetWindowText(ID);                                  //获取主对话框的“用户名”
		for(i=0;i<roomtotal;i++)                        //登记log表(用户名,操作类型,房间号,操作日期)
		{
			sql.Format("INSERT INTO log \
				(房间号,用户名,操作类型,操作日期) \
				VALUES ('%s','%s','订房','%s') ",roomNum[i],ID,str1);
		    m_connection.WriteSql(sql);
		}

        //获取客户名
		CString ClientName;
        m_clientname.GetWindowText(ClientName);          
		//登记client表(客户流水号,客户名)
		sql.Format("INSERT INTO client (客户流水号,客户名,房间数) VALUES ('%s','%s',%d)",serial,ClientName,roomtotal);        
        m_connection.WriteSql(sql);  

        //更新serialID表
		sql.Format("UPDATE serialID SET 状态 = '不可用' WHERE 客户流水号 = '%s' ;" ,serial);
		m_connection.WriteSql(sql); 

		//关闭数据库
		m_connection.close();
		//清空对话框
		OnCancelbook();	         
		//灰化确定订房按钮                               
	   (CWnd *)GetDlgItem(IDC_BOOKROOM)->EnableWindow(FALSE);   	
	}	
}

void BookDlg::OnnewClient() 
{
	// TODO: Add your control notification handler code here
	(CWnd *)GetDlgItem(IDC_BOOKROOM)->EnableWindow(TRUE);        //亮化确定订房按钮
	(CWnd *)GetDlgItem(IDC_CANCELBOOK)->EnableWindow(FALSE); 	 //灰化取消订房按钮	
}

⌨️ 快捷键说明

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