// Liset.cpp : implementation file
//
#include "stdafx.h"
#include "myapp.h"
#include "Liset.h"
#include "ReceivedataSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CLiset dialog
CLiset::CLiset(CWnd* pParent /*=NULL*/)
: CDialog(CLiset::IDD, pParent)
{
//{{AFX_DATA_INIT(CLiset)
//}}AFX_DATA_INIT
}
void CLiset::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLiset)
DDX_Control(pDX, IDC_TREE1, m_treectrl);
DDX_Control(pDX, IDC_LIST1, m_listctrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLiset, CDialog)
//{{AFX_MSG_MAP(CLiset)
ON_WM_PAINT()
ON_WM_TIMER()
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CLiset message handlers
BOOL CLiset::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strHeader[8] = {"ID","PID","COUNT","VAL1","VAL2","VAL3","VAL4","VAL5"};
int nLong[8] ={60,60,75,70,70,70,70,70};
for(int nCol = 0;nCol<8;nCol++)
m_listctrl.InsertColumn(nCol,strHeader[nCol],LVCFMT_CENTER,nLong[nCol]);
// CHeaderCtrl * pHeader=m_listctrl.GetHeaderCtrl();
// pHeader->ModifyStyle(0, LVS_OWNERDRAWFIXED , TRUE);// CCS_NORESIZE
SetTimer(5,30000,NULL);
// ListId();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
HTREEITEM CLiset::FindTreeItem(HTREEITEM hParent, CString str)
{
HTREEITEM hNext;
CString strItem;
hNext = m_treectrl.GetChildItem(hParent);
while(hNext != NULL)
{
strItem = m_treectrl.GetItemText(hNext);
if(strItem == str)
return hNext;
else
hNext = m_treectrl.GetNextItem(hNext,TVGN_NEXT);
}
return NULL;
}
void CLiset::DispList(CString strFilter,int id)
{
m_listctrl.DeleteAllItems(); //删除所有表项
CReceivedataSet dpSet;
dpSet.m_strFilter = strFilter;
dpSet.Open();
int nItem = 0;
CString dpstr;
// dpSet.MoveFirst();
int count = 0;
dpSet.MoveLast();
//while(!dpSet.IsEOF())
while(!dpSet.IsBOF())
{
dpstr.Format("%d",dpSet.m_ID);
m_listctrl.InsertItem(nItem,dpstr);
dpstr.Format("%d",dpSet.m_PID);
m_listctrl.SetItemText(nItem,1,dpstr);
dpstr.Format("%d",dpSet.m_COUNTER);
m_listctrl.SetItemText(nItem,2,dpstr);
dpstr.Format("%d",dpSet.m_VALUE1);
m_listctrl.SetItemText(nItem,3,dpstr);
dpstr.Format("%d",dpSet.m_VALUE2);
m_listctrl.SetItemText(nItem,4,dpstr);
dpstr.Format("%d",dpSet.m_VALUE3);
m_listctrl.SetItemText(nItem,5,dpstr);
dpstr.Format("%d",dpSet.m_VALUE4);
m_listctrl.SetItemText(nItem,6,dpstr);
dpstr.Format("%d",dpSet.m_VALUE5);
m_listctrl.SetItemText(nItem,7,dpstr);
count++;
// dpSet.MoveNext();
dpSet.MovePrev();
}
dpSet.Close();
dpstr.Format("节点%d记录一共%d条",id,count);
GetDlgItem(IDC_STATIC_LIST)->SetWindowText(dpstr);
}
void CLiset::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CLiset::ListId()
{
HTREEITEM hRoot,hChild;
CString str;
hRoot = m_treectrl.InsertItem("ID",0,1);
CReceivedataSet lSet;
lSet.Open();
lSet.MoveFirst();
while(!lSet.IsEOF())
{
// if(lSet.m_ID == 0)
// lSet.Delete();
// else
// {
str.Format("%d",lSet.m_ID);
hChild = FindTreeItem(hRoot,str);
if(hChild == NULL)
hChild = m_treectrl.InsertItem(str,0,1,hRoot);
lSet.MoveNext();
// }
}
lSet.Close();
}
void CLiset::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 5)
{
m_treectrl.DeleteAllItems();
ListId();
}
CDialog::OnTimer(nIDEvent);
}
void CLiset::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
HTREEITEM hSelItem = pNMTreeView->itemNew.hItem;
if(m_treectrl.GetChildItem(hSelItem) == NULL)
{
CString strSelItem,str;
strSelItem =m_treectrl.GetItemText(hSelItem);
int temp;
temp =atoi(strSelItem.GetBuffer(strSelItem.GetLength())); //cstring转换成int型
str.Format("ID LIKE %d",temp);
DispList(str,temp);
}
*pResult = 0;
}