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

📄 result_show.cpp

📁 匿名通信代码
💻 CPP
字号:
// result_show.cpp : implementation file
//

#include "stdafx.h"
#include "afxwin.h"
#include "file_handle.h"
#include "result_show.h"
#include "database_show.h"
#include "resource.h"
#include "info_show.h"

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

/////////////////////////////////////////////////////////////////////////////
// result_show dialog


result_show::result_show(CWnd* pParent /*=NULL*/)
	: CDialog(result_show::IDD, pParent)
{
	//{{AFX_DATA_INIT(result_show)
	//}}AFX_DATA_INIT
}


void result_show::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(result_show)
	DDX_Control(pDX, IDC_LIST2, m_result_list);
	DDX_Control(pDX, IDC_STATIC1, m_mainboard);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(result_show, CDialog)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(result_show)
	ON_WM_PAINT()
	ON_COMMAND(ID_INFO_SHOW, OnInfoShow)
	ON_NOTIFY(NM_RCLICK, IDC_LIST2, OnRclickList2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// result_show message handlers

BOOL result_show::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	DWORD dwStyle = m_result_list.GetExtendedStyle();
    dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
    dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
    //dwStyle |= LVS_EX_CHECKBOXES;//item前生成checkbox控件
    m_result_list.SetExtendedStyle(dwStyle); //设置扩展风格

	m_result_list.InsertColumn(0, "序号", LVCFMT_LEFT, 45 );//插入列
	m_result_list.InsertColumn(1, "主机1", LVCFMT_LEFT, 120 );
    m_result_list.InsertColumn(2, "区域号", LVCFMT_LEFT,  70);
	m_result_list.InsertColumn(3, "主机2", LVCFMT_LEFT, 120);
	m_result_list.InsertColumn(4, "区域号", LVCFMT_LEFT, 70);
	m_result_list.InsertColumn(5, "通信次数", LVCFMT_LEFT, 80 );

	database_show r_list;
	r_list.DBConnect();
	CDBVariant varValue;

	CRecordset rs(&r_list.m_db);
	rs.Open(CRecordset::dynaset,"select * from location where sign = '1'");
	
	struct node *L = new node;
	L->next = NULL;
	CString srcip,dstip;
	int zone1,zone2;
	int temp = 0;
	
	if(rs.GetRecordCount()!=0)
	{
		rs.MoveFirst();		
	}
	else
	{
		rs.Close();
		return true;
	}
	while(!rs.IsEOF())
	{	
		rs.GetFieldValue(temp,varValue);
		srcip = varValue.m_pstring->GetBuffer(1);
		
		rs.GetFieldValue(1,varValue);
		zone1 = varValue.m_chVal;
		
		rs.GetFieldValue(3,varValue);
		dstip = varValue.m_pstring->GetBuffer(1);
		
		rs.GetFieldValue(4,varValue);
		zone2 = varValue.m_chVal;
		
		bool same = false;
		struct node *M = L->next;
		while(M != NULL)
		{
			if(((M->srcip == srcip)&&(M->zone1 == zone1)&&(M->dstip == dstip)&&(M->zone2 == zone2)) || ((M->srcip == dstip)&&(M->zone1 == zone2)&&(M->dstip == srcip)&&(M->zone2 == zone1)))
			{
				M->count = M->count +1;
				same = true;
				break;
			}
			else
				M = M ->next;
		}
		
		if(!same)
		{
			struct node *N = new node;
			N->srcip = srcip;
			N->dstip = dstip;
			N->zone1 = zone1;
			N->zone2 = zone2;
			N->count = 1;
			
			N->next = L->next;
			L->next = N;
		}
		
		rs.MoveNext();		
	}
	rs.Close();
	r_list.m_db.Close();

	//显示结果
	struct node *p = L->next;
	int nRow=0,no=1;
    char nostr[3],pzone1[2],pzone2[2],pcount[3];
	while(p != NULL)
	{
		sprintf(nostr,"%d",no++);
		m_result_list.InsertItem(nRow,nostr);
        m_result_list.SetItemText(nRow,1,(LPSTR)(LPCTSTR)p->srcip);
        m_result_list.SetItemText(nRow,2,itoa(p->zone1,pzone1,10));
		m_result_list.SetItemText(nRow,3,(LPSTR)(LPCTSTR)p->dstip);
		m_result_list.SetItemText(nRow,4,itoa(p->zone2,pzone2,10));
		m_result_list.SetItemText(nRow,5,itoa(p->count/2,pcount,10));

		nRow++;
		p = p->next;
	}

	//释放链表
	while(L->next != NULL)
	{
		struct node *temp = L->next;
		L->next = L->next->next;
		delete temp;
	}
	delete L;
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void result_show::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here

	CDC *pdc = m_mainboard.GetDC();
	CRect rc ;
	m_mainboard.GetClientRect(&rc);


	CPen pen,*oldpen;
	pen.CreatePen(PS_SOLID,2,RGB(255,0,0));
	oldpen = pdc->SelectObject(&pen);
	pdc->MoveTo(rc.left-8,rc.top);
	pdc->LineTo(rc.right,rc.bottom);
	pdc->SelectObject(oldpen);

	m_mainboard.ReleaseDC(pdc);
	
	// Do not call CDialog::OnPaint() for painting messages
}

void result_show::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_RESULT_SHOW));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}

void result_show::OnInfoShow() 
{
	// TODO: Add your command handler code here

    //判断有无选中的项,而且唯一,取得查询条件
	CString str[4];
	CString sqlstr;
	int j = 0,index[50];
	for(int i=0; i<m_result_list.GetItemCount(); i++)
	{
		if( m_result_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED )
		{
			index[j] = i;
			j++;
		}
	}

	if(j != 1)
	{
		AfxMessageBox("请选择一行数据");
		return;
	}

	str[0] = m_result_list.GetItemText(index[0],1);
    str[1] = m_result_list.GetItemText(index[0],2);
	str[2] = m_result_list.GetItemText(index[0],3);
	str[3] = m_result_list.GetItemText(index[0],4);
	//sqlstr.Format("select * from location where ip1 = '%s'and zone1='%s'and ip2='%s' and zone2='%s' or ip1 = '%s'and zone1='%s'and ip2='%s' and zone2='%s'",str[0],str[1],str[2],str[3],str[2],str[3],str[0],str[1]);
	sqlstr.Format("select * from location where sign = '1' and ip1 = '%s'and zone1='%s'and ip2='%s' and zone2='%s'",str[0],str[1],str[2],str[3]);
	
	//弹出新对话框显示具体通信信息
	info_show *dlg = new info_show;
    dlg->transe(sqlstr);
	dlg->Create(IDD_DIALOG4);
	dlg->ShowWindow(SW_RESTORE);
}

void result_show::OnRclickList2(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	/*NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	if(pNMListView->iItem != -1)
	{
		DWORD dwPos = GetMessagePos();
		CPoint point( LOWORD(dwPos), HIWORD(dwPos) );
		
		CMenu menu;
		VERIFY( menu.LoadMenu( CG_IDR_POPUP_RESULT_SHOW ) );
		CMenu* popup = menu.GetSubMenu(0);
		ASSERT( popup != NULL );
		popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this );
	} 

	//NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	if(pNMListView->iItem != -1)
	{
		CString strtemp;
		strtemp.Format("单击的是第%d行第%d列",pNMListView->iItem, pNMListView->iSubItem);
		AfxMessageBox(strtemp);
	}*/

	*pResult = 0;
}

⌨️ 快捷键说明

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