📄 sjsysview.cpp
字号:
// SjsysView.cpp : implementation of the CSjsysView class
//
#include "stdafx.h"
#include "Sjsys.h"
#include "LeftTreeView.h"
#include "SjsysDoc.h"
#include "CntrItem.h"
#include "MainFrm.h"
#include "SjsysView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSjsysView
IMPLEMENT_DYNCREATE(CSjsysView, CRichEditView)
BEGIN_MESSAGE_MAP(CSjsysView, CRichEditView)
//{{AFX_MSG_MAP(CSjsysView)
ON_WM_DESTROY()
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSjsysView construction/destruction
CSjsysView::CSjsysView()
{
// TODO: add construction code here
CurrentDeviceID=-1;
CurrentDetailID=-1;
}
CSjsysView::~CSjsysView()
{
}
BOOL CSjsysView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRichEditView::PreCreateWindow(cs);
}
void CSjsysView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
//CRichEditView::setrea
::CoInitialize(NULL);
pDetailRecordset.CreateInstance(__uuidof(Recordset));
pFlowRecordset.CreateInstance(__uuidof(Recordset));
SetTimer(1,10000,NULL); //设置上网记录的刷新时间为10000ms(10s)
SetTimer(2,600000,NULL); //设置上网记录的刷新时间为600s(10m)
//SetTimer(3,2000,NULL);
// Set the printing margins (720 twips = 1/2 inch).
SetMargins(CRect(720, 720, 720, 720));
}
/////////////////////////////////////////////////////////////////////////////
// CSjsysView printing
BOOL CSjsysView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSjsysView::OnDestroy()
{
// Deactivate the item on destruction; this is important
// when a splitter view is being used.
KillTimer(1);
KillTimer(2);
CRichEditView::OnDestroy();
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}
/////////////////////////////////////////////////////////////////////////////
// CSjsysView diagnostics
#ifdef _DEBUG
void CSjsysView::AssertValid() const
{
CRichEditView::AssertValid();
}
void CSjsysView::Dump(CDumpContext& dc) const
{
CRichEditView::Dump(dc);
}
CSjsysDoc* CSjsysView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSjsysDoc)));
return (CSjsysDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSjsysView message handlers
void CSjsysView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
if(pHint==NULL)
return;
UpdateDetail();
UpdateFlow();
}
void CSjsysView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//AfxMessageBox("here!");
switch(nIDEvent)
{
case 1:
{
UpdateDetail();
CRichEditCtrl &m_edit=GetRichEditCtrl();
if(m_edit.GetLineCount()>=35) //如果文本显示满屏,则清屏
{
m_edit.SetSel(0, -1); //选中当前所有文本
m_edit.Clear();
}
break;
}
case 2:
{
CLeftTreeView *p_TreeView;
CSjsysDoc *m_pDoc=(CSjsysDoc *)((CMainFrame *)
AfxGetApp()->m_pMainWnd)->GetActiveDocument();
POSITION pos=m_pDoc->GetFirstViewPosition();
while (pos!=NULL)
{
CView *pView= m_pDoc->GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CLeftTreeView)))
p_TreeView=(CLeftTreeView *)pView;
}
p_TreeView->UpdateTree();
break;
}
}
CRichEditView::OnTimer(nIDEvent);
}
void CSjsysView::UpdateDetail()
{
//首先通过遍历得到CLeftTreeView的p_TreeView对象
CLeftTreeView *p_TreeView;
CSjsysDoc *m_pDoc=(CSjsysDoc *)((CMainFrame *)
AfxGetApp()->m_pMainWnd)->GetActiveDocument();
POSITION pos=m_pDoc->GetFirstViewPosition();
while (pos!=NULL)
{
CView *pView= m_pDoc->GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CLeftTreeView)))
p_TreeView=(CLeftTreeView *)pView;
}
CTreeCtrl &m_tree=p_TreeView->GetTreeCtrl();
HTREEITEM hSel=m_tree.GetSelectedItem();
CString DeviceName=m_tree.GetItemText(hSel);
CRichEditCtrl &m_edit=GetRichEditCtrl();
m_edit.SetReadOnly(TRUE);
CString SQLStr;
SQLStr.Format("select * from Department where Cname='%s'",DeviceName);
//打开数据集
pDetailRecordset->Open(_bstr_t(SQLStr),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(pDetailRecordset->adoEOF) //如果选中的是设备
{
pDetailRecordset->Close();
if(m_tree.GetChildItem(hSel)==NULL)
{
try
{
SQLStr.Format("select * from Netconnectdetail where ID>%d and Deviceid in (select ID from Device where Devicename='%s')",CurrentDetailID,DeviceName);
//打开数据集
pDetailRecordset->Open(_bstr_t(SQLStr),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
/*if(pDetailRecordset->adoEOF) //如果数据库中无此记录
{
CString str;
str.Format("对不起,系统未查找到%s符合条件的上网记录!",DeviceName); //要写的内容
str += "\r\n"; //加入换行
int nTextLength = m_edit.GetWindowTextLength(); //获得文字的长度
m_edit.SetSel(nTextLength, nTextLength); //将光标放在文本最末
CHARFORMAT cf;
//ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize=sizeof(CHARFORMAT);
cf.dwMask=CFM_BOLD | CFM_COLOR | CFM_FACE |
CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
cf.dwEffects=0;
cf.crTextColor=RGB(255, 0, 0);
//m_edit.SetSel(1, 5); //设置处理区域
m_edit.SetSelectionCharFormat(cf);
m_edit.ReplaceSel(str); //写入文本
}*/
CString time;
CString name;
CString description;
CString status;
CString record;
CString m_detail=""; //所有上网信息容器
_variant_t var;
while(!pDetailRecordset->adoEOF)
{
var = pDetailRecordset->GetCollect("ID");
if(var.vt != VT_NULL)
{
CurrentDetailID=atoi((LPCSTR)_bstr_t(var));
}
else
{
continue;
}
/*var = pDetailRecordset->GetCollect("Devicename");
if(var.vt != VT_NULL)
{
devicename=(LPCSTR)_bstr_t(var);
}
else
{
continue;
}*/
//AfxMessageBox("here!");
var = pDetailRecordset->GetCollect("DateTime");
if(var.vt != VT_NULL)
{
time=(LPCSTR)_bstr_t(var);
}
else
{
continue;
}
var = pDetailRecordset->GetCollect("Descr");
if(var.vt != VT_NULL)
{
description=(LPCSTR)_bstr_t(var);
}
else
{
description="";
}
var = pDetailRecordset->GetCollect("Name");
if(var.vt != VT_NULL)
{
name=(LPCSTR)_bstr_t(var);
}
else
{
continue;
}
var = pDetailRecordset->GetCollect("Status");
if(var.vt != VT_NULL)
{
status=(LPCSTR)_bstr_t(var);
}
else
{
continue;
}
if(status=="1")
{
record.Format(" >> 设备[%s] %s 通过 %s %s",DeviceName,time,name,description);
}
else
{
record.Format(" >> 设备[%s] %s 禁止 %s %s",DeviceName,time,name,description);
}
m_detail+=record;
m_detail+="\r\n";
pDetailRecordset->MoveNext();
}
pDetailRecordset->Close();
m_edit.ReplaceSel(m_detail);
UpdateData(false);
m_edit.LineScroll(m_edit.GetLineCount());
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
}
}
else
pDetailRecordset->Close();
}
void CSjsysView::UpdateFlow()
{
//首先通过遍历得到CLeftTreeView的p_TreeView对象
CLeftTreeView *p_TreeView;
CSjsysDoc *m_pDoc=(CSjsysDoc *)((CMainFrame *)
AfxGetApp()->m_pMainWnd)->GetActiveDocument();
POSITION pos=m_pDoc->GetFirstViewPosition();
while (pos!=NULL)
{
CView *pView= m_pDoc->GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CLeftTreeView)))
p_TreeView=(CLeftTreeView *)pView;
}
CTreeCtrl &m_tree=p_TreeView->GetTreeCtrl();
HTREEITEM hSel=m_tree.GetSelectedItem();
//得到当前选中设备ID
CurrentDeviceID=m_tree.GetItemData(hSel);
CString value;
int intFlow;
double doubleFlow;
CString temp1,temp2;
//如果当前选中的是设备项
if(m_tree.GetChildItem(hSel)==NULL)
{
try
{
//打开数据集
CString SQLStr;
SQLStr.Format("select * from Device where ID=%d",CurrentDeviceID);
_variant_t var;
pFlowRecordset->Open(_bstr_t(SQLStr),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
while(!pFlowRecordset->adoEOF)
{
var = pFlowRecordset->GetCollect("RealOutFlow");
if(var.vt != VT_NULL)
{
intFlow=atoi((LPCSTR)_bstr_t(var));
doubleFlow=(double)intFlow/1000;
temp1.Format("输出流量:%0.2f kb/s",doubleFlow);
}
var = pFlowRecordset->GetCollect("RealInFlow");
if(var.vt != VT_NULL)
{
intFlow=atoi((LPCSTR)_bstr_t(var));
doubleFlow=(double)intFlow/1000;
temp2.Format("输入流量:%0.2f kb/s",doubleFlow);
}
m_flow=temp1+","+temp2;
break;
}
pFlowRecordset->Close();
UpdateData(false);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
//先获得主窗口指针,再获得状态栏指针
CStatusBar *pStatus=(CStatusBar *)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR);
if(pStatus)
{
//显示流量在状态栏中
//MessageBox("here!");
pStatus->SetPaneInfo(1, ID_VIEW_STATUS_BAR,SBPS_NOBORDERS , 235);
pStatus->SetPaneText(1,m_flow);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -