📄 voteselect.cpp
字号:
// Voteselect.cpp : implementation file
//
#include "stdafx.h"
#include "Office.h"
#include "Voteselect.h"
#include "VoteselectClass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVoteselect dialog
CVoteselect::CVoteselect(CWnd* pParent /*=NULL*/)
: CDialog(CVoteselect::IDD, pParent)
{
//{{AFX_DATA_INIT(CVoteselect)
m_staff = _T("");
//}}AFX_DATA_INIT
}
void CVoteselect::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVoteselect)
DDX_Control(pDX, IDC_STAFF, m_staffCombo);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_CBString(pDX, IDC_STAFF, m_staff);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVoteselect, CDialog)
//{{AFX_MSG_MAP(CVoteselect)
ON_BN_CLICKED(IDC_EXPECT, OnExpect)
ON_BN_CLICKED(IDC_OPPOSITE, OnOpposite)
ON_BN_CLICKED(IDC_NONUSER, OnNonuser)
ON_BN_CLICKED(IDC_SUBMIT, OnSubmit)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVoteselect message handlers
void CVoteselect::OnExpect()
{
m_selection="同意";
}
void CVoteselect::OnOpposite()
{
m_selection="反对";
}
void CVoteselect::OnNonuser()
{
m_selection="弃权";
}
void CVoteselect::OnSubmit()
{
UpdateData(true); //将对话框数据更新到控件变量
CVoteselectClass voteSelect; //投票选择记录表数据库访问类
voteSelect.SetSelectDate(COleDateTime::GetCurrentTime()); //设定投票时间为当前系统时间
voteSelect.SetStaff(m_staff); //投票人
voteSelect.SetVoteContent(m_voteContent); //投票内容
voteSelect.SetSelection(m_selection); //投票选择
voteSelect.sqlInsert(); //将投票结果插入数据库
AfxMessageBox("投票结果已经提交!");
this->OnCancel();
}
void CVoteselect::OnExit()
{
this->OnCancel();
}
BOOL CVoteselect::OnInitDialog()
{
CDialog::OnInitDialog();
//设定列表框的样式
DWORD style;
style=m_list.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_list.SetExtendedStyle(style);
//为列表框控件添加列
m_list.InsertColumn(0,"发表人",LVCFMT_LEFT,100);
m_list.InsertColumn(1,"发表时间",LVCFMT_LEFT,100);
m_list.InsertColumn(2,"投票内容",LVCFMT_LEFT,100);
_RecordsetPtr m_pRecordset; //记录集
CString strSQL;
// _RecordsetPtr m_pRecordset; //记录集
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));//创建实例
strSQL="select distinct staffName from staff"; //查询语句
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText); //查询,打开记录集
int i=0;
while(!(m_pRecordset->adoEOF))
{
m_staffCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("staffName")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
// CString strSQL;
strSQL="select * from voteRecord"; //查询语句,返回所有的投票
// HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));//创建实例
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText); //打开查询结果记录集
int i=0;
while(!(m_pRecordset->adoEOF))
{
//将查询结果显示在列表框控件中
m_list.InsertItem(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("staff")));//发布人
m_list.SetItemText(i,1,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("publishDate")));//发布日期
m_list.SetItemText(i,2,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));//投票内容
i++;
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext(); //记录集指针向后移动
}
}
return TRUE;
}
void CVoteselect::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition(); //获得单击位置
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos); //获得单击条目
m_voteContent=m_list.GetItemText(nFirstSelItem,2); //获得单击的投票的内容
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -