📄 voterecord.cpp
字号:
// VoteRecord.cpp : implementation file
//
#include "stdafx.h"
#include "Office.h"
#include "VoteRecord.h"
#include "Vote.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVoteRecord dialog
CVoteRecord::CVoteRecord(CWnd* pParent /*=NULL*/)
: CDialog(CVoteRecord::IDD, pParent)
{
//{{AFX_DATA_INIT(CVoteRecord)
m_staff = _T("");
m_content = _T("");
m_publishDate = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
}
void CVoteRecord::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVoteRecord)
DDX_Control(pDX, IDC_STAFF, m_staffCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_CBString(pDX, IDC_STAFF, m_staff);
DDX_Text(pDX, IDC_CONTENT, m_content);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVoteRecord, CDialog)
//{{AFX_MSG_MAP(CVoteRecord)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_MODIFY, OnModify)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_CANCELLATION, OnCancellation)
ON_BN_CLICKED(IDC_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVoteRecord message handlers
BOOL CVoteRecord::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);
cwnd_list = GetDlgItem(IDC_LIST1);
cwnd_staff = GetDlgItem(IDC_STAFF);
cwnd_content = GetDlgItem(IDC_CONTENT);
cwnd_add = GetDlgItem(IDC_ADD);
cwnd_cancel = GetDlgItem(IDC_CANCELLATION);
cwnd_delete = GetDlgItem(IDC_DELETE);
cwnd_modify = GetDlgItem(IDC_MODIFY);
cwnd_save = GetDlgItem(IDC_SAVE);
cwnd_exit = GetDlgItem(IDC_EXIT);
_RecordsetPtr m_pRecordset;
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();
}
}
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(false);
cwnd_content->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancel->EnableWindow(false);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CVoteRecord::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
m_content=m_list.GetItemText(nFirstSelItem,2);
}
CVote vote;
vote.GetData(m_content);
m_staff=vote.GetStaff();
m_publishDate=vote.GetPublishDate();
m_content=vote.GetContent();
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(false);
cwnd_content->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancel->EnableWindow(false);
cwnd_delete->EnableWindow(true);
cwnd_modify->EnableWindow(true);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
UpdateData(false);
*pResult = 0;
}
void CVoteRecord::OnAdd()
{
m_staff = _T("");
m_content = _T("");
m_publishDate = COleDateTime::GetCurrentTime();
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(true);
cwnd_content->EnableWindow(true);
cwnd_add->EnableWindow(false);
cwnd_cancel->EnableWindow(true);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(true);
cwnd_exit->EnableWindow(false);
flag=1;
UpdateData(false);
}
void CVoteRecord::OnDelete()
{
UpdateData(true);
CVote vote;
vote.sqlDelete(m_content);
m_staff = _T("");
m_content = _T("");
m_publishDate = COleDateTime::GetCurrentTime();
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(false);
cwnd_content->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancel->EnableWindow(false);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
Refresh();
UpdateData(false);
}
void CVoteRecord::OnModify()
{
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(true);
cwnd_content->EnableWindow(false);
cwnd_add->EnableWindow(false);
cwnd_cancel->EnableWindow(true);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(true);
cwnd_exit->EnableWindow(false);
flag=2;
UpdateData(false);
}
void CVoteRecord::OnSave()
{
UpdateData(true);
if(flag==1)
{
CVote vote;
vote.SetStaff(m_staff);
vote.SetPublishDate(m_publishDate);
vote.SetContent(m_content);
vote.sqlInsert();
}
else if(flag==2)
{
CVote vote;
vote.SetStaff(m_staff);
vote.SetPublishDate(m_publishDate);
vote.SetContent(m_content);
vote.sqlUpdate(m_content);
}
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(false);
cwnd_content->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancel->EnableWindow(false);
cwnd_delete->EnableWindow(true);
cwnd_modify->EnableWindow(true);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
Refresh();
UpdateData(false);
}
void CVoteRecord::OnCancellation()
{
m_staff = _T("");
m_content = _T("");
m_publishDate = COleDateTime::GetCurrentTime();
cwnd_list->EnableWindow(true);
cwnd_staff->EnableWindow(false);
cwnd_content->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancel->EnableWindow(false);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
UpdateData(false);
}
void CVoteRecord::OnExit()
{
this->OnCancel();
}
void CVoteRecord::Refresh()
{
m_list.DeleteAllItems();
_RecordsetPtr m_pRecordset;
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();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -