SetNet.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:9k
开发平台:

Visual C++

  1. // SetNet.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Property.h"
  5. #include "SetNet.h"
  6. //onwer add
  7. #include "GuiRes.h"
  8. #include "NetIPAria.h"
  9. #include "NetTimeSheet.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. //=============================================================================================
  16. // CSetNet property page
  17. extern CAclFile m_AclFile;
  18. XACL_IP m_tmpIP;
  19. XACL_IP* m_pIP;
  20. CNetTimeSheet* mNetTimeSheet;
  21. CNetIPAria *dlgNetIPAria = NULL;
  22. IMPLEMENT_DYNCREATE(CSetNet, CPropertyPage)
  23. CSetNet::CSetNet() : CPropertyPage(CSetNet::IDD)
  24. {
  25. iListIndex = 0;
  26. iTreeIndex = 0;
  27. m_TreeText = GUI_SET_NET_TREE_0;
  28. }
  29. CSetNet::~CSetNet()
  30. {
  31. }
  32. void CSetNet::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CPropertyPage::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CSetNet)
  36. DDX_Control(pDX, IDC_SET_NET_TREE, m_TreeSetNet);
  37. DDX_Control(pDX, IDC_SET_NET_LIST, m_ListSetNet);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CSetNet, CPropertyPage)
  41. //{{AFX_MSG_MAP(CSetNet)
  42. ON_BN_CLICKED(IDC_SET_NET_BUTTON_ADD, OnSetNetButtonAdd)
  43. ON_NOTIFY(TVN_SELCHANGED, IDC_SET_NET_TREE, OnSelchangedSetNetTree)
  44. ON_NOTIFY(LVN_ITEMCHANGED, IDC_SET_NET_LIST,OnItemchangedSetNetList)
  45. ON_BN_CLICKED(IDC_SET_NET_BUTTON_EDIT, OnSetNetButtonEdit)
  46. ON_NOTIFY(NM_DBLCLK, IDC_SET_NET_LIST, OnDblclkSetNetList)
  47. ON_BN_CLICKED(IDC_SET_NET_BUTTON_DELETE, OnSetNetButtonDelete)
  48. ON_NOTIFY(NM_CLICK, IDC_SET_NET_LIST, OnClickSetNetList)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. //=============================================================================================
  52. // CSetNet message handlers
  53. BOOL CSetNet::OnInitDialog() 
  54. {
  55. CPropertyPage::OnInitDialog();
  56. InitDlgResource();
  57. mNetTimeSheet = (CNetTimeSheet*)this->GetOwner();
  58. return TRUE;  
  59. }
  60. //---------------------------------------------------------------------------------------------
  61. //initialize dialog's resource
  62. void CSetNet::InitDlgResource()
  63. {
  64. SetDlgItemText(IDC_SET_NET_NET_LABLE ,GUI_SET_NET_NET_LABLE);
  65. SetDlgItemText(IDC_SET_NET_BUTTON_ADD ,GUI_SET_NET_BUTTON_ADD);
  66. SetDlgItemText(IDC_SET_NET_BUTTON_EDIT ,GUI_SET_NET_BUTTON_EDIT);
  67. SetDlgItemText(IDC_SET_NET_BUTTON_DELETE,GUI_SET_NET_BUTTON_DELETE);
  68. m_TreeSetNet.InsertItem(GUI_SET_NET_TREE_0);
  69. m_TreeSetNet.InsertItem(GUI_SET_NET_TREE_1);
  70. m_TreeSetNet.InsertItem(GUI_SET_NET_TREE_2);
  71. m_TreeSetNet.InsertItem(GUI_SET_NET_TREE_3);
  72. m_TreeSetNet.InsertItem(GUI_SET_NET_TREE_4);
  73. InitList(&m_ListSetNet);
  74. SelectTreeItem(m_TreeText);
  75. }
  76. void CSetNet::InitList(CListCtrl *mList)
  77. {
  78. mList->SetExtendedStyle (LVS_EX_GRIDLINES  | LVS_EX_FULLROWSELECT);
  79. mList->InsertColumn (0, GUI_SET_NET_LIST_START_IP, LVCFMT_LEFT,143);
  80. mList->InsertColumn (1, GUI_SET_NET_LIST_END_IP , LVCFMT_LEFT,143);
  81. }
  82. void CSetNet::OnSelchangedSetNetTree(NMHDR* pNMHDR, LRESULT* pResult) 
  83. {
  84. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  85. SelectTreeItemOperate();
  86. *pResult = 0;
  87. }
  88. int CSetNet::SelectTreeItemOperate()
  89. {
  90. DWORD i = 0;
  91. CString sNetText= m_TreeSetNet.GetItemText(m_TreeSetNet.GetSelectedItem());
  92. iTreeIndex = NetTextToIndex(sNetText);
  93. m_ListSetNet.DeleteAllItems();
  94. switch(iTreeIndex)
  95. {
  96. case 0:
  97. EnableButton(FALSE);
  98. m_ListSetNet.InsertItem(0,GUI_NET_IP_ARIA_ALL);
  99. m_ListSetNet.SetItemText(0,1,GUI_NET_IP_ARIA_ALL);
  100. break;
  101. case 1:
  102. EnableButton(FALSE);
  103. ListAddIP(&m_AclFile.mAclIntranetIP, m_AclFile.mAclHeader.ulIntranetIPCount);
  104. break;
  105. case 2:
  106. EnableButton(TRUE);
  107. ListAddIP(m_AclFile.mpAclDistrustIP, m_AclFile.mAclHeader.ulDistrustIPCount);
  108. break;
  109. case 3:
  110. EnableButton(TRUE);
  111. ListAddIP(m_AclFile.mpAclTrustIP, m_AclFile.mAclHeader.ulTrustIPCount);
  112. break;
  113. case 4:
  114. EnableButton(TRUE);
  115. ListAddIP(m_AclFile.mpAclCustomIP, m_AclFile.mAclHeader.ulCustomIPCount);
  116. break;
  117. default:
  118. break;
  119. }
  120. m_ListSetNet.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  121. return 0;
  122. }
  123. int CSetNet::ListAddIP(void* mpAclIP,DWORD mCount)
  124. {
  125. DWORD i = 0;
  126. for(i = 0; i < mCount; i++)
  127. ListAddOneIP(i, mpAclIP);
  128. return 0;
  129. }
  130. int CSetNet::ListAddOneIP(DWORD iIndex, void* mpAclIP, BOOL isSelected)
  131. {
  132. XACL_IP *mAclIP = (XACL_IP*)mpAclIP;
  133. if(isSelected)
  134. {
  135. m_ListSetNet.InsertItem(iIndex, m_AclFile.DIPToSIP(&mAclIP->ulStartIP));
  136. m_ListSetNet.SetItemText(iIndex, 1, m_AclFile.DIPToSIP(&mAclIP->ulEndIP));
  137. m_ListSetNet.EnsureVisible(iIndex, TRUE);
  138. m_ListSetNet.SetItemState(iIndex, LVIS_SELECTED,LVIS_SELECTED);
  139. }
  140. else
  141. {
  142. m_ListSetNet.InsertItem(iIndex, m_AclFile.DIPToSIP(&mAclIP[iIndex].ulStartIP));
  143. m_ListSetNet.SetItemText(iIndex, 1, m_AclFile.DIPToSIP(&mAclIP[iIndex].ulEndIP));
  144. }
  145. return 0;
  146. }
  147. int CSetNet::EnableButton(BOOL bEnable,BOOL bEnableEx)
  148. {
  149. GetDlgItem(IDC_SET_NET_BUTTON_ADD) ->EnableWindow(bEnable);
  150. GetDlgItem(IDC_SET_NET_BUTTON_EDIT) ->EnableWindow(bEnableEx);
  151. GetDlgItem(IDC_SET_NET_BUTTON_DELETE) ->EnableWindow(bEnableEx);
  152. return 0;
  153. }
  154. int CSetNet::NetTextToIndex(CString sNetText)
  155. {
  156. if(sNetText.Compare(GUI_SET_NET_TREE_0) == 0) return 0;
  157. if(sNetText.Compare(GUI_SET_NET_TREE_1) == 0) return 1;
  158. if(sNetText.Compare(GUI_SET_NET_TREE_2) == 0) return 2;
  159. if(sNetText.Compare(GUI_SET_NET_TREE_3) == 0) return 3;
  160. if(sNetText.Compare(GUI_SET_NET_TREE_4) == 0) return 4;
  161. return -1;
  162. }
  163. int CSetNet::SelectTreeItem(CString sNetText)
  164. {
  165. int i = 0 , iItemCount = m_TreeSetNet.GetCount();
  166. HTREEITEM mItem = m_TreeSetNet.GetFirstVisibleItem();
  167. if(sNetText.Compare(m_TreeSetNet.GetItemText(mItem)) == 0)
  168. return i;
  169. for(i = 1; i < iItemCount; i++)
  170. {
  171. mItem = m_TreeSetNet.GetNextSiblingItem(mItem);
  172. if(sNetText.Compare(m_TreeSetNet.GetItemText(mItem)) == 0)
  173. {
  174. m_TreeSetNet.SelectItem(mItem);
  175. return i;
  176. }
  177. }
  178. return -1;
  179. }
  180. void CSetNet::OnItemchangedSetNetList(NMHDR* pNMHDR, LRESULT* pResult) 
  181. {
  182. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  183. *pResult = 0;
  184. if((iListIndex = pNMListView->iItem) == -1)
  185. return;
  186. if(iTreeIndex != 0 && iTreeIndex != 1)
  187. EnableButton(TRUE,TRUE);
  188. if(iTreeIndex == 2)
  189. m_pIP = &m_AclFile.mpAclDistrustIP[iListIndex];
  190. else if(iTreeIndex == 3)
  191. m_pIP = &m_AclFile.mpAclTrustIP[iListIndex];
  192. else if(iTreeIndex == 4)
  193. m_pIP = &m_AclFile.mpAclCustomIP[iListIndex];
  194. return;
  195. }
  196. void CSetNet::OnSetNetButtonAdd() 
  197. {
  198. if(!GetDlgItem(IDC_SET_NET_BUTTON_ADD)->IsWindowEnabled())
  199. return;
  200. if(MAX_IP_ARIA != 0 && m_ListSetNet.GetItemCount() >= MAX_IP_ARIA)
  201. {
  202. AfxMessageBox(GUI_ACL_MESSAGE_MAX_IP_ARIA);
  203. return;
  204. }
  205. dlgNetIPAria = new CNetIPAria;
  206. dlgNetIPAria->iState= 0; //add
  207. int iRet = dlgNetIPAria->DoModal();
  208. m_tmpIP.ulStartIP = dlgNetIPAria->ulStartIP;
  209. m_tmpIP.ulEndIP = dlgNetIPAria->ulEndIP;
  210. delete dlgNetIPAria;
  211. dlgNetIPAria = NULL;
  212. if(iRet == IDCANCEL)
  213. return;
  214. if(m_AclFile.AddAcl(&m_tmpIP,1,iTreeIndex) != XERR_SUCCESS)
  215. {
  216. AfxMessageBox(GUI_ACL_MESSAGE_ADD_ACL_IP_ERROR);
  217. return;
  218. }
  219. ListAddOneIP(m_ListSetNet.GetItemCount(),&m_tmpIP,TRUE);
  220. mNetTimeSheet->EnableButton(TRUE);
  221. }
  222. void CSetNet::OnSetNetButtonEdit() 
  223. {
  224. if(!GetDlgItem(IDC_SET_NET_BUTTON_EDIT)->IsWindowEnabled())
  225. return;
  226. if(iListIndex < 0)
  227. return;
  228. dlgNetIPAria = new CNetIPAria;
  229. dlgNetIPAria->iState = 1; //edit
  230. dlgNetIPAria->ulStartIP = m_pIP->ulStartIP ;
  231. dlgNetIPAria->ulEndIP = m_pIP->ulEndIP ;
  232. int iRet = dlgNetIPAria->DoModal();
  233. m_pIP->ulStartIP= dlgNetIPAria->ulStartIP;
  234. m_pIP->ulEndIP = dlgNetIPAria->ulEndIP;
  235. delete dlgNetIPAria;
  236. dlgNetIPAria = NULL;
  237. if(iRet == IDCANCEL)
  238. return;
  239. m_ListSetNet.SetItemText(iListIndex, 0, m_AclFile.DIPToSIP(&m_pIP->ulStartIP));
  240. m_ListSetNet.SetItemText(iListIndex, 1, m_AclFile.DIPToSIP(&m_pIP->ulEndIP));
  241. mNetTimeSheet->EnableButton(TRUE);
  242. }
  243. void CSetNet::OnDblclkSetNetList(NMHDR* pNMHDR, LRESULT* pResult) 
  244. {
  245. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  246. if((iListIndex = pNMListView->iItem) != -1)
  247. OnSetNetButtonEdit();
  248. *pResult = 0;
  249. }
  250. void CSetNet::OnSetNetButtonDelete() 
  251. {
  252. if(iListIndex < 0)
  253. return;
  254. int tmpIndex = iListIndex;
  255. m_AclFile .DelAcl(iListIndex, iTreeIndex);
  256. m_ListSetNet.DeleteItem(iListIndex);
  257. mNetTimeSheet->EnableButton(TRUE);
  258. if(m_ListSetNet.GetItemCount() <= 0)
  259. {
  260. EnableButton(TRUE,FALSE);
  261. return;
  262. }
  263. if(tmpIndex == m_ListSetNet.GetItemCount())
  264. tmpIndex -- ;
  265. m_ListSetNet.SetItemState(tmpIndex,LVIS_SELECTED,LVIS_SELECTED);
  266. }
  267. void CSetNet::OnClickSetNetList(NMHDR* pNMHDR, LRESULT* pResult) 
  268. {
  269. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  270. if((iListIndex = pNMListView->iItem) == -1)
  271. EnableButton(iTreeIndex > 1 ? TRUE : FALSE, FALSE);
  272. *pResult = 0;
  273. }