?? chargedlg.cpp
字號:
// chargeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "charge.h"
#include "chargeDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CChargeDlg dialog
CChargeDlg::CChargeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChargeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChargeDlg)
m_UserId = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CChargeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChargeDlg)
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Text(pDX, IDC_EDIT1, m_UserId);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChargeDlg, CDialog)
//{{AFX_MSG_MAP(CChargeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_inquiry, Oninquiry)
ON_BN_CLICKED(IDC_CHARGE, OnCharge)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
extern CChargeApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CChargeDlg message handlers
BOOL CChargeDlg::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);
m_List.InsertColumn(0,"預(yù)約號",LVCFMT_LEFT,60);
m_List.InsertColumn(1,"姓名",LVCFMT_LEFT,80);
m_List.InsertColumn(2,"預(yù)約時間",LVCFMT_LEFT,100);
m_List.InsertColumn(3,"收費",LVCFMT_LEFT,60);
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
return TRUE; // return TRUE unless you set the focus to a control
}
void CChargeDlg::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 CChargeDlg::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 CChargeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CChargeDlg::Oninquiry()
{
UpdateData();
if(!m_UserId.IsEmpty())
{
CString sql="SELECT * FROM users where 用戶ID='"+m_UserId+"'" ;
try
{
//查詢數(shù)據(jù)庫,看是否有此用戶和密碼
m_pRecordset1.CreateInstance("ADODB.Recordset");
m_pRecordset1->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true), //如果沒有此用戶和密碼,再查詢是否有此用戶
adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset1->adoEOF)
{
AfxMessageBox("該用戶未注冊!");
return;
}
else
{
int nItem;
_variant_t vID,vUsername,vOld,vCharge;
vID = m_pRecordset1->GetCollect("預(yù)約號");
vUsername = m_pRecordset1->GetCollect("姓名");
vOld = m_pRecordset1->GetCollect("預(yù)約時間");
vCharge = m_pRecordset1->GetCollect("收費");
nItem=m_List.InsertItem(0xffff,(_bstr_t)vID);
m_List.SetItem(nItem,1,1,(_bstr_t)vUsername,NULL,0,0,0);
m_List.SetItem(nItem,2,1,(_bstr_t)vOld,NULL,0,0,0);
m_List.SetItem(nItem,3,1,(_bstr_t)vCharge,NULL,0,0,0);
}
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("連接數(shù)據(jù)庫錯誤信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
else
{
AfxMessageBox("請輸入用戶ID!");
}
}
void CChargeDlg::OnCharge()
{
UpdateData();
//for(int k=2;k>=0;k--) //注意要從后往前刪,否則出錯
// m_List.DeleteColumn(k);
//m_List.DeleteAllItems();
//m_List.DeleteItem(0);
int nCount = m_List.GetItemCount();
for (int i=0;i < nCount;i++)
{
m_List.DeleteItem(0);
}
if(!m_UserId.IsEmpty())
{
CString sql="SELECT * FROM users where 用戶ID='"+m_UserId+"'" ;
try
{
//查詢數(shù)據(jù)庫,看是否有此用戶和密碼
m_pRecordset1.CreateInstance("ADODB.Recordset");
m_pRecordset1->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true), //如果沒有此用戶和密碼,再查詢是否有此用戶
adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset1->adoEOF)
{
AfxMessageBox("該用戶未注冊!");
return;
}
else
{
m_pRecordset1->PutCollect("收費",_variant_t("已付"));
m_pRecordset1->Update();
AfxMessageBox("該用戶已繳費!");
}
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("連接數(shù)據(jù)庫錯誤信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
else
{
AfxMessageBox("請輸入用戶ID!");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -