9b2c29d4ef4774f08a485875ec50855ff986e84b
[public/netxms.git] / src / console / win32 / DataCollectionEditor.cpp
1 // DataCollectionEditor.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "DataCollectionEditor.h"
7 #include "DCIPropPage.h"
8 #include "DCIThresholdsPage.h"
9 #include "DCITransformPage.h"
10
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
16
17
18 /////////////////////////////////////////////////////////////////////////////
19 // CDataCollectionEditor
20
21 IMPLEMENT_DYNCREATE(CDataCollectionEditor, CMDIChildWnd)
22
23 CDataCollectionEditor::CDataCollectionEditor()
24 {
25 m_pItemList = NULL;
26 }
27
28 CDataCollectionEditor::CDataCollectionEditor(NXC_DCI_LIST *pList)
29 {
30 m_pItemList = pList;
31 }
32
33 CDataCollectionEditor::~CDataCollectionEditor()
34 {
35 }
36
37
38 BEGIN_MESSAGE_MAP(CDataCollectionEditor, CMDIChildWnd)
39 //{{AFX_MSG_MAP(CDataCollectionEditor)
40 ON_WM_CREATE()
41 ON_WM_DESTROY()
42 ON_WM_CLOSE()
43 ON_WM_SIZE()
44 ON_WM_CONTEXTMENU()
45 ON_COMMAND(ID_ITEM_NEW, OnItemNew)
46 ON_COMMAND(ID_ITEM_EDIT, OnItemEdit)
47 ON_WM_SETFOCUS()
48 ON_UPDATE_COMMAND_UI(ID_ITEM_EDIT, OnUpdateItemEdit)
49 ON_COMMAND(ID_ITEM_DELETE, OnItemDelete)
50 ON_UPDATE_COMMAND_UI(ID_ITEM_DELETE, OnUpdateItemDelete)
51 ON_COMMAND(ID_ITEM_SHOWDATA, OnItemShowdata)
52 ON_UPDATE_COMMAND_UI(ID_ITEM_SHOWDATA, OnUpdateItemShowdata)
53 ON_COMMAND(ID_ITEM_GRAPH, OnItemGraph)
54 ON_UPDATE_COMMAND_UI(ID_ITEM_GRAPH, OnUpdateItemGraph)
55 ON_COMMAND(ID_ITEM_COPY, OnItemCopy)
56 ON_COMMAND(ID_FILE_EXPORT, OnFileExport)
57 ON_UPDATE_COMMAND_UI(ID_FILE_EXPORT, OnUpdateFileExport)
58 ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
59 ON_COMMAND(ID_ITEM_DUPLICATE, OnItemDuplicate)
60 ON_UPDATE_COMMAND_UI(ID_ITEM_COPY, OnUpdateItemCopy)
61 ON_UPDATE_COMMAND_UI(ID_ITEM_DUPLICATE, OnUpdateItemDuplicate)
62 ON_COMMAND(ID_ITEM_DISABLE, OnItemDisable)
63 ON_COMMAND(ID_ITEM_ACTIVATE, OnItemActivate)
64 ON_UPDATE_COMMAND_UI(ID_ITEM_ACTIVATE, OnUpdateItemActivate)
65 ON_UPDATE_COMMAND_UI(ID_ITEM_DISABLE, OnUpdateItemDisable)
66 //}}AFX_MSG_MAP
67 ON_NOTIFY(NM_DBLCLK, IDC_LIST_VIEW, OnListViewDblClk)
68 END_MESSAGE_MAP()
69
70 /////////////////////////////////////////////////////////////////////////////
71 // CDataCollectionEditor message handlers
72
73
74 //
75 // WM_CREATE message handler
76 //
77
78 int CDataCollectionEditor::OnCreate(LPCREATESTRUCT lpCreateStruct)
79 {
80 RECT rect;
81 DWORD i;
82
83 if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
84 return -1;
85
86 // We should't create window without bound item list
87 if (m_pItemList == NULL)
88 return -1;
89
90 // Create image list
91 m_imageList.Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 1);
92 m_imageList.Add(theApp.LoadIcon(IDI_ACTIVE));
93 m_imageList.Add(theApp.LoadIcon(IDI_DISABLED));
94 m_imageList.Add(theApp.LoadIcon(IDI_UNSUPPORTED));
95
96 // Create list view control
97 GetClientRect(&rect);
98 m_wndListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT, rect, this, IDC_LIST_VIEW);
99 m_wndListCtrl.SetExtendedStyle(LVS_EX_TRACKSELECT | LVS_EX_UNDERLINEHOT |
100 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
101 m_wndListCtrl.SetHoverTime(0x7FFFFFFF);
102 m_wndListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
103
104 // Setup columns
105 m_wndListCtrl.InsertColumn(0, "ID", LVCFMT_LEFT, 40);
106 m_wndListCtrl.InsertColumn(1, "Source", LVCFMT_LEFT, 80);
107 m_wndListCtrl.InsertColumn(2, "Description", LVCFMT_LEFT, 150);
108 m_wndListCtrl.InsertColumn(3, "Parameter", LVCFMT_LEFT, 150);
109 m_wndListCtrl.InsertColumn(4, "Data type", LVCFMT_LEFT, 80);
110 m_wndListCtrl.InsertColumn(5, "Polling Interval", LVCFMT_LEFT, 80);
111 m_wndListCtrl.InsertColumn(6, "Retention Time", LVCFMT_LEFT, 80);
112 m_wndListCtrl.InsertColumn(7, "Status", LVCFMT_LEFT, 90);
113
114 // Fill list view with data
115 for(i = 0; i < m_pItemList->dwNumItems; i++)
116 AddListItem(&m_pItemList->pItems[i]);
117
118 ((CConsoleApp *)AfxGetApp())->OnViewCreate(IDR_DC_EDITOR, this, m_pItemList->dwNodeId);
119
120 return 0;
121 }
122
123
124 //
125 // WM_DESTROY message handler
126 //
127
128 void CDataCollectionEditor::OnDestroy()
129 {
130 theApp.OnViewDestroy(IDR_DC_EDITOR, this);
131 CMDIChildWnd::OnDestroy();
132 }
133
134
135 //
136 // WM_CLOSE message handler
137 //
138
139 void CDataCollectionEditor::OnClose()
140 {
141 DWORD dwResult;
142
143 dwResult = DoRequestArg1(NXCCloseNodeDCIList, m_pItemList, "Unlocking node's data collection information...");
144 if (dwResult != RCC_SUCCESS)
145 theApp.ErrorBox(dwResult, "Unable to close data collection configuration:\n%s");
146
147 CMDIChildWnd::OnClose();
148 }
149
150
151 //
152 // WM_SIZE message handler
153 //
154
155 void CDataCollectionEditor::OnSize(UINT nType, int cx, int cy)
156 {
157 CMDIChildWnd::OnSize(nType, cx, cy);
158 m_wndListCtrl.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
159 }
160
161
162 //
163 // Add new item to list
164 //
165
166 int CDataCollectionEditor::AddListItem(NXC_DCI *pItem)
167 {
168 int iItem;
169 char szBuffer[32];
170
171 sprintf(szBuffer, "%d", pItem->dwId);
172 iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, szBuffer);
173 if (iItem != -1)
174 {
175 m_wndListCtrl.SetItemData(iItem, pItem->dwId);
176 UpdateListItem(iItem, pItem);
177 }
178 return iItem;
179 }
180
181
182 //
183 // Update existing list view item
184 //
185
186 void CDataCollectionEditor::UpdateListItem(int iItem, NXC_DCI *pItem)
187 {
188 char szBuffer[32];
189
190 m_wndListCtrl.SetItemText(iItem, 1, g_pszItemOrigin[pItem->iSource]);
191 m_wndListCtrl.SetItemText(iItem, 2, pItem->szDescription);
192 m_wndListCtrl.SetItemText(iItem, 3, pItem->szName);
193 m_wndListCtrl.SetItemText(iItem, 4, g_pszItemDataType[pItem->iDataType]);
194 sprintf(szBuffer, "%d sec", pItem->iPollingInterval);
195 m_wndListCtrl.SetItemText(iItem, 5, szBuffer);
196 sprintf(szBuffer, "%d days", pItem->iRetentionTime);
197 m_wndListCtrl.SetItemText(iItem, 6, szBuffer);
198 m_wndListCtrl.SetItemText(iItem, 7, g_pszItemStatus[pItem->iStatus]);
199 m_wndListCtrl.SetItem(iItem, 0, LVIF_IMAGE, NULL, pItem->iStatus, 0, 0, 0);
200 }
201
202
203 //
204 // WM_CONTEXTMENU message handler
205 //
206
207 void CDataCollectionEditor::OnContextMenu(CWnd* pWnd, CPoint point)
208 {
209 CMenu *pMenu;
210
211 pMenu = theApp.GetContextMenu(2);
212 pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this, NULL);
213 }
214
215
216 //
217 // WM_COMMAND::ID_ITEM_NEW message handler
218 //
219
220 void CDataCollectionEditor::OnItemNew()
221 {
222 DWORD dwResult, dwItemId, dwIndex;
223 NXC_DCI item;
224 int iItem;
225
226 // Prepare default data collection item
227 memset(&item, 0, sizeof(NXC_DCI));
228 item.iPollingInterval = 60;
229 item.iRetentionTime = 30;
230 item.iSource = DS_NATIVE_AGENT;
231 item.iStatus = ITEM_STATUS_ACTIVE;
232
233 if (EditItem(&item))
234 {
235 dwResult = DoRequestArg2(NXCCreateNewDCI, m_pItemList, &dwItemId,
236 "Creating new data collection item...");
237 if (dwResult == RCC_SUCCESS)
238 {
239 dwIndex = NXCItemIndex(m_pItemList, dwItemId);
240 item.dwId = dwItemId;
241 if (dwIndex != INVALID_INDEX)
242 {
243 dwResult = DoRequestArg2(NXCUpdateDCI, (void *)m_pItemList->dwNodeId, &item,
244 "Updating data collection item...");
245 if (dwResult == RCC_SUCCESS)
246 {
247 memcpy(&m_pItemList->pItems[dwIndex], &item, sizeof(NXC_DCI));
248 iItem = AddListItem(&item);
249 SelectListItem(iItem);
250 }
251 else
252 {
253 theApp.ErrorBox(dwResult, "Unable to update data collection item: %s");
254 }
255 }
256 }
257 else
258 {
259 theApp.ErrorBox(dwResult, "Unable to create new data collection item: %s");
260 }
261 }
262 }
263
264
265 //
266 // WM_COMMAND::ID_ITEM_EDIT message handler
267 //
268
269 void CDataCollectionEditor::OnItemEdit()
270 {
271 int iItem;
272 DWORD dwItemId, dwIndex, dwResult;
273 NXC_DCI item;
274
275 if (m_wndListCtrl.GetSelectedCount() == 1)
276 {
277 iItem = m_wndListCtrl.GetNextItem(-1, LVIS_FOCUSED);
278 dwItemId = m_wndListCtrl.GetItemData(iItem);
279 dwIndex = NXCItemIndex(m_pItemList, dwItemId);
280 if (dwIndex != INVALID_INDEX)
281 {
282 memcpy(&item, &m_pItemList->pItems[dwIndex], sizeof(NXC_DCI));
283 item.pThresholdList = (NXC_DCI_THRESHOLD *)nx_memdup(
284 m_pItemList->pItems[dwIndex].pThresholdList,
285 sizeof(NXC_DCI_THRESHOLD) * item.dwNumThresholds);
286 if (EditItem(&item))
287 {
288 dwResult = DoRequestArg2(NXCUpdateDCI, (void *)m_pItemList->dwNodeId, &item,
289 "Updating data collection item...");
290 if (dwResult == RCC_SUCCESS)
291 {
292 free(m_pItemList->pItems[dwIndex].pThresholdList);
293 memcpy(&m_pItemList->pItems[dwIndex], &item, sizeof(NXC_DCI));
294 UpdateListItem(iItem, &m_pItemList->pItems[dwIndex]);
295 }
296 else
297 {
298 free(item.pThresholdList);
299 theApp.ErrorBox(dwResult, "Unable to update data collection item: %s");
300 }
301 }
302 else
303 {
304 free(item.pThresholdList);
305 }
306 }
307 }
308 }
309
310
311 //
312 // Start item editing dialog
313 //
314
315 BOOL CDataCollectionEditor::EditItem(NXC_DCI *pItem)
316 {
317 BOOL bSuccess = FALSE;
318 CPropertySheet dlg;
319 CDCIPropPage pgCollection;
320 CDCITransformPage pgTransform;
321 CDCIThresholdsPage pgThresholds;
322
323 // Setup "Collection" page
324 pgCollection.m_iDataType = pItem->iDataType;
325 pgCollection.m_iOrigin = pItem->iSource;
326 pgCollection.m_iPollingInterval = pItem->iPollingInterval;
327 pgCollection.m_iRetentionTime = pItem->iRetentionTime;
328 pgCollection.m_iStatus = pItem->iStatus;
329 pgCollection.m_strName = pItem->szName;
330 pgCollection.m_strDescription = pItem->szDescription;
331 pgCollection.m_pNode = NXCFindObjectById(m_pItemList->dwNodeId);
332
333 // Setup "Transformation" page
334 pgTransform.m_iDeltaProc = pItem->iDeltaCalculation;
335 pgTransform.m_strFormula = CHECK_NULL_EX(pItem->pszFormula);
336
337 // Setup "Thresholds" page
338 pgThresholds.m_pItem = pItem;
339 pgThresholds.m_strInstance = pItem->szInstance;
340
341 // Setup property sheet and run
342 dlg.SetTitle("Data Collection Item");
343 dlg.m_psh.dwFlags |= PSH_NOAPPLYNOW;
344 dlg.AddPage(&pgCollection);
345 dlg.AddPage(&pgTransform);
346 dlg.AddPage(&pgThresholds);
347 if (dlg.DoModal() == IDOK)
348 {
349 pItem->iDataType = pgCollection.m_iDataType;
350 pItem->iSource = pgCollection.m_iOrigin;
351 pItem->iPollingInterval = pgCollection.m_iPollingInterval;
352 pItem->iRetentionTime = pgCollection.m_iRetentionTime;
353 pItem->iStatus = pgCollection.m_iStatus;
354 strcpy(pItem->szName, (LPCTSTR)pgCollection.m_strName);
355 strcpy(pItem->szDescription, (LPCTSTR)pgCollection.m_strDescription);
356 StrStrip(pItem->szDescription);
357 if (pItem->szDescription[0] == 0)
358 strcpy(pItem->szDescription, pItem->szName);
359 pItem->iDeltaCalculation = pgTransform.m_iDeltaProc;
360 safe_free(pItem->pszFormula);
361 pItem->pszFormula = strdup((LPCTSTR)pgTransform.m_strFormula);
362 strcpy(pItem->szInstance, (LPCTSTR)pgThresholds.m_strInstance);
363 StrStrip(pItem->szInstance);
364 bSuccess = TRUE;
365 }
366 return bSuccess;
367 }
368
369
370 //
371 // WM_SETFOCUS message handler
372 //
373
374 void CDataCollectionEditor::OnSetFocus(CWnd* pOldWnd)
375 {
376 CMDIChildWnd::OnSetFocus(pOldWnd);
377 m_wndListCtrl.SetFocus();
378 }
379
380
381 //
382 // UPDATE_COMMAND_UI handlers
383 //
384
385 void CDataCollectionEditor::OnUpdateItemEdit(CCmdUI* pCmdUI)
386 {
387 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() == 1);
388 }
389
390 void CDataCollectionEditor::OnUpdateItemDelete(CCmdUI* pCmdUI)
391 {
392 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
393 }
394
395 void CDataCollectionEditor::OnUpdateItemShowdata(CCmdUI* pCmdUI)
396 {
397 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
398 }
399
400 void CDataCollectionEditor::OnUpdateItemGraph(CCmdUI* pCmdUI)
401 {
402 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() == 1);
403 }
404
405 void CDataCollectionEditor::OnUpdateItemCopy(CCmdUI* pCmdUI)
406 {
407 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
408 }
409
410 void CDataCollectionEditor::OnUpdateItemDuplicate(CCmdUI* pCmdUI)
411 {
412 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
413 }
414
415 void CDataCollectionEditor::OnUpdateItemActivate(CCmdUI* pCmdUI)
416 {
417 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
418 }
419
420 void CDataCollectionEditor::OnUpdateItemDisable(CCmdUI* pCmdUI)
421 {
422 pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
423 }
424
425 void CDataCollectionEditor::OnUpdateFileExport(CCmdUI* pCmdUI)
426 {
427 NXC_OBJECT *pObject;
428
429 pObject = NXCFindObjectById(m_pItemList->dwNodeId);
430 if (pObject != NULL)
431 pCmdUI->Enable(pObject->iClass == OBJECT_TEMPLATE);
432 else
433 pCmdUI->Enable(FALSE);
434 }
435
436
437 //
438 // Clear list view selection and select specified item
439 //
440
441 void CDataCollectionEditor::SelectListItem(int iItem)
442 {
443 int iOldItem;
444
445 // Clear current selection
446 iOldItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
447 while(iOldItem != -1)
448 {
449 m_wndListCtrl.SetItemState(iOldItem, 0, LVIS_SELECTED);
450 iOldItem = m_wndListCtrl.GetNextItem(iOldItem, LVNI_SELECTED);
451 }
452
453 // Remove current focus
454 iOldItem = m_wndListCtrl.GetNextItem(-1, LVNI_FOCUSED);
455 if (iOldItem != -1)
456 m_wndListCtrl.SetItemState(iOldItem, 0, LVIS_FOCUSED);
457
458 // Select and set focus to new item
459 m_wndListCtrl.EnsureVisible(iItem, FALSE);
460 m_wndListCtrl.SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED,
461 LVIS_SELECTED | LVIS_FOCUSED);
462 m_wndListCtrl.SetSelectionMark(iItem);
463 }
464
465
466 //
467 // WM_COMMAND::ID_ITEM_DELETE message handler
468 //
469
470 void CDataCollectionEditor::OnItemDelete()
471 {
472 int iItem;
473 DWORD dwItemId, dwResult;
474
475 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
476 while(iItem != -1)
477 {
478 dwItemId = m_wndListCtrl.GetItemData(iItem);
479 dwResult = DoRequestArg2(NXCDeleteDCI, m_pItemList, (void *)dwItemId,
480 "Deleting data collection item...");
481 if (dwResult != RCC_SUCCESS)
482 {
483 theApp.ErrorBox(dwResult, "Unable to delete data collection item: %s");
484 break;
485 }
486 m_wndListCtrl.DeleteItem(iItem);
487 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
488 }
489 }
490
491
492 //
493 // Handler for WM_NOTIFY::NM_DBLCLK from IDC_LIST_VIEW
494 //
495
496 void CDataCollectionEditor::OnListViewDblClk(LPNMITEMACTIVATE pNMHDR, LRESULT *pResult)
497 {
498 PostMessage(WM_COMMAND, ID_ITEM_EDIT, 0);
499 }
500
501
502 //
503 // Show collected data for specific item
504 //
505
506 void CDataCollectionEditor::OnItemShowdata()
507 {
508 int iItem;
509 DWORD dwItemId, dwIndex;
510 char szBuffer[384];
511 NXC_OBJECT *pObject;
512
513 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
514 while(iItem != -1)
515 {
516 dwItemId = m_wndListCtrl.GetItemData(iItem);
517 dwIndex = NXCItemIndex(m_pItemList, dwItemId);
518 pObject = NXCFindObjectById(m_pItemList->dwNodeId);
519 sprintf(szBuffer, "%s - %s", pObject->szName,
520 m_pItemList->pItems[dwIndex].szDescription);
521 theApp.ShowDCIData(m_pItemList->dwNodeId, dwItemId, szBuffer);
522 iItem = m_wndListCtrl.GetNextItem(iItem, LVNI_SELECTED);
523 }
524 }
525
526
527 //
528 // WM_COMMAND::ID_ITEM_GRAPH message handler
529 //
530
531 void CDataCollectionEditor::OnItemGraph()
532 {
533 int iItem;
534 DWORD dwItemId, dwIndex;
535 char szBuffer[384];
536 NXC_OBJECT *pObject;
537
538 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_FOCUSED);
539 if (iItem != -1)
540 {
541 dwItemId = m_wndListCtrl.GetItemData(iItem);
542 dwIndex = NXCItemIndex(m_pItemList, dwItemId);
543 pObject = NXCFindObjectById(m_pItemList->dwNodeId);
544 sprintf(szBuffer, "%s - %s", pObject->szName,
545 m_pItemList->pItems[dwIndex].szDescription);
546 theApp.ShowDCIGraph(m_pItemList->dwNodeId, dwItemId, szBuffer);
547 }
548 }
549
550
551 //
552 // Overriden PreCreateWindow()
553 //
554
555 BOOL CDataCollectionEditor::PreCreateWindow(CREATESTRUCT& cs)
556 {
557 if (cs.lpszClass == NULL)
558 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, NULL, NULL,
559 AfxGetApp()->LoadIcon(IDI_DATACOLLECT));
560 return CMDIChildWnd::PreCreateWindow(cs);
561 }
562
563
564 //
565 // Copy DCIs to host(s)
566 //
567
568 static DWORD __cdecl CopyItems(DWORD dwSourceNode, DWORD dwNumObjects, DWORD *pdwObjectList,
569 DWORD dwNumItems, DWORD *pdwItemList)
570 {
571 DWORD i, dwResult;
572
573 for(i = 0; i < dwNumObjects; i++)
574 {
575 dwResult = NXCCopyDCI(dwSourceNode, pdwObjectList[i], dwNumItems, pdwItemList);
576 if (dwResult != RCC_SUCCESS)
577 break;
578 }
579 return dwResult;
580 }
581
582
583 //
584 // WM_COMMAND::ID_ITEM_COPY message handler
585 //
586
587 void CDataCollectionEditor::OnItemCopy()
588 {
589 CObjectSelDlg dlg;
590 int iPos, iItem;
591 DWORD dwResult, dwNumItems, *pdwItemList;
592
593 dwNumItems = m_wndListCtrl.GetSelectedCount();
594 if (dwNumItems > 0)
595 {
596 pdwItemList = (DWORD *)malloc(sizeof(DWORD) * dwNumItems);
597
598 // Build list of items to be copied
599 iPos = 0;
600 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
601 while(iItem != -1)
602 {
603 pdwItemList[iPos++] = m_wndListCtrl.GetItemData(iItem);
604 iItem = m_wndListCtrl.GetNextItem(iItem, LVNI_SELECTED);
605 }
606
607 // Ask for destination nodes
608 dlg.m_dwAllowedClasses = SCL_NODE;
609 if (dlg.DoModal() == IDOK)
610 {
611 // Perform request(s) to server
612 dwResult = DoRequestArg5(CopyItems, (void *)m_pItemList->dwNodeId,
613 (void *)dlg.m_dwNumObjects, dlg.m_pdwObjectList,
614 (void *)dwNumItems, pdwItemList, "Copying items...");
615 if (dwResult != RCC_SUCCESS)
616 theApp.ErrorBox(dwResult, "Error copying items: %s");
617 }
618
619 // Cleanup
620 free(pdwItemList);
621 }
622 }
623
624
625 //
626 // WM_COMMAND::ID_ITEM_DUPLICATE message handler
627 //
628
629 void CDataCollectionEditor::OnItemDuplicate()
630 {
631 int iPos, iItem;
632 DWORD dwResult, dwNumItems, *pdwItemList;
633
634 dwNumItems = m_wndListCtrl.GetSelectedCount();
635 if (dwNumItems > 0)
636 {
637 pdwItemList = (DWORD *)malloc(sizeof(DWORD) * dwNumItems);
638
639 // Build list of items to be copied
640 iPos = 0;
641 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
642 while(iItem != -1)
643 {
644 pdwItemList[iPos++] = m_wndListCtrl.GetItemData(iItem);
645 iItem = m_wndListCtrl.GetNextItem(iItem, LVNI_SELECTED);
646 }
647
648 // Perform request(s) to server
649 dwResult = DoRequestArg4(NXCCopyDCI, (void *)m_pItemList->dwNodeId,
650 (void *)m_pItemList->dwNodeId, (void *)dwNumItems,
651 pdwItemList, "Copying items...");
652 if (dwResult != RCC_SUCCESS)
653 theApp.ErrorBox(dwResult, "Error copying items: %s");
654 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
655
656 // Cleanup
657 free(pdwItemList);
658 }
659 }
660
661
662 //
663 // WM_COMMAND::ID_FILE_EXPORT message handler
664 //
665
666 void CDataCollectionEditor::OnFileExport()
667 {
668 CFileDialog dlg(FALSE);
669
670 dlg.m_ofn.lpstrDefExt = _T("dct");
671 dlg.m_ofn.Flags |= OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
672 dlg.m_ofn.lpstrFilter = _T("Data Collection Templates (*.dct)\0*.dct\0XML Files (*.xml)\0*.xml\0All Files (*.*)\0*.*\0");
673 if (dlg.DoModal() == IDOK)
674 {
675 MessageBox(dlg.m_ofn.lpstrFile,"FILE");
676 }
677 }
678
679
680 //
681 // WM_COMMAND::ID_VIEW_REFRESH message handler
682 //
683
684 void CDataCollectionEditor::OnViewRefresh()
685 {
686 DWORD i, dwResult, dwObjectId;
687
688 dwObjectId = m_pItemList->dwNodeId;
689
690 // Re-open node's DCI list
691 dwResult = DoRequestArg1(NXCCloseNodeDCIList, m_pItemList, "Unlocking node's data collection information...");
692 if (dwResult != RCC_SUCCESS)
693 theApp.ErrorBox(dwResult, "Unable to close data collection configuration:\n%s");
694
695 dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)dwObjectId,
696 &m_pItemList, "Loading node's data collection information...");
697 if (dwResult != RCC_SUCCESS)
698 theApp.ErrorBox(dwResult, "Unable to load data collection information for node:\n%s");
699
700 // Fill list view with data
701 m_wndListCtrl.DeleteAllItems();
702 for(i = 0; i < m_pItemList->dwNumItems; i++)
703 AddListItem(&m_pItemList->pItems[i]);
704 }
705
706
707 //
708 // WM_COMMAND::ID_ITEM_DISABLE message handler
709 //
710
711 void CDataCollectionEditor::OnItemDisable()
712 {
713 ChangeItemsStatus(ITEM_STATUS_DISABLED);
714 }
715
716
717 //
718 // WM_COMMAND::ID_ITEM_ACTIVATE message handler
719 //
720
721 void CDataCollectionEditor::OnItemActivate()
722 {
723 ChangeItemsStatus(ITEM_STATUS_ACTIVE);
724 }
725
726
727 //
728 // Change status for one or more items at once
729 //
730
731 void CDataCollectionEditor::ChangeItemsStatus(int iStatus)
732 {
733 int iItem;
734 DWORD iPos, dwNumItems, *pdwItemList, dwResult;
735
736 dwNumItems = m_wndListCtrl.GetSelectedCount();
737 if (dwNumItems > 0)
738 {
739 pdwItemList = (DWORD *)malloc(sizeof(DWORD) * dwNumItems);
740
741 // Build list of items to be copied
742 iPos = 0;
743 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
744 while(iItem != -1)
745 {
746 pdwItemList[iPos++] = m_wndListCtrl.GetItemData(iItem);
747 iItem = m_wndListCtrl.GetNextItem(iItem, LVNI_SELECTED);
748 }
749
750 // Send request to server
751 dwResult = DoRequestArg4(NXCSetDCIStatus, (void *)m_pItemList->dwNodeId,
752 (void *)dwNumItems, pdwItemList, (void *)iStatus,
753 _T("Updating DCI status..."));
754 if (dwResult == RCC_SUCCESS)
755 {
756 DWORD dwIndex;
757
758 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
759 while(iItem != -1)
760 {
761 dwIndex = NXCItemIndex(m_pItemList, m_wndListCtrl.GetItemData(iItem));
762 m_pItemList->pItems[dwIndex].iStatus = iStatus;
763 UpdateListItem(iItem, &m_pItemList->pItems[dwIndex]);
764 iItem = m_wndListCtrl.GetNextItem(iItem, LVNI_SELECTED);
765 }
766 }
767 else
768 {
769 theApp.ErrorBox(dwResult, _T("Error setting DCI status: %s"));
770 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
771 }
772
773 free(pdwItemList);
774 }
775 }