TreeForGrpSend.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:9k
- // TreeForGrpSend.cpp : implementation file
- #include "stdafx.h"
- #include "trfAgent.h"
- #include "variantex.h"
- #include "TreeForGrpSend.h"
- /////////////////////////////////////////////////////////////////////////////
- CTreeForGrpSend::CTreeForGrpSend()
- {
- }
- CTreeForGrpSend::~CTreeForGrpSend()
- {
- }
- BEGIN_MESSAGE_MAP(CTreeForGrpSend, CTreeCtrl)
- //{{AFX_MSG_MAP(CTreeForGrpSend)
- ON_WM_CREATE()
- ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- //////////////////////////////////////////////////////////////////////////
- int CTreeForGrpSend::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- lpCreateStruct->style |= TVS_SHOWSELALWAYS;
- lpCreateStruct->style |= TVS_DISABLEDRAGDROP;
- if (CTreeCtrl::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if(!this->m_imgTree.Create(IDB_WORKSPACE, 16, 3, RGB(255, 255, 255)))
- {
- TRACE0("Failed to create the m_imgTree for historyn");
- return -1;
- }
- this->SetImageList(&m_imgTree, TVSIL_NORMAL);
-
- return 0;
- }
- //add group node.
- BOOL CTreeForGrpSend::AddGroup(const char *lpszGroupName)
- {
- CGuiRecordSet rs;
- CVariantEx varex;
- char sql[MAX_SQL_SIZE];
- try
- {
- int groupid = 1;
- //////////////////////////////////////////////////////////////////////////
-
- //get new group id.
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_GRPSND_GETCNTOFSNDGRP);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- return FALSE;
- }
- rs.GetCollect("SNDGRPCNT", varex.get_variant_t());
- rs.Close();
- if(varex.AsInteger() != 0)
- {
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_GRPSND_GETNEXTSNDGRPID);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- return FALSE;
- }
- rs.GetCollect("NEXTID", varex.get_variant_t());
- rs.Close();
- groupid = varex.AsInteger();
- }
- //////////////////////////////////////////////////////////////////////////
-
- //insert group record into database.
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_GRPSND_ADDSNDGRP, groupid, lpszGroupName);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- return FALSE;
- }
- rs.Close();
-
- //////////////////////////////////////////////////////////////////////////
-
- HTREEITEM hitem = this->InsertItem(lpszGroupName, 0, 0);
-
- this->SetItemData(hitem, MAKELONG(groupid, NT_DEPART));
- this->SelectItem(hitem);
-
- //////////////////////////////////////////////////////////////////////////
- return TRUE;
- }
- catch (...)
- {
- return FALSE;
- }
- }
- //delete group node.
- BOOL CTreeForGrpSend::DelGroup(const int nGroupId)
- {
- CGuiRecordSet rs;
- char sql[MAX_SQL_SIZE];
-
- try
- {
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_GRPSND_DELSNDGRP, nGroupId);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- return FALSE;
- }
- rs.Close();
- return TRUE;
- }
- catch (...)
- {
- return FALSE;
- }
- }
- //rename group node.
- BOOL CTreeForGrpSend::RenameGroup(const int nGroupId, const char *lpszNewGroupName)
- {
- CGuiRecordSet rs;
- char sql[MAX_SQL_SIZE];
-
- try
- {
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_GRPSND_EDTSNDGRPNAME, nGroupId, lpszNewGroupName);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- return FALSE;
- }
- rs.Close();
- return TRUE;
- }
- catch (...)
- {
- return FALSE;
- }
- }
- //add one user under someone group item.
- BOOL CTreeForGrpSend::AddGroupUser(const int nGroupId, const int nGroupUserId)
- {
- CGuiRecordSet rs;
- char sql[MAX_SQL_SIZE];
- try
- {
- //insert send group user info.
-
- _snprintf(sql, MAX_SQL_SIZE - 1, SQL::CLIENT_GRPSNDUSR_ADDSNDGRPUSR, nGroupUserId, nGroupId);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return FALSE;
- }
- rs.Close();
- return TRUE;
- }
- catch (...)
- {
- return FALSE;
- }
- }
- //delete one user under someone group item.
- BOOL CTreeForGrpSend::DelGroupUser(const int nGroupId, const int nGroupUserId)
- {
- CGuiRecordSet rs;
- char sql[MAX_SQL_SIZE];
-
- try
- {
- //insert send group user info.
-
- _snprintf(sql, MAX_SQL_SIZE - 1, SQL::CLIENT_GRPSNDUSR_DELSNDGRPUSR, nGroupUserId, nGroupId);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return FALSE;
- }
- rs.Close();
-
- return TRUE;
- }
- catch (...)
- {
- return FALSE;
- }
- }
- //update user tree's data.
- void CTreeForGrpSend::UpdateTreeForUserDatas()
- {
- CGuiRecordSet rsd, rsu;
- DWORD olddata = 0;
- CVariantEx varex;
- char sql[MAX_SQL_SIZE];
- try
- {
- //find all first level departs' info
-
- _snprintf(sql, MAX_SQL_SIZE - 1, SQL::CLIENT_GRPSND_GETALLSNDGRPS);
- if(!rsd.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return ;
- }
-
- //enter departs looping
- this->DeleteAllItems();
-
- if(rsd.GetRecordCount() > 0)
- {
- for(rsd.MoveFirst(); !rsd.IsEof(); rsd.MoveNext())
- {
- //get depart.db table's field value.
- int departid = 0;
- string departname("");
-
- rsd.GetCollect("departid", varex.get_variant_t());
- departid = varex.AsInteger();
-
- rsd.GetCollect("departname", varex.get_variant_t());
- departname = varex.AsString();
-
- HTREEITEM departnode = this->InsertItem(departname.c_str(), 0, 0);
- this->SetItemData(departnode, MAKELONG(departid, NT_DEPART));
- //get all user list for specialed depart
-
- _snprintf(sql, MAX_SQL_SIZE - 1, SQL::CLIENT_GRPSND_GETUSRSOFSNDGRP, departid);
- if(!rsu.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return ;
- }
-
- //enter users looping
- if(rsu.GetRecordCount() > 0)
- {
- for(rsu.MoveFirst(); !rsu.IsEof(); rsu.MoveNext())
- {
- int userid = 0, state = 0, imgindex = 1;
- string username("");
-
- rsu.GetCollect("id", varex.get_variant_t());
- userid = varex.AsInteger();
-
- rsu.GetCollect("name", varex.get_variant_t());
- username = varex.AsString();
- HTREEITEM usernode = this->InsertItem(username.c_str(), 1, 1, departnode);
- this->SetItemData(usernode, MAKELONG(userid, NT_AGENT));
- }
- }
- rsu.Close();
- }
- }
- rsd.Close();
- }
- catch (_com_error e)
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED));
- return ;
- }
- }
- bool CTreeForGrpSend::GetAGInfoOfItem(HTREEITEM hitem, AGINFO &aginfo)
- {
- HTREEITEM hselected = hitem;
-
- if(NULL == hselected)
- {
- MSGBOX_INFO(_LoadString(IDS_NOSELECTNODE).GetBuffer(0));
- return false;
- }
- else
- {
- CGuiRecordSet rs;
- CVariantEx varex;
- CString stemp;
- char sql[MAX_SQL_SIZE];
-
- try
- {
- if(HIWORD(this->GetItemData(hselected)) == NT_AGENT)
- {
- WORD agentid = LOWORD(this->GetItemData(hselected));
-
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_GETSPECEAGENT_FROM_ID, agentid);
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return false;
- }
-
- if(rs.GetRecordCount() == 0) return false;
-
- rs.GetCollect("ipaddr", varex.get_variant_t());
- aginfo.shostip = varex.AsString();
-
- rs.GetCollect("hostname", varex.get_variant_t());
- aginfo.shostname = varex.AsString();
-
- rs.Close();
-
- return true;
- }
- else return false;
- }
- catch (_com_error e)
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return false;
- }
- }
- }
- void CTreeForGrpSend::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- *pResult = 0;
- HTREEITEM hitem = pNMTreeView->itemNew.hItem;
- if(hitem == NULL) return ;
- DWORD dwdata = this->GetItemData(hitem);
- if(HIWORD(dwdata) == NT_DEPART) return ;
- AGINFO aginfo;
-
- if(this->GetAGInfoOfItem(pNMTreeView->itemNew.hItem, aginfo))
- {
- CString stemp;
-
- stemp.Format("%s / %s", aginfo.shostname.c_str(), aginfo.shostip.c_str());
- char *puretxt = new char[stemp.GetLength()+1];
-
- _snprintf(puretxt, stemp.GetLength()+1, "%s", stemp.GetBuffer(0));
-
- stemp.Empty();
-
- ::SendMessage(theApp.m_pMainWnd->GetSafeHwnd(), UWM_UPDATESTATUSBAR, MAKEWORD(0, 1), (LPARAM)puretxt);
- }
- else
- {
- ::SendMessage(theApp.m_pMainWnd->GetSafeHwnd(), UWM_UPDATESTATUSBAR, MAKEWORD(0, 1), (LPARAM)NULL);
- }
- }