1 |
torben |
21 |
// ResultDetailsDialog.cpp : implementation file
|
2 |
|
|
//
|
3 |
|
|
|
4 |
|
|
#include "stdafx.h"
|
5 |
|
|
#include "h6-udlånssystem.h"
|
6 |
|
|
#include "ResultDetailsDialog.h"
|
7 |
|
|
#include ".\resultdetailsdialog.h"
|
8 |
|
|
#include "CommonStorage.h"
|
9 |
torben |
29 |
#include "DatabaseLayer.h"
|
10 |
|
|
#include "CheckoutDialog.h"
|
11 |
torben |
21 |
|
12 |
|
|
// ResultDetailsDialog dialog
|
13 |
|
|
|
14 |
|
|
IMPLEMENT_DYNAMIC(ResultDetailsDialog, CDialog)
|
15 |
|
|
ResultDetailsDialog::ResultDetailsDialog(CWnd* pParent /*=NULL*/)
|
16 |
|
|
: CDialog(ResultDetailsDialog::IDD, pParent)
|
17 |
|
|
{
|
18 |
|
|
m_loadingData = false;
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
ResultDetailsDialog::~ResultDetailsDialog()
|
22 |
|
|
{
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
void ResultDetailsDialog::DoDataExchange(CDataExchange* pDX)
|
26 |
|
|
{
|
27 |
|
|
CDialog::DoDataExchange(pDX);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
BEGIN_MESSAGE_MAP(ResultDetailsDialog, CDialog)
|
32 |
|
|
ON_EN_CHANGE(IDC_BARCODE, OnEnChangeBarcode)
|
33 |
|
|
ON_EN_CHANGE(IDC_NAME, OnEnChangeName)
|
34 |
|
|
ON_EN_CHANGE(IDC_DESCRIPTION, OnEnChangeDescription)
|
35 |
|
|
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement)
|
36 |
|
|
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus)
|
37 |
|
|
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose)
|
38 |
torben |
29 |
ON_BN_CLICKED(IDC_RETURN, OnBnClickedReturn)
|
39 |
|
|
ON_BN_CLICKED(IDC_CHECKOUT, OnBnClickedCheckout)
|
40 |
|
|
ON_BN_CLICKED(IDC_RESERVE, OnBnClickedReserve)
|
41 |
|
|
ON_BN_CLICKED(IDC_DELRES, OnBnClickedDelres)
|
42 |
torben |
21 |
END_MESSAGE_MAP()
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
// ResultDetailsDialog message handlers
|
46 |
|
|
|
47 |
|
|
void ResultDetailsDialog::LoadData(void)
|
48 |
|
|
{
|
49 |
|
|
if (m_loadingData == true)
|
50 |
|
|
return;
|
51 |
|
|
m_loadingData = true;
|
52 |
|
|
Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex];
|
53 |
|
|
|
54 |
|
|
GetDlgItem(IDC_BARCODE)->SetWindowText(currentdata.barcode);
|
55 |
|
|
GetDlgItem(IDC_NAME)->SetWindowText(currentdata.name);
|
56 |
|
|
GetDlgItem(IDC_DESCRIPTION)->SetWindowText(currentdata.description);
|
57 |
|
|
GetDlgItem(IDC_PLACEMENT)->SetWindowText(currentdata.placement);
|
58 |
|
|
GetDlgItem(IDC_STATUS)->SetWindowText(currentdata.status);
|
59 |
|
|
|
60 |
|
|
m_loadingData = false;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
void ResultDetailsDialog::LoadListControls(void)
|
64 |
|
|
{
|
65 |
|
|
if (CommonStorage::Instance()->getAdmin() ) {
|
66 |
|
|
Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex];
|
67 |
|
|
|
68 |
|
|
//load Equipment::checkouts
|
69 |
|
|
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS);
|
70 |
torben |
29 |
checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
|
71 |
torben |
21 |
checkouts->InsertColumn(0,"Inits");
|
72 |
|
|
checkouts->InsertColumn(1,"Start date");
|
73 |
|
|
checkouts->InsertColumn(2,"Return date");
|
74 |
|
|
checkouts->InsertColumn(3,"Number of days");
|
75 |
|
|
|
76 |
|
|
for (int i=0; i<currentdata.checkouts.size(); i++) {
|
77 |
|
|
int nItem = checkouts->InsertItem(i,currentdata.checkouts[i].inits);
|
78 |
|
|
checkouts->SetItemText(nItem,1,currentdata.checkouts[i].startdate);
|
79 |
|
|
checkouts->SetItemText(nItem,2,currentdata.checkouts[i].enddate);
|
80 |
|
|
checkouts->SetItemText(nItem,3,currentdata.checkouts[i].numdays);
|
81 |
|
|
}
|
82 |
|
|
checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
83 |
|
|
checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
84 |
|
|
checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
85 |
|
|
checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
|
86 |
|
|
|
87 |
|
|
// load Equipment::reservations
|
88 |
|
|
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS);
|
89 |
torben |
29 |
reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
|
90 |
|
|
reservations->InsertColumn(0,"#");
|
91 |
|
|
reservations->InsertColumn(1,"Inits");
|
92 |
|
|
reservations->InsertColumn(2,"Reservation date");
|
93 |
torben |
21 |
|
94 |
torben |
29 |
|
95 |
torben |
21 |
for (int i=0; i<currentdata.reservations.size(); i++) {
|
96 |
torben |
29 |
CString tmp;
|
97 |
|
|
tmp.Format("%d", i+1);
|
98 |
|
|
int nItem = reservations->InsertItem(i, tmp);
|
99 |
|
|
reservations->SetItemText(nItem,1, currentdata.reservations[i].inits);
|
100 |
|
|
reservations->SetItemText(nItem,2, currentdata.reservations[i].startdate);
|
101 |
|
|
|
102 |
torben |
21 |
}
|
103 |
|
|
|
104 |
torben |
29 |
if (currentdata.reservations.size() > 0)
|
105 |
|
|
GetDlgItem(IDC_DELRES)->EnableWindow(true);
|
106 |
|
|
|
107 |
|
|
|
108 |
torben |
21 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
109 |
|
|
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
110 |
|
|
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
} else { // not administrator
|
114 |
|
|
GetDlgItem(IDC_CHECKOUTS)->EnableWindow(false);
|
115 |
|
|
GetDlgItem(IDC_RESERVATIONS)->EnableWindow(false);
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
BOOL ResultDetailsDialog::OnInitDialog()
|
121 |
|
|
{
|
122 |
|
|
CDialog::OnInitDialog();
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
126 |
|
|
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
127 |
|
|
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
128 |
|
|
|
129 |
|
|
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status;
|
130 |
|
|
|
131 |
torben |
29 |
if (status == "Ledig") {
|
132 |
torben |
21 |
GetDlgItem(IDC_RETURN)->EnableWindow(false);
|
133 |
torben |
29 |
GetDlgItem(IDC_RESERVE)->EnableWindow(false);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
torben |
21 |
if (status == "Udlånt")
|
137 |
|
|
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false);
|
138 |
|
|
if (status == "Reserveret")
|
139 |
|
|
GetDlgItem(IDC_RETURN)->EnableWindow(false);
|
140 |
|
|
|
141 |
|
|
LoadData();
|
142 |
|
|
LoadListControls();
|
143 |
|
|
|
144 |
|
|
return TRUE;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
torben |
29 |
/////////////////////////////////////////////
|
148 |
torben |
24 |
// a normal EditControl is prettier than a greyed out read-only
|
149 |
|
|
// So to simulate a read-only field, we reload the data every time the
|
150 |
|
|
// user tries to modify the data
|
151 |
torben |
21 |
void ResultDetailsDialog::OnEnChangeBarcode()
|
152 |
|
|
{
|
153 |
|
|
LoadData();
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
void ResultDetailsDialog::OnEnChangeName()
|
157 |
|
|
{
|
158 |
|
|
LoadData();
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
void ResultDetailsDialog::OnEnChangeDescription()
|
162 |
|
|
{
|
163 |
|
|
LoadData();
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
void ResultDetailsDialog::OnEnChangePlacement()
|
167 |
|
|
{
|
168 |
|
|
LoadData();
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
void ResultDetailsDialog::OnEnChangeStatus()
|
172 |
|
|
{
|
173 |
|
|
LoadData();
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
void ResultDetailsDialog::OnBnClickedClose()
|
177 |
|
|
{
|
178 |
|
|
OnOK();
|
179 |
|
|
}
|
180 |
torben |
29 |
|
181 |
|
|
//////////////////////////////////////////////////
|
182 |
|
|
|
183 |
|
|
void ResultDetailsDialog::OnBnClickedReturn()
|
184 |
|
|
{
|
185 |
|
|
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode;
|
186 |
|
|
|
187 |
|
|
CommonStorage::Instance()->getDBLayer()->ReturnEquipment(barcode);
|
188 |
|
|
MessageBox("The Item is returned, but the changes won't show until the next query");
|
189 |
|
|
OnOK();
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
void ResultDetailsDialog::OnBnClickedCheckout()
|
193 |
|
|
{
|
194 |
|
|
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status;
|
195 |
|
|
CheckoutDialog check;
|
196 |
|
|
|
197 |
|
|
check.m_checkoutMode = true;
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
Reservation topReservation;
|
201 |
|
|
if (status == "Reserveret") {
|
202 |
|
|
topReservation = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[0];
|
203 |
|
|
check.m_reservedTo = topReservation.inits;
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
if (check.DoModal() == IDOK)
|
207 |
|
|
{
|
208 |
|
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
|
209 |
|
|
Person p = dblayer->GetPerson(check.m_inits);
|
210 |
|
|
|
211 |
|
|
Equipment eq;
|
212 |
|
|
GetDlgItem(IDC_BARCODE)->GetWindowText(eq.barcode);
|
213 |
|
|
|
214 |
|
|
dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) );
|
215 |
|
|
|
216 |
|
|
if (status == "Reserveret") { //if the equipment was reserved, we must delete the reservation
|
217 |
|
|
dblayer->DeleteReservation(eq.barcode, topReservation.reservationID);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
OnOK();
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
void ResultDetailsDialog::OnBnClickedReserve()
|
225 |
|
|
{
|
226 |
|
|
CheckoutDialog check;
|
227 |
|
|
check.m_checkoutMode = false;
|
228 |
|
|
if (check.DoModal() == IDOK)
|
229 |
|
|
{
|
230 |
|
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
|
231 |
|
|
Person p = dblayer->GetPerson(check.m_inits);
|
232 |
|
|
CString barcode;
|
233 |
|
|
GetDlgItem(IDC_BARCODE)->GetWindowText(barcode);
|
234 |
|
|
dblayer->EquipmentReservation(barcode,p);
|
235 |
|
|
OnOK();
|
236 |
|
|
}
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
void ResultDetailsDialog::OnBnClickedDelres()
|
240 |
|
|
{
|
241 |
|
|
int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark();
|
242 |
|
|
if (sel != -1) {
|
243 |
|
|
CString reservationID = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[sel].reservationID;
|
244 |
|
|
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode;
|
245 |
|
|
CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID);
|
246 |
|
|
MessageBox("Reservation deleted, but won't show until next search");
|
247 |
|
|
} else {
|
248 |
|
|
MessageBox("No reservation is selected");
|
249 |
|
|
}
|
250 |
|
|
}
|