www.gusucode.com > VC++酒店业务管理系统源程序代码-源码程序 > VC++酒店业务管理系统源程序代码-源码程序\code\代码\RMSDlg.cpp

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

#include "stdafx.h"
#include "RMS.h"
#include "RMSDlg.h"
#include "DlgProxy.h"
#include "DataBinding.h"
#include "DlgLogIn.h"
#include "DlgUpdPwd.h"
#include "DlgDC.h"
#include "DlgJS.h"
#include "DlgBeginJS.h"
#include "DlgViewZBY.h"
#include "DlgViewCP.h"
#include "DlgViewKH.h"
#include "DlgViewDC.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRMSDlg dialog

IMPLEMENT_DYNAMIC(CRMSDlg, CDialog);

CRMSDlg::CRMSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRMSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRMSDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_pAutoProxy = NULL;
}

CRMSDlg::~CRMSDlg()
{
	// If there is an automation proxy for this dialog, set
	//  its back pointer to this dialog to NULL, so it knows
	//  the dialog has been deleted.
	if (m_pAutoProxy != NULL)
		m_pAutoProxy->m_pDialog = NULL;
}

void CRMSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRMSDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRMSDlg, CDialog)
	//{{AFX_MSG_MAP(CRMSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BTN_ZBY, OnBtnZby)
	ON_BN_CLICKED(IDC_BTN_CP, OnBtnCp)
	ON_BN_CLICKED(IDC_BTN_ABOUT, OnBtnAbout)
	ON_BN_CLICKED(IDC_BTN_DC, OnBtnDc)
	ON_BN_CLICKED(IDC_BTN_HELP, OnBtnHelp)
	ON_BN_CLICKED(IDC_BTN_JS, OnBtnJs)
	ON_BN_CLICKED(IDC_BTN_KH, OnBtnKh)
	ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
	ON_BN_CLICKED(IDC_BTN_UPDPWD, OnBtnUpdpwd)
	ON_BN_CLICKED(IDC_BTN_VIEWDC, OnBtnViewdc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRMSDlg message handlers

BOOL CRMSDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	try
	{
		m_DBCnt.CreateInstance(__uuidof(Connection));
		m_DBCnt->ConnectionString = "DSN=MyDS;UID=fdd;PWD=121"; //	"driver={SQL Server};server=HS;UID=fdd;PWD=111;database=RMS";
		m_DBCnt->Open("","","",-1);
	}
	catch(_com_error& e)
    {
        AfxMessageBox(e.ErrorMessage());
		this->EndDialog(0);
    }                              

	GetDlgItem(IDC_BTN_UPDPWD)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_DC)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_JS)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_KH)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_CP)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_ZBY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_VIEWDC)->EnableWindow(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CRMSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CRMSDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CRMSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// Automation servers should not exit when a user closes the UI
//  if a controller still holds on to one of its objects.  These
//  message handlers make sure that if the proxy is still in use,
//  then the UI is hidden but the dialog remains around if it
//  is dismissed.

void CRMSDlg::OnClose() 
{
	if (CanExit())
		CDialog::OnClose();
}

void CRMSDlg::OnOK() 
{
	if (CanExit())
		CDialog::OnOK();
}

void CRMSDlg::OnCancel() 
{
	if (CanExit())
		CDialog::OnCancel();
}

BOOL CRMSDlg::CanExit()
{
	// If the proxy object is still around, then the automation
	//  controller is still holding on to this application.  Leave
	//  the dialog around, but hide its UI.
	if (m_pAutoProxy != NULL)
	{
		ShowWindow(SW_HIDE);
		return FALSE;
	}

	return TRUE;
}

void CRMSDlg::OnBtnZby() 
{
	CDlgViewZBY dlg;
	ShowWindow(SW_HIDE);
	dlg.DoModal();
	ShowWindow(SW_SHOW);
}

void CRMSDlg::OnBtnCp() 
{
	CDlgViewCP dlg;
	ShowWindow(SW_HIDE);
	dlg.Setup(m_DBCnt);
	dlg.DoModal();
	ShowWindow(SW_SHOW);
}

void CRMSDlg::OnBtnKh() 
{
	CDlgViewKH dlg;
	ShowWindow(SW_HIDE);
	dlg.Setup(m_DBCnt);
	dlg.DoModal();
	ShowWindow(SW_SHOW);
}

void CRMSDlg::OnBtnDc() 
{
	CDlgDC dlg;
	ShowWindow(SW_HIDE);
	dlg.Setup(m_DBCnt);
	dlg.DoModal();
	ShowWindow(SW_SHOW);
}

void CRMSDlg::OnBtnViewdc() 
{
	CDlgViewDC dlg;
	ShowWindow(SW_HIDE);
	dlg.Setup(m_DBCnt);
	dlg.DoModal();
	ShowWindow(SW_SHOW);
}

void CRMSDlg::OnBtnJs() 
{
	CDlgBeginJS dlg1;
	ShowWindow(SW_HIDE);
	
	dlg1.DoModal();
	if (dlg1.m_desk.GetLength()>0)
	{
		CDlgJS dlg2;
		dlg2.Setup(m_DBCnt, dlg1.m_desk, dlg1.m_dz);
		dlg2.DoModal();
	} else
	{
		MessageBox("请输入桌号!");
	}
	ShowWindow(SW_SHOW);

}

void CRMSDlg::OnBtnLogin() 
{
	CDlgLogin dlg;
	dlg.DoModal();

	try
	{
		CString sql_;
		sql_.Format("SELECT ZBY_NAME FROM ZBY WHERE ZBY_NAME='%s' AND ZBY_PSWD='%s'",
			dlg.m_name, dlg.m_pswd);
		_bstr_t sql = sql_;
		_RecordsetPtr pRst;

		pRst = m_DBCnt->Execute(sql, NULL, adCmdText);
		if (!pRst->adoEOF)
		{
			MessageBox("登录成功!");
			GetDlgItem(IDC_BTN_UPDPWD)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_DC)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_JS)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_KH)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_CP)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_ZBY)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_VIEWDC)->EnableWindow(TRUE);
		} else
		{
			MessageBox("登录失败!");
		}
		pRst->Close();
	} 
	catch(_com_error& e)
	{
        AfxMessageBox(e.ErrorMessage());
		return;
    } 

}

void CRMSDlg::OnBtnUpdpwd() 
{
	CDlgUpdPwd dlg;
	dlg.DoModal();

	if (dlg.m_newpswd!=dlg.m_newpswd2)
	{
		MessageBox("两次输入新密码不一致!");
		return;
	}

	try
	{
		CString sql_;
		sql_.Format("SELECT ZBY_NAME FROM ZBY WHERE ZBY_NAME='%s' AND ZBY_PSWD='%s'",
			dlg.m_name, dlg.m_oldpswd);
		_bstr_t sql = sql_;
		_RecordsetPtr pRst;

		pRst = m_DBCnt->Execute(sql, NULL, adCmdText);
		if (pRst->adoEOF)
		{
			MessageBox("密码错误!");
			pRst->Close();
			return;
		}
		pRst->Close();

		sql_.Format("Update ZBY SET ZBY_PSWD='%s' WHERE ZBY_NAME='%s'",
			dlg.m_newpswd, dlg.m_name);
		sql = sql_;

		m_DBCnt->Execute(sql, NULL, adCmdText);

		MessageBox("修改密码成功!");
	} 
	catch(_com_error& e)
	{
        AfxMessageBox(e.ErrorMessage());
		return;
    } 
}

void CRMSDlg::OnBtnAbout() 
{
	CAboutDlg dlg;
	dlg.DoModal();
}

void CRMSDlg::OnBtnHelp() 
{
	WinExec("hh.exe rms.chm", SW_SHOW);
}