1 |
/*
|
2 |
* Developed by Torben H. Nielsen
|
3 |
*/
|
4 |
|
5 |
#include "stdafx.h"
|
6 |
#include "h6-udlånssystem.h"
|
7 |
#include "ResultDialog.h"
|
8 |
#include ".\resultdialog.h"
|
9 |
|
10 |
#include "CommonStorage.h"
|
11 |
#include "Containers.h"
|
12 |
#include "ResultDetailsDialog.h"
|
13 |
|
14 |
|
15 |
// ResultDialog dialog
|
16 |
|
17 |
IMPLEMENT_DYNAMIC(ResultDialog, CDialog)
|
18 |
ResultDialog::ResultDialog(CWnd* pParent /*=NULL*/)
|
19 |
: CDialog(ResultDialog::IDD, pParent)
|
20 |
{
|
21 |
}
|
22 |
|
23 |
ResultDialog::~ResultDialog()
|
24 |
{
|
25 |
}
|
26 |
|
27 |
void ResultDialog::DoDataExchange(CDataExchange* pDX)
|
28 |
{
|
29 |
CDialog::DoDataExchange(pDX);
|
30 |
}
|
31 |
|
32 |
|
33 |
BEGIN_MESSAGE_MAP(ResultDialog, CDialog)
|
34 |
ON_WM_SETFOCUS()
|
35 |
ON_BN_CLICKED(IDC_DETAILS, OnBnClickedDetails)
|
36 |
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnNMDblclkList)
|
37 |
END_MESSAGE_MAP()
|
38 |
|
39 |
|
40 |
// ResultDialog message handlers
|
41 |
|
42 |
void ResultDialog::OnOK()
|
43 |
{
|
44 |
// TODO: Add your specialized code here and/or call the base class
|
45 |
|
46 |
//CDialog::OnOK();
|
47 |
}
|
48 |
|
49 |
void ResultDialog::OnCancel()
|
50 |
{
|
51 |
// TODO: Add your specialized code here and/or call the base class
|
52 |
|
53 |
//CDialog::OnCancel();
|
54 |
}
|
55 |
|
56 |
void ResultDialog::OnSetFocus(CWnd* pOldWnd)
|
57 |
{
|
58 |
CDialog::OnSetFocus(pOldWnd);
|
59 |
LoadResults();
|
60 |
|
61 |
}
|
62 |
|
63 |
void ResultDialog::LoadResults(void)
|
64 |
{
|
65 |
CListCtrl *list = (CListCtrl *) GetDlgItem(IDC_LIST);
|
66 |
vector<Equipment> result = CommonStorage::Instance()->getSearchResult();
|
67 |
|
68 |
CString count;
|
69 |
count.Format("Found %d items", result.size());
|
70 |
GetDlgItem(IDC_COUNTER)->SetWindowText(count);
|
71 |
list->DeleteAllItems();
|
72 |
|
73 |
for (int i=0; i<result.size(); i++) {
|
74 |
int nItem = list->InsertItem(i, result[i].barcode);
|
75 |
list->SetItemText(nItem,1,result[i].name);
|
76 |
list->SetItemText(nItem,2,result[i].status);
|
77 |
}
|
78 |
|
79 |
if (result.size() >0) {
|
80 |
list->SetColumnWidth(0,LVSCW_AUTOSIZE);
|
81 |
list->SetColumnWidth(1,100);
|
82 |
list->SetColumnWidth(2,100);
|
83 |
}
|
84 |
|
85 |
}
|
86 |
|
87 |
BOOL ResultDialog::OnInitDialog()
|
88 |
{
|
89 |
CDialog::OnInitDialog();
|
90 |
|
91 |
CListCtrl *list = (CListCtrl *) GetDlgItem(IDC_LIST);
|
92 |
list->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
|
93 |
list->InsertColumn(0,"Barcode");
|
94 |
list->InsertColumn(1,"Equipment");
|
95 |
list->InsertColumn(2,"Status");
|
96 |
|
97 |
list->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
98 |
list->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
99 |
list->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
100 |
|
101 |
return TRUE;
|
102 |
}
|
103 |
|
104 |
void ResultDialog::OnBnClickedDetails()
|
105 |
{
|
106 |
CListCtrl *list = (CListCtrl *) GetDlgItem(IDC_LIST);
|
107 |
if (list->GetItemCount() > 0) {
|
108 |
|
109 |
int sel = list->GetSelectionMark();
|
110 |
CString barcode = list->GetItemText(sel,0);
|
111 |
|
112 |
if (sel == -1) {
|
113 |
MessageBox("You must select an item");
|
114 |
} else {
|
115 |
ResultDetailsDialog resdialog;
|
116 |
resdialog.m_barcode = barcode;
|
117 |
|
118 |
resdialog.DoModal();
|
119 |
}
|
120 |
}
|
121 |
}
|
122 |
|
123 |
void ResultDialog::OnNMDblclkList(NMHDR *pNMHDR, LRESULT *pResult)
|
124 |
{
|
125 |
CListCtrl *list = (CListCtrl *) GetDlgItem(IDC_LIST);
|
126 |
if (list->GetItemCount() > 0) {
|
127 |
int sel = list->GetSelectionMark();
|
128 |
CString barcode = list->GetItemText(sel,0);
|
129 |
|
130 |
ResultDetailsDialog resdialog;
|
131 |
resdialog.m_barcode = barcode;
|
132 |
|
133 |
resdialog.DoModal();
|
134 |
}
|
135 |
|
136 |
*pResult = 0;
|
137 |
}
|