📄 ondutyrecord.cpp
字号:
// OndutyRecord.cpp : implementation file
//
#include "stdafx.h"
#include "Office.h"
#include "OndutyRecord.h"
#include "Onduty.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COndutyRecord dialog
COndutyRecord::COndutyRecord(CWnd* pParent /*=NULL*/)
: CDialog(COndutyRecord::IDD, pParent)
{
//{{AFX_DATA_INIT(COndutyRecord)
m_watcher = _T("");
m_beginDate = COleDateTime::GetCurrentTime();
m_endDate = COleDateTime::GetCurrentTime();
m_beginTime = COleDateTime::GetCurrentTime();
m_endTime = COleDateTime::GetCurrentTime();;
m_duty = _T("");
m_events = _T("");
m_remark = _T("");
//}}AFX_DATA_INIT
}
void COndutyRecord::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COndutyRecord)
DDX_Control(pDX, IDC_WATCHER, m_watcherCombo);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_CBString(pDX, IDC_WATCHER, m_watcher);
DDX_DateTimeCtrl(pDX, IDC_BEGINDATE, m_beginDate);
DDX_DateTimeCtrl(pDX, IDC_ENDDATE1, m_endDate);
DDX_DateTimeCtrl(pDX, IDC_BEGINTIME, m_beginTime);
DDX_DateTimeCtrl(pDX, IDC_ENDTIME, m_endTime);
DDX_Text(pDX, IDC_DUTY, m_duty);
DDX_Text(pDX, IDC_EVENTS, m_events);
DDX_Text(pDX, IDC_REMARK, m_remark);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COndutyRecord, CDialog)
//{{AFX_MSG_MAP(COndutyRecord)
ON_NOTIFY(NM_CLICK, IDC_LIST, 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()
/////////////////////////////////////////////////////////////////////////////
// COndutyRecord message handlers
void COndutyRecord::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition();
CString str_beginDate;
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
str_beginDate=m_list.GetItemText(nFirstSelItem,0);
}
CString strSQL;
strSQL="select * from ondutyRecord where beginDate='";
strSQL=strSQL+str_beginDate+"'";
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
CString str;
m_events= ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("events"));
m_watcher= ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("watcher"));
m_beginDate= m_pRecordset->GetCollect("beginDate");
m_beginTime= m_pRecordset->GetCollect("beginTime");
m_endDate= m_pRecordset->GetCollect("endDate");
m_endTime= m_pRecordset->GetCollect("endTime");
m_duty= ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("duty"));
m_remark= ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("remark"));
}
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(false);
cwnd_beginDate->EnableWindow(false);
cwnd_endDate->EnableWindow(false);
cwnd_beginTime->EnableWindow(false);
cwnd_endTime->EnableWindow(false);
cwnd_duty->EnableWindow(false);
cwnd_events->EnableWindow(false);
cwnd_remark->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancellation->EnableWindow(false);
cwnd_delete->EnableWindow(true);
cwnd_modify->EnableWindow(true);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
*pResult = 0;
UpdateData(false);
}
BOOL COndutyRecord::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);
m_list.InsertColumn(3,"任务",LVCFMT_LEFT,100);
m_list.InsertColumn(4,"重要记事",LVCFMT_LEFT,100);
_RecordsetPtr m_pRecordset;
CString strSQL;
strSQL="select * from ondutyRecord";
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("beginDate")));
m_list.SetItemText(i,1,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("beginTime")));
m_list.SetItemText(i,2,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("watcher")));
m_list.SetItemText(i,3,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("duty")));
m_list.SetItemText(i,4,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("events")));
i++;
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
cwnd_list = GetDlgItem(IDC_LIST);
cwnd_watcher = GetDlgItem(IDC_WATCHER);
cwnd_beginDate = GetDlgItem(IDC_BEGINDATE);
cwnd_endDate = GetDlgItem(IDC_BEGINTIME);
cwnd_beginTime = GetDlgItem(IDC_ENDDATE1);
cwnd_endTime = GetDlgItem(IDC_ENDTIME);
cwnd_duty = GetDlgItem(IDC_DUTY);
cwnd_events = GetDlgItem(IDC_EVENTS);
cwnd_remark = GetDlgItem(IDC_REMARK);
cwnd_add = GetDlgItem(IDC_ADD);
cwnd_cancellation = GetDlgItem(IDC_CANCELLATION);
cwnd_delete = GetDlgItem(IDC_DELETE);
cwnd_modify = GetDlgItem(IDC_MODIFY);
cwnd_save = GetDlgItem(IDC_SAVE);
cwnd_exit = GetDlgItem(IDC_EXIT);
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(false);
cwnd_beginDate->EnableWindow(false);
cwnd_endDate->EnableWindow(false);
cwnd_beginTime->EnableWindow(false);
cwnd_endTime->EnableWindow(false);
cwnd_duty->EnableWindow(false);
cwnd_events->EnableWindow(false);
cwnd_remark->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancellation->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 COndutyRecord::OnAdd()
{
m_watcher = _T("");
m_beginDate = COleDateTime::GetCurrentTime();
m_endDate = COleDateTime::GetCurrentTime();
m_beginTime = COleDateTime::GetCurrentTime();
m_endTime = COleDateTime::GetCurrentTime();;
m_duty = _T("");
m_events = _T("");
m_remark = _T("");
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(true);
cwnd_beginDate->EnableWindow(true);
cwnd_endDate->EnableWindow(true);
cwnd_beginTime->EnableWindow(true);
cwnd_endTime->EnableWindow(true);
cwnd_duty->EnableWindow(true);
cwnd_events->EnableWindow(true);
cwnd_remark->EnableWindow(true);
cwnd_add->EnableWindow(false);
cwnd_cancellation->EnableWindow(true);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(true);
cwnd_exit->EnableWindow(false);
flag=1;
UpdateData(false);
}
void COndutyRecord::OnDelete()
{
COnduty onduty;
onduty.sqlDelete(m_beginDate);
m_watcher = _T("");
m_beginDate = COleDateTime::GetCurrentTime();
m_endDate = COleDateTime::GetCurrentTime();
m_beginTime = COleDateTime::GetCurrentTime();
m_endTime = COleDateTime::GetCurrentTime();;
m_duty = _T("");
m_events = _T("");
m_remark = _T("");
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(false);
cwnd_beginDate->EnableWindow(false);
cwnd_endDate->EnableWindow(false);
cwnd_beginTime->EnableWindow(false);
cwnd_endTime->EnableWindow(false);
cwnd_duty->EnableWindow(false);
cwnd_events->EnableWindow(false);
cwnd_remark->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancellation->EnableWindow(false);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
Refresh();
UpdateData(false);
}
void COndutyRecord::OnModify()
{
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(true);
cwnd_beginDate->EnableWindow(false);
cwnd_endDate->EnableWindow(true);
cwnd_beginTime->EnableWindow(true);
cwnd_endTime->EnableWindow(true);
cwnd_duty->EnableWindow(true);
cwnd_events->EnableWindow(true);
cwnd_remark->EnableWindow(true);
cwnd_add->EnableWindow(false);
cwnd_cancellation->EnableWindow(true);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(true);
cwnd_exit->EnableWindow(true);
flag=2;
UpdateData(false);
}
void COndutyRecord::OnSave()
{
UpdateData(true);
if(flag==1)
{
COnduty onduty;
onduty.SetBeginDate(m_beginDate);
onduty.SetBeginTime(m_beginTime);
onduty.SetEndDate(m_endDate);
onduty.SetEndTime(m_endTime);
onduty.SetWatcher(m_watcher);
onduty.SetEvents(m_events);
onduty.SetRemark(m_remark);
onduty.SetDuty(m_duty);
onduty.sqlInsert();
}
else if(flag==2)
{
COnduty onduty;
// onduty.SetBeginDate(m_beginDate);
onduty.SetBeginTime(m_beginTime);
onduty.SetEndDate(m_endDate);
onduty.SetEndTime(m_endTime);
onduty.SetDuty(m_duty);
onduty.SetWatcher(m_watcher);
onduty.SetEvents(m_events);
onduty.SetRemark(m_remark);
onduty.sqlUpdate(m_beginDate);
}
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(false);
cwnd_beginDate->EnableWindow(false);
cwnd_endDate->EnableWindow(false);
cwnd_beginTime->EnableWindow(false);
cwnd_endTime->EnableWindow(false);
cwnd_duty->EnableWindow(false);
cwnd_events->EnableWindow(false);
cwnd_remark->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancellation->EnableWindow(false);
cwnd_delete->EnableWindow(true);
cwnd_modify->EnableWindow(true);
cwnd_save->EnableWindow(true);
cwnd_exit->EnableWindow(true);
flag=0;
Refresh();
UpdateData(false);
}
void COndutyRecord::OnCancellation()
{
m_watcher = _T("");
m_beginDate = COleDateTime::GetCurrentTime();
m_endDate = COleDateTime::GetCurrentTime();
m_beginTime = COleDateTime::GetCurrentTime();
m_endTime = COleDateTime::GetCurrentTime();;
m_duty = _T("");
m_events = _T("");
m_remark = _T("");
cwnd_list->EnableWindow(true);
cwnd_watcher->EnableWindow(false);
cwnd_beginDate->EnableWindow(false);
cwnd_endDate->EnableWindow(false);
cwnd_beginTime->EnableWindow(false);
cwnd_endTime->EnableWindow(false);
cwnd_duty->EnableWindow(false);
cwnd_events->EnableWindow(false);
cwnd_remark->EnableWindow(false);
cwnd_add->EnableWindow(true);
cwnd_cancellation->EnableWindow(false);
cwnd_delete->EnableWindow(false);
cwnd_modify->EnableWindow(false);
cwnd_save->EnableWindow(false);
cwnd_exit->EnableWindow(true);
flag=0;
UpdateData(false);
}
void COndutyRecord::OnExit()
{
this->OnCancel();
}
void COndutyRecord::Refresh()
{
m_list.DeleteAllItems();
_RecordsetPtr m_pRecordset;
CString strSQL;
strSQL="select * from ondutyRecord";
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("beginDate")));
m_list.SetItemText(i,1,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("beginTime")));
m_list.SetItemText(i,2,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("watcher")));
m_list.SetItemText(i,3,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("duty")));
m_list.SetItemText(i,4,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("events")));
i++;
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -