www.gusucode.com > VC++宾馆管理系统(Access)程序 > VC++宾馆管理系统(Access)程序\code\StandardDlg.cpp

    // StandardDlg.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "HotelManageSys.h"
#include "StandardDlg.h"

#include "Columns.h"
#include "Column.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStandardDlg dialog
extern CHotelManageSysApp theApp;

CStandardDlg::CStandardDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStandardDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStandardDlg)
	m_bAircondition = FALSE;
	m_bInternet = FALSE;
	m_bTelephone = FALSE;
	m_bTelevision = FALSE;
	m_bWashroom = FALSE;
	m_strStanType = _T("");
	m_nStanArea = 0;
	m_strStanId = _T("");
	m_nPeople = 0;
	m_nStanPrice = 0;
	//}}AFX_DATA_INIT
}


void CStandardDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStandardDlg)
	DDX_Control(pDX, IDC_DATAGRID_STANDARD, m_dgStandard);
	DDX_Check(pDX, IDC_CHECK_AIRCONDITION, m_bAircondition);
	DDX_Check(pDX, IDC_CHECK_INTERNET, m_bInternet);
	DDX_Check(pDX, IDC_CHECK_TELEPHONE, m_bTelephone);
	DDX_Check(pDX, IDC_CHECK_TELEVISION, m_bTelevision);
	DDX_Check(pDX, IDC_CHECK_WASHROOM, m_bWashroom);
	DDX_CBString(pDX, IDC_COMBO_STAN_TYPE, m_strStanType);
	DDX_Text(pDX, IDC_EDIT_STAN_AREA, m_nStanArea);
	DDX_Text(pDX, IDC_EDIT_STAN_ID, m_strStanId);
	DDX_Text(pDX, IDC_EDIT_STAN_PEOPLE, m_nPeople);
	DDX_Text(pDX, IDC_EDIT_STAN_PRICE, m_nStanPrice);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStandardDlg, CDialog)
//{{AFX_MSG_MAP(CStandardDlg)
ON_BN_CLICKED(ID_ADD_STAN_BTN, OnAddStanBtn)
ON_EN_CHANGE(IDC_EDIT_STAN_ID, OnChangeEditStanId)
ON_BN_CLICKED(IDC_MODIFY_STAN_BTN, OnModifyStanBtn)
ON_BN_CLICKED(IDC__DEL_STAN_BTN, OnDelStanBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStandardDlg message handlers

BOOL CStandardDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_bAircondition = FALSE;
	m_bInternet = FALSE;
	m_bTelephone = FALSE;
	m_bTelevision = FALSE;
	m_bWashroom = FALSE;
	m_strStanType = _T("单人间");
	m_nStanArea = 0;
	m_strStanId = _T("0");
	m_nPeople = 0;
	m_nStanPrice = 0;
	
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open("SELECT * FROM RoomStandard",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       
	
	m_dgStandard.SetRefDataSource(NULL);
	m_dgStandard.SetRefDataSource((LPUNKNOWN)m_pRecordset);
	m_dgStandard.SetColumnHeaders(2) ;
	
	_variant_t var;
	var = long(0);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("编号");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(40);
	var = long(1);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("类型");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(50);
	var = long(2);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("面积");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(3);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("容纳");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(4);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("空调");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(5);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("电话");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(6);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("电视");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(7);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("网络");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(8);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("卫生间");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(40);
	var = long(9);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("价格");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	
	m_dgStandard.Refresh();
	
	UpdateData(FALSE);	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CStandardDlg::OnAddStanBtn() 
{
	// TODO: Add your control notification handler code here
	if( theApp.m_level%2 == 0)//取余
	{
		AfxMessageBox("您不具有添加客房标准信息的权限");
		return;
	}
	
	UpdateData(TRUE);
	CString sql,str;
	sql = "select * from RoomStandard where ID = '"+m_strStanId+"'";
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	
	if (m_pRecordset->GetRecordCount()>0)
	{
		AfxMessageBox("该客房已添加,请重新输入客房");
		return;
	}
	else
	{
		m_pRecordset->AddNew();
		
		m_pRecordset->PutCollect("ID",(_variant_t)m_strStanId);
		
		str.Format("%d",m_bAircondition);
		m_pRecordset->PutCollect("Aircondition",(_variant_t)str);
		
		str.Format("%d",m_bInternet);
		m_pRecordset->PutCollect("Internet",(_variant_t)str);
		
		str.Format("%d",m_bTelephone);
		m_pRecordset->PutCollect("Telephone",(_variant_t)str);
		
		str.Format("%d",m_bTelevision);
		m_pRecordset->PutCollect("Television",(_variant_t)str);
		
		str.Format("%d",m_bWashroom);
		m_pRecordset->PutCollect("Washroom",(_variant_t)str);
		
		m_pRecordset->PutCollect("Type",(_variant_t)m_strStanType);
		
		str.Format("%d",m_nStanArea);
		m_pRecordset->PutCollect("Area",(_variant_t)str);
		
		str.Format("%d",m_nPeople);
		m_pRecordset->PutCollect("PeopleNum",(_variant_t)str);
		
		str.Format("%d",m_nStanPrice);
		m_pRecordset->PutCollect("Price",(_variant_t)str);
		
		m_pRecordset->Update();
		m_pRecordset->Close();
		
		UpdateList();
		
		UpdateData(FALSE);	
	}
	
}

void CStandardDlg::OnChangeEditStanId() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString sql,str;
	sql = "select * from RoomStandard where ID = '"+m_strStanId+"'";
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	
	
	if(m_pRecordset->GetRecordCount()!= 0)
	{
		m_bAircondition = m_pRecordset->GetCollect("Aircondition").lVal;
		m_bInternet = m_pRecordset->GetCollect("Internet").lVal;
		m_bTelephone = m_pRecordset->GetCollect("Telephone").lVal;
		m_bTelevision = m_pRecordset->GetCollect("Television").lVal;
		m_bWashroom = m_pRecordset->GetCollect("Washroom").lVal;
		m_strStanType = m_pRecordset->GetCollect("Type").bstrVal;
		m_nStanArea = m_pRecordset->GetCollect("Area").lVal;
		m_nPeople = m_pRecordset->GetCollect("PeopleNum").lVal;
		m_nStanPrice = m_pRecordset->GetCollect("Price").lVal;
	}
	m_pRecordset->Close();
	
	UpdateData(FALSE);
}

void CStandardDlg::OnModifyStanBtn() 
{
	// TODO: Add your control notification handler code here
	if(theApp.m_level!=2&&theApp.m_level!=3&&theApp.m_level!=6&&theApp.m_level!=7&&
		theApp.m_level!=10&&theApp.m_level!=11&&theApp.m_level!=14&&theApp.m_level!=15)
	{
		AfxMessageBox("您不具有修改客房标准信息的权限");
		return;
	}
	
	UpdateData(TRUE);
	CString sql,str;
	sql = "select * from RoomStandard where ID='"+m_strStanId+"'";
	
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	
	
	if(m_pRecordset->GetRecordCount()!=0)
	{
		str.Format("%d",m_bAircondition);
		m_pRecordset->PutCollect("Aircondition",(_variant_t)str);
		
		str.Format("%d",m_bInternet);
		m_pRecordset->PutCollect("Internet",(_variant_t)str);
		
		str.Format("%d",m_bTelephone);
		m_pRecordset->PutCollect("Telephone",(_variant_t)str);
		
		str.Format("%d",m_bTelevision);
		m_pRecordset->PutCollect("Television",(_variant_t)str);
		
		str.Format("%d",m_bWashroom);
		m_pRecordset->PutCollect("Washroom",(_variant_t)str);
		
		m_pRecordset->PutCollect("Type",(_variant_t)m_strStanType);
		
		str.Format("%d",m_nStanArea);
		m_pRecordset->PutCollect("Area",(_variant_t)str);
		
		str.Format("%d",m_nPeople);
		m_pRecordset->PutCollect("PeopleNum",(_variant_t)str);
		
		str.Format("%d",m_nStanPrice);
		m_pRecordset->PutCollect("Price",(_variant_t)str);
		
		m_pRecordset->Update();
	}
	else
	{
		AfxMessageBox("该客房不存在,修改失败!");
	}
	
	m_pRecordset->Close();
	
	UpdateList();
	UpdateData(FALSE);		
}

void CStandardDlg::OnDelStanBtn() 
{
	// TODO: Add your control notification handler code here
	if((!(theApp.m_level >=4 && theApp.m_level <= 7)) && (!(theApp.m_level >=12 && theApp.m_level <= 15)) )
	{
		AfxMessageBox("您不具有删除客房标准信息的权限");
		return;
	}
	UpdateData(TRUE);
	CString sql,str;
	sql = "select * from RoomStandard where ID='"+m_strStanId+"'";
	
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	
	
	if(m_pRecordset->GetRecordCount()!=0)
	{
		m_pRecordset->Delete(adAffectCurrent);
		m_pRecordset->Update();
	}
	else
	{
		AfxMessageBox("该客房不存在,删除失败!");
	}
	
	m_pRecordset->Close();
	
	UpdateList();
	UpdateData(FALSE);			
}

void CStandardDlg::UpdateList()
{
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open("SELECT * FROM RoomStandard",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       
	
	m_dgStandard.SetRefDataSource(NULL);
	m_dgStandard.SetRefDataSource((LPUNKNOWN)m_pRecordset);
	m_dgStandard.SetColumnHeaders(2) ;
	
	_variant_t var;
	var = long(0);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("编号");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(40);
	var = long(1);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("类型");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(50);
	var = long(2);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("面积");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(3);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("容纳");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(4);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("空调");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(5);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("电话");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(6);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("电视");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(7);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("网络");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	var = long(8);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("卫生间");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(40);
	var = long(9);
	m_dgStandard.GetColumns().GetItem(var).SetCaption("价格");
	m_dgStandard.GetColumns().GetItem(var).SetWidth(30);
	
	m_dgStandard.Refresh();
	
	UpdateData(FALSE);	
}