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

📄 checkinregdlg.cpp

📁 系统主要包括住宿管理,客房管理,查询统计,报表管理,系统设置五个模块,适用于中小型宾馆酒店。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
	// 
	try
	{//打开数据库
		m_pRecordset->Open("SELECT * FROM checkinregtable",                // 查询表中所有字段
							theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);
	}
	catch(_com_error *e)//捕获打开数据库时候的各种异常
	{
		AfxMessageBox(e->ErrorMessage());
	}
//////////////////////////////////////////////////////////////

	   try
	   {
		// 写入各字段值,准备更新数据库
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("凭证号码", _variant_t(m_regnumber));
		m_pRecordset->PutCollect("姓名",_variant_t(m_gustname));
		m_pRecordset->PutCollect("证件名称", _variant_t(m_zhengjian));
        m_pRecordset->PutCollect("证件号码", _variant_t(m_zhengjian_number));
	
		m_pRecordset->PutCollect("详细地址", _variant_t(m_gustaddr));
		m_pRecordset->PutCollect("出差事由",_variant_t(m_checkinreg_reason));
		m_pRecordset->PutCollect("房间号", _variant_t(m_roomnumber));
        m_pRecordset->PutCollect("客房类型", _variant_t(m_roomlevel));
	   
		CString str_room_money;
	    m_room_money.GetWindowText(str_room_money);
	    m_pRecordset->PutCollect("客房价格", _variant_t(str_room_money));
	
		CString checkindate;//获取登记住宿日期
    	int nYear,nDay,nMonth;
	    CString sYear,sDay,sMonth;
	    nYear=m_checkindate.GetYear();//提取年份
	   nDay=m_checkindate.GetDay();//提取日
	   nMonth=m_checkindate.GetMonth();//提取月份
    	sYear.Format("%d",nYear);//转换为字符串
	    sDay.Format("%d",nDay);//转换为字符串
	    sMonth.Format("%d",nMonth);//转换为字符串
	    checkindate.Format("%s-%s-%s",sYear,sMonth,sDay);//格式化时间
		m_pRecordset->PutCollect("住宿日期",_variant_t(checkindate));
		//保存
		CString checkintime;//准备获取登记住宿时间
    	int nhour,nmin,nsecond;
	    CString shour,smin,ssecond;
	    nhour=m_checkindate.GetHour();//提取小时数
	   nmin=m_checkindate.GetMinute();//提取分钟
	   nsecond=m_checkindate.GetSecond();//提取秒
    	shour.Format("%d",nhour);//转换为字符串
	    smin.Format("%d",nmin);//转换为字符串
	    ssecond.Format("%d",nsecond);//转换为字符串
	    checkintime.Format("%s:%s:%s",shour,smin,ssecond);//格式化时间
		m_pRecordset->PutCollect("住宿时间", _variant_t(checkintime));
        m_pRecordset->PutCollect("住宿天数", _variant_t(m_checkdays));
	    //定义临时存储空间
		char str_money[50]; 
	   _gcvt(atof(str_room_money)*m_checkdays, 4, str_money );
		m_pRecordset->PutCollect("宿费", _variant_t(str_money));
	

		m_pRecordset->PutCollect("折扣",_variant_t(m_discountnumber));
		//定义临时存储空间
		char strhand_money[50]; 
	   _gcvt(atof(m_realmoney)*m_discountnumber/100, 4, strhand_money );
	   	m_pRecordset->PutCollect("应收宿费", _variant_t(strhand_money));
        m_pRecordset->PutCollect("预收金额", _variant_t(m_pre_handinmoney));
	    
		CString alarmdate;//准备获取提醒日期
        nYear=m_alarmdate.GetYear();//提取年份
	   nDay=m_alarmdate.GetDay();//提取日
	   nMonth=m_alarmdate.GetMonth();//提取月份
    	sYear.Format("%d",nYear);//转换为字符串
	    sDay.Format("%d",nDay);//转换为字符串
	    sMonth.Format("%d",nMonth);//转换为字符串
	    alarmdate.Format("%s-%s-%s",sYear,sMonth,sDay);//格式化时间
		m_pRecordset->PutCollect("提醒日期", _variant_t(alarmdate));
	
        CString checkoutdate;//准备获取退宿日期
        nYear=m_checkoutdate.GetYear();//提取年份
	   nDay=m_checkoutdate.GetDay();//提取日
	   nMonth=m_checkoutdate.GetMonth();//提取月份
    	sYear.Format("%d",nYear);//转换为字符串
	    sDay.Format("%d",nDay);//转换为字符串
	    sMonth.Format("%d",nMonth);//转换为字符串
	    checkoutdate.Format("%s-%s-%s",sYear,sMonth,sDay);//格式化时间
		m_pRecordset->PutCollect("退宿日期",_variant_t(checkoutdate));
		m_pRecordset->PutCollect("备注", _variant_t(m_beizhu));


		CString nowdate,nowtime;//准备获取当前日期
		CTime tTime;
 	   tTime=tTime.GetCurrentTime(); 
	   nYear=tTime.GetYear();//提取年份
	   nDay=tTime.GetDay();
	   nMonth=tTime.GetMonth();//提取月份
	   sYear.Format("%d",nYear);//转换为字符串
	   sDay.Format("%d",nDay);//转换为字符串
	   sMonth.Format("%d",nMonth);//转换为字符串
	   nowdate.Format("%s-%s-%s",sYear,sMonth,sDay);//格式化时间

	   nhour=tTime.GetHour();////提取小时数,准备获取当前时间
	   nmin=tTime.GetMinute();//提取分钟
	   nsecond=tTime.GetSecond();//提取秒
    	shour.Format("%d",nhour);//转换为字符串
	    smin.Format("%d",nmin);//转换为字符串
	    ssecond.Format("%d",nsecond);//转换为字符串
	    nowtime.Format("%s:%s:%s",shour,smin,ssecond);//格式化时间
        m_pRecordset->PutCollect("日期", _variant_t(nowdate));
	    m_pRecordset->PutCollect("时间", _variant_t(nowtime));
	
		
		m_pRecordset->PutCollect("结款方式", _variant_t(m_discount_kind));
      
		CString checkouttime;//准备获取退宿时间
		nhour=m_checkouttime.GetHour();//提取小时数
	   nmin=m_checkouttime.GetMinute();//提取分钟
	   nsecond=m_checkouttime.GetSecond();//提取秒
    	shour.Format("%d",nhour);//转换为字符串
	    smin.Format("%d",nmin);//转换为字符串
	    ssecond.Format("%d",nsecond);//转换为字符串
	    checkouttime.Format("%s:%s:%s",shour,smin,ssecond);//格式化时间
		m_pRecordset->PutCollect("退宿时间", _variant_t(checkouttime));
	   
		CString alarmtime;//准备获取提醒时间
		nhour=m_alarmtime.GetHour();//提取小时数
	   nmin=m_alarmtime.GetMinute();//提取分钟
	   nsecond=m_alarmtime.GetSecond();//提取秒
    	shour.Format("%d",nhour);//转换为字符串
	    smin.Format("%d",nmin);//转换为字符串
	    ssecond.Format("%d",nsecond);//转换为字符串
	    alarmtime.Format("%s:%s:%s",shour,smin,ssecond);//格式化时间
		m_pRecordset->PutCollect("提醒时间", _variant_t(alarmtime));
	    //更新数据库
		m_pRecordset->Update();
        
		MessageBox("登记成功!","客房管理系统");
	   }
      	catch(_com_error *e)//捕获写入数据库时候可能发生的异常情况
		{
		AfxMessageBox(e->ErrorMessage());
		}
///////////////////////////////////////////////////
//关闭记录集
	m_pRecordset->Close();
	m_pRecordset = NULL;

//	CDialog::OnOK();
}



void CCheckinregdlg::OnChangeEDITcheckdays() 
{
	// 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.
		//获取输入数据
	UpdateData(true);
	CString str_room_money;
	m_room_money.GetWindowText(str_room_money);
	m_pre_discount=atof(str_room_money)*m_checkdays;
//更新显示
    UpdateData(false);
	// TODO: Add your control notification handler code here
	
}

void CCheckinregdlg::OnCloseupCOMBOroomnumber() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	int index=0;
    CString roomnumber;
	index=m_roomnumberctr.GetCurSel();//获取所选择的列表项目序号
	m_roomnumberctr.GetLBText(index,roomnumber);
	//获得选择的列表项目内容
	CString SQLstr;
	SQLstr="SELECT * FROM roomsetting where 房间号='" ;
    SQLstr+=roomnumber;
    SQLstr+="'";


	if(!myroominfoset.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
	{//查询数据库得到数据集合
		MessageBox("没有此房间号码,打开数据库失败!","客房管理系统");
			if(myroominfoset.IsOpen())
			{//关闭数据表
	         myroominfoset.Close();
			}
		return ;
	}
	if(myroominfoset.m_column4=="入住")//查看房间状态
	{
		MessageBox("此房间已经有人入住,请选择其他房间!","客房管理系统");
			if(myroominfoset.IsOpen())
			{//关闭数据表
	          myroominfoset.Close();
			}
		return ;
	}
    m_roomlevel=myroominfoset.m_column2;//读取数据
    m_room_money.SetWindowText(myroominfoset.m_column3);
//////////////////////////////////
	myroominfoset.Edit();
	//设置数据库操作类型
	if (issave)
		myroominfoset.m_column4="入住";
	myroominfoset.Update();
	myroominfoset.Requery();
	issave = false;
///////////////////////////////////
	if(myroominfoset.IsOpen())//打开数据库
	{
	   myroominfoset.Close();
	}
	regnumber=m_regnumber;//读入变量对应的将要写入的内容
	gustname=m_gustname;
	gustaddr=m_gustaddr;//读入变量对应的将要写入的内容
	
	zhengjian=m_zhengjian;//读入变量对应的将要写入的内容
	zhengjian_number=m_zhengjian_number;//读入变量对应的将要写入的内容
	checkinreg_reason=m_checkinreg_reason;//读入变量对应的将要写入的内容
    //更新显示
	UpdateData(false);
}

void CCheckinregdlg::OnChangediscountnumber() 
{
	// 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.
	UpdateData(true);
	CString need_room_money;

	float fneed_room_money=0;//初始化
	m_room_money.GetWindowText(need_room_money);//获取输入内容
    fneed_room_money=m_pre_discount*m_discountnumber;
    //定义临时存储空间
	char strhand_money[50]; 
	//格式转换
	_gcvt(fneed_room_money/100, 4, strhand_money );//格式转换
    m_realmoney=strhand_money;
	//更新显示
	UpdateData(false);
	// TODO: Add your control notification handler code here
	
}

void CCheckinregdlg::OnCancel_regin() 
{
	// TODO: Add your control notification handler code here
	//输入数据对应变量初始化
	m_regnumber = _T("");
	m_gustname = _T("");
	m_gustaddr = _T("");
	m_beizhu = _T("");
	m_pre_discount = 0.0f;
	m_roomlevel = _T("");
	m_zhengjian_number = _T("");
	m_checkinreg_reason = _T("");
	m_discount_kind = _T("");
	m_roomnumber = _T("");
	m_zhengjian = _T("");
	m_checkindate = 0;
	m_alarmdate = 0;
	m_alarmtime = 0;
	m_checkintime = 0;
	m_checkoutdate = 0;
	m_checkouttime = 0;
	m_checkdays = 0.0;
	m_discountnumber = 0.0;
	m_realmoney = _T("");
	m_pre_handinmoney = _T("");
    m_room_money.SetWindowText("");
	//初始化完毕
	//更新显示
	UpdateData(false);
}

BOOL CCheckinregdlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN)
	{
		pMsg->wParam=VK_TAB;
	        
	}
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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