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

📄 flowreport.cpp

📁 本程序使用Visual C++6.0编写
💻 CPP
字号:
// FlowReport.cpp : implementation file
//

#include "stdafx.h"
#include "sjsys.h"
#include "FlowReport.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFlowReport dialog


CFlowReport::CFlowReport(CWnd* pParent /*=NULL*/)
	: CDialog(CFlowReport::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFlowReport)
	m_Begintime = COleDateTime::GetCurrentTime();
	m_Endtime = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
}


void CFlowReport::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFlowReport)
	DDX_Control(pDX, IDB_INQUIRE, m_inquire);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_Begintime);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_Endtime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFlowReport, CDialog)
	//{{AFX_MSG_MAP(CFlowReport)
	ON_BN_CLICKED(IDB_INQUIRE, OnInquire)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFlowReport message handlers

void CFlowReport::OnInquire() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);//将对话框数据更新到变量
	HRESULT hTRes;
	CString strSQL;
	m_list.DeleteAllItems();//清空列表框
	m_list.SetRedraw(FALSE);
	strSQL="select TotalFlow.Deviceid,Device.Devicename as IP,TotalFlow.Datetime,TotalFlow.TotalInFlow,TotalFlow.TotalOutFlow from Device,TotalFlow where Device.ID=TotalFlow.Deviceid";//构造查询语句
	if(TimeToString(m_Begintime)!="")//开始日期
	{
		strSQL=strSQL+" and TotalFlow.Datetime>='"+TimeToString(m_Begintime)+"'";
	}
	else
	{
		MessageBox("开始时间不能为空");
		return;
	}
	if(TimeToString(m_Endtime)!="")//结束日期
	{
		strSQL=strSQL+" and TotalFlow.Datetime<'"+TimeToString(m_Endtime)+"'";
	}
	strSQL=strSQL+"order by TotalFlow.TotalInFlow desc";
   	_RecordsetPtr m_pRecordset;

   	try
	{
		hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
		if (SUCCEEDED(hTRes))
		{
			hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
			if(SUCCEEDED(hTRes))
			{
				//将查询结果插入列表框控件中
				int i=0;
	        	int nItem=0;
				while(!(m_pRecordset->adoEOF))
				{
					nItem=m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));//产品编号
					m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("IP")));	//产品名称			
					m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("TotalInFlow"))); //规格
					m_list.SetItemText(nItem,3,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("TotalOutFlow"))); //型号
					
					m_pRecordset->MoveNext();
					i++;
				}
			}
		}
	}	
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
		MessageBox("创建记录集失败!","错误");
	}
	m_pRecordset->Close();
	m_list.SetRedraw(TRUE);
	UpdateData(false);//更新对话框数据
}

BOOL CFlowReport::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
    m_inquire.SetShade(CShadeButtonST::SHS_HSHADE);
	RECT rect;
	int width=0;
	m_list.GetWindowRect(&rect);
	width=rect.right-rect.left;
	m_list.SetExtendedStyle(WS_CHILD|WS_CLIPSIBLINGS|WS_EX_TOOLWINDOW|WS_BORDER|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

	m_list.InsertColumn(0,"员工",LVCFMT_LEFT,width/4);
	m_list.InsertColumn(1,"IP地址",LVCFMT_LEFT,width/4);
	m_list.InsertColumn(2,"总输入流量(G)",LVCFMT_LEFT,width/4);
	m_list.InsertColumn(3,"总输出流量(G)",LVCFMT_LEFT,width/4);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
CString CFlowReport::TimeToString(COleDateTime ct)
{
    CString str;
	str.Format("%d-%d-%d ",ct.GetYear(),ct.GetMonth(),ct.GetDay());
	return str;
}

⌨️ 快捷键说明

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