📄 ballotdlg.cpp
字号:
// BallotDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Practical.h"
#include "BallotDlg.h"
#include "PieDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr m_pConnection; //连接对象指针
extern _RecordsetPtr m_pRecordset; //记录集对象指针
/////////////////////////////////////////////////////////////////////////////
// CBallotDlg dialog
CBallotDlg::CBallotDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBallotDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBallotDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CBallotDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBallotDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBallotDlg, CDialog)
//{{AFX_MSG_MAP(CBallotDlg)
ON_BN_CLICKED(IDC_BALLOT, OnBallot)
ON_BN_CLICKED(IDC_RESULT, OnResult)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBallotDlg message handlers
BOOL CBallotDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
int i=0,j=0;
RECT rect;
m_Font.CreatePointFont(90,"宋体");
CString sql = "select * from tb_ballot";
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
m_Name[i] = (char*)(_bstr_t)m_pRecordset->GetCollect("活动名称");
if(i==3*(j+1))
j++;
if(i>=j*3 && i<(j+1)*3)
{
rect.left = 10+(i-j*3)*120;
rect.top = 10+j*30;
rect.right = 120+(i-j*3)*120;
rect.bottom = 50+j*30;
}
m_Check[i].Create(m_Name[i],WS_CHILD|BS_CHECKBOX|BS_AUTOCHECKBOX,
CRect(0,40,10,50),this,1200+i);
m_Check[i].SetFont(&m_Font);
m_Check[i].MoveWindow(&rect);
m_Check[i].ShowWindow(SW_SHOW);
m_Check[i].SetFocus();
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name;
Name = Buffer;
sql.Format("select * from tb_isballot where 投票人='%s'",Name);
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
GetDlgItem(IDC_BALLOT)->EnableWindow(FALSE);
m_pRecordset->Close();
// m_Sum = i;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBallotDlg::OnBallot()
{
// TODO: Add your control notification handler code here
int num,i=0;
CString sql = "select * from tb_ballot";
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
CString str;
num = atoi((char*)(_bstr_t)m_pRecordset->GetCollect("活动票数"));
num = num + m_Check[i].GetCheck();
str.Format("%d",num);
m_pRecordset->GetFields()->GetItem("活动票数")->Value = (_bstr_t)str;
m_pRecordset->Update(); //更新数据库
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
MessageBox("投票成功");
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name;
Name = Buffer;
sql.Format("insert into tb_isballot (投票人) values ('%s')",Name);
m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
GetDlgItem(IDC_BALLOT)->EnableWindow(FALSE);
}
void CBallotDlg::OnResult()
{
// TODO: Add your control notification handler code here
CPieDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -