⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagesysevent.cpp

📁 人事管理系统
💻 CPP
字号:
// PageSysEvent.cpp : implementation file
//

#include "stdafx.h"
#include "PersonelManage.h"
#include "PageSysEvent.h"

#include "QuerySysEntDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPageSysEvent property page

IMPLEMENT_DYNCREATE(CPageSysEvent, CResizablePage)

CPageSysEvent::CPageSysEvent() : CResizablePage(CPageSysEvent::IDD)
{
	//{{AFX_DATA_INIT(CPageSysEvent)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_psp.dwFlags &= (~PSP_HASHELP);
	m_psp.dwFlags |= ( PSP_USEHICON );
	HICON hIconTab = AfxGetApp()->LoadIcon(IDI_PERSON);
	m_psp.hIcon = hIconTab;
}

CPageSysEvent::~CPageSysEvent()
{
}

void CPageSysEvent::DoDataExchange(CDataExchange* pDX)
{
	CResizablePage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageSysEvent)
	DDX_Control(pDX, IDC_LIST_SYSEVENT, m_ctrlSysEntList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageSysEvent, CResizablePage)
	//{{AFX_MSG_MAP(CPageSysEvent)
	ON_BN_CLICKED(IDC_BUTTON_QUERYEVENT, OnButtonQueryevent)
	ON_BN_CLICKED(IDC_BUTTON_SHOWALL, OnButtonShowall)
	ON_NOTIFY(NM_RCLICK, IDC_LIST_SYSEVENT, OnRclickListSysevent)
	ON_COMMAND(ID_SYSENT_SHOWALL, OnSysentShowall)
	ON_COMMAND(ID_SYSENT_QUERY, OnSysentQuery)
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
	ON_COMMAND(ID_SYSENT_DEL, OnSysentDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageSysEvent message handlers

void CPageSysEvent::OnButtonQueryevent() 
{
	// TODO: Add your control notification handler code here
	CQuerySysEntDlg querySysEnt;
	CString strEventID;
	CString strEventMessage;
	CString strEventTime;
	COleDateTime start(0, 0, 0, 0, 0, 0);
	COleDateTime end(0, 0, 0, 0, 0, 0);
	COleDateTime tmp;
	COleDateTimeSpan ts(1, 0, 0, 0);

	if(querySysEnt.DoModal() == IDOK)
	{
		tmp = querySysEnt.GetStartTime();
		start.SetDate(tmp.GetYear(), tmp.GetMonth(), tmp.GetDay());
		tmp = querySysEnt.GetEndTime();
		tmp += ts;
		end.SetDate(tmp.GetYear(), tmp.GetMonth(), tmp.GetDay());

		CADODatabase *pDb = new CADODatabase;
		try
		{
			if(pDb->Open())
			{
				CADORecordset *pRs = new CADORecordset(pDb);
				CADOParameter pParamStart(CADORecordset::typeDBDate, sizeof(COleDateTime), CADOParameter::paramInput);
				CADOParameter pParamEnd(CADORecordset::typeDBDate, sizeof(COleDateTime), CADOParameter::paramInput);
				pParamStart.SetValue(start);
				pParamEnd.SetValue(end);

				CADOCommand pCmd(pDb, "spwinQueryEventbyTime");
				pCmd.AddParameter(&pParamStart);
				pCmd.AddParameter(&pParamEnd);
				if(pRs->Execute(&pCmd))
				{
					if(pRs->GetRecordCount() > 0)
					{
						m_ctrlSysEntList.DeleteAllItems();
						int cur = 0;
						while(!pRs->IsEOF())
						{
							pRs->GetFieldValue("事件编号", strEventID);
							m_ctrlSysEntList.InsertItem(cur, strEventID, 0);
							pRs->GetFieldValue("事件信息", strEventMessage);
							m_ctrlSysEntList.SetItemText(cur, 1, strEventMessage);
							pRs->GetFieldValue("时间", strEventTime);
							m_ctrlSysEntList.SetItemText(cur, 2, strEventTime);

							cur++;
							pRs->MoveNext();
						}	
					}
					else
						AfxMessageBox("未查询到任何结果!");
					pRs->Close();
				}
				delete pRs;
				pDb->Close();
			}
			delete pDb;
		}
		catch(CADOException &e)
		{
			AfxMessageBox(e.GetErrorMessage());
		}
	}
	
}

BOOL CPageSysEvent::OnInitDialog() 
{
	CResizablePage::OnInitDialog();
	
	// TODO: Add extra initialization here
	AddAnchor(IDC_LIST_SYSEVENT, TOP_LEFT, BOTTOM_RIGHT);
	AddAnchor(IDC_BUTTON_QUERYEVENT, BOTTOM_RIGHT);
	AddAnchor(IDC_BUTTON_SHOWALL, BOTTOM_RIGHT);
	AddAnchor(IDC_BUTTON_DEL, BOTTOM_RIGHT);

	DWORD dwStyle = m_ctrlSysEntList.GetExtendedStyle();
	dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT;
	m_ctrlSysEntList.SetExtendedStyle(dwStyle);

	m_ctrlSysEntList.InsertColumn(0, "事件编号", LVCFMT_LEFT, 64);
	m_ctrlSysEntList.InsertColumn(1, "事件信息", LVCFMT_LEFT, 192);
	m_ctrlSysEntList.InsertColumn(2, "时间", LVCFMT_LEFT, 128);

	//填充数据
	GetSysEntList();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//查询数据库获得信息,填充列表
void CPageSysEvent::GetSysEntList()
{
	CString strQuery = "SELECT [EventID],[EventMessage],[EventTime] FROM [tblSystemEvent]";
	CString strEventID;
	CString strEventMessage;
	CString strEventTime;

	CString strConnection = _T("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BlueHill;Data Source=dragonflylong\\sqlexpress");
	CADODatabase *pDb = new CADODatabase;
	pDb->SetConnectionString(strConnection);
	try
	{
		if(pDb->Open())
		{
			CADORecordset *pRs = new CADORecordset(pDb);
			if(pRs->Open(strQuery, CADORecordset::openQuery))
			{
				m_ctrlSysEntList.DeleteAllItems();

				int cur = 0;
				while(!pRs->IsEOF())
				{
					pRs->GetFieldValue("EventID", strEventID);
					m_ctrlSysEntList.InsertItem(cur, strEventID, 0);
					pRs->GetFieldValue("EventMessage", strEventMessage);
					m_ctrlSysEntList.SetItemText(cur, 1, strEventMessage);
					pRs->GetFieldValue("EventTime", strEventTime);
					m_ctrlSysEntList.SetItemText(cur, 2, strEventTime);

					cur++;
					pRs->MoveNext();
				}
				pRs->Close();
			}
			delete pRs;
			pDb->Close();
		}
		delete pDb;
	}
	catch(CADOException)
	{
	}
}

void CPageSysEvent::OnButtonShowall() 
{
	// TODO: Add your control notification handler code here
	GetSysEntList();
	
}

void CPageSysEvent::OnRclickListSysevent(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CMenu menu, *pSubMenu;
	menu.LoadMenu(IDR_SYSENT_POPUP);
	pSubMenu = menu.GetSubMenu(0);
	CPoint curPoint;
	GetCursorPos(&curPoint);
	pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, curPoint.x, curPoint.y, this);
	
	*pResult = 0;
}

void CPageSysEvent::OnSysentShowall() 
{
	// TODO: Add your command handler code here
	GetSysEntList();
}

void CPageSysEvent::OnSysentQuery() 
{
	// TODO: Add your command handler code here
	OnButtonQueryevent();
}

void CPageSysEvent::OnButtonDel() 
{
	// TODO: Add your control notification handler code here
	int nItem = m_ctrlSysEntList.GetNextItem(-1, LVIS_SELECTED);
	if(nItem != -1)
	{
		if(AfxMessageBox("确定要删除这条记录吗?", MB_YESNO | MB_ICONSTOP) == IDNO)
			return;
		CString cmdText, entID;
		entID = m_ctrlSysEntList.GetItemText(nItem, 0);
		entID.TrimRight();
		cmdText.Format("DELETE FROM [tblSystemEvent] WHERE EventID = %s", entID);

		CADODatabase *pAdoDb = new CADODatabase();				
		if(pAdoDb->Open())
		{
			CADOCommand pCmd(pAdoDb, cmdText, CADOCommand::typeCmdText);
			if(pCmd.Execute(CADOCommand::typeCmdText))
			{
				m_ctrlSysEntList.DeleteItem(nItem);
				MessageBox("已成功删除记录!");
			}
		}
		pAdoDb->Close();
		delete pAdoDb;
	}
	else
		AfxMessageBox("请选择一条数据!");
	
}

void CPageSysEvent::OnSysentDel() 
{
	// TODO: Add your command handler code here
	OnButtonDel();
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -