1 |
// ResultDetailsDialog.cpp : implementation file |
/* |
2 |
// |
* Developed by Torben H. Nielsen |
3 |
|
*/ |
4 |
|
|
5 |
|
|
6 |
#include "stdafx.h" |
#include "stdafx.h" |
7 |
#include "h6-udlånssystem.h" |
#include "h6-udlånssystem.h" |
8 |
#include "ResultDetailsDialog.h" |
#include "ResultDetailsDialog.h" |
9 |
#include ".\resultdetailsdialog.h" |
#include ".\resultdetailsdialog.h" |
10 |
#include "CommonStorage.h" |
#include "CommonStorage.h" |
11 |
|
#include "DatabaseLayer.h" |
12 |
|
#include "CheckoutDialog.h" |
13 |
|
#include "SearchDialog.h" |
14 |
|
#include "ResultDialog.h" |
15 |
|
#include "MyTabCtrl.h" |
16 |
|
|
17 |
// ResultDetailsDialog dialog |
// ResultDetailsDialog dialog |
18 |
|
|
40 |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
41 |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
42 |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
43 |
|
ON_BN_CLICKED(IDC_RETURN, OnBnClickedReturn) |
44 |
|
ON_BN_CLICKED(IDC_CHECKOUT, OnBnClickedCheckout) |
45 |
|
ON_BN_CLICKED(IDC_RESERVE, OnBnClickedReserve) |
46 |
|
ON_BN_CLICKED(IDC_DELRES, OnBnClickedDelres) |
47 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
48 |
|
|
49 |
|
|
72 |
|
|
73 |
//load Equipment::checkouts |
//load Equipment::checkouts |
74 |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
75 |
checkouts->InsertColumn(0,"Inits"); |
checkouts->DeleteAllItems(); |
|
checkouts->InsertColumn(1,"Start date"); |
|
|
checkouts->InsertColumn(2,"Return date"); |
|
|
checkouts->InsertColumn(3,"Number of days"); |
|
76 |
|
|
77 |
for (int i=0; i<currentdata.checkouts.size(); i++) { |
for (int i=0; i<currentdata.checkouts.size(); i++) { |
78 |
int nItem = checkouts->InsertItem(i,currentdata.checkouts[i].inits); |
int nItem = checkouts->InsertItem(i,currentdata.checkouts[i].inits); |
87 |
|
|
88 |
// load Equipment::reservations |
// load Equipment::reservations |
89 |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
90 |
reservations->InsertColumn(0,"Inits"); |
reservations->DeleteAllItems(); |
91 |
reservations->InsertColumn(1,"Start date"); |
|
|
reservations->InsertColumn(2,"Number of days"); |
|
92 |
|
|
93 |
for (int i=0; i<currentdata.reservations.size(); i++) { |
for (int i=0; i<currentdata.reservations.size(); i++) { |
94 |
int nItem = reservations->InsertItem(i, currentdata.reservations[i].inits); |
CString tmp; |
95 |
reservations->SetItemText(nItem,1, currentdata.reservations[i].startdate); |
tmp.Format("%d", i+1); |
96 |
reservations->SetItemText(nItem,2, currentdata.reservations[i].numdays); |
int nItem = reservations->InsertItem(i, tmp); |
97 |
|
reservations->SetItemText(nItem,1, currentdata.reservations[i].inits); |
98 |
|
reservations->SetItemText(nItem,2, currentdata.reservations[i].startdate); |
99 |
|
|
100 |
} |
} |
101 |
|
|
102 |
|
if (currentdata.reservations.size() > 0) |
103 |
|
GetDlgItem(IDC_DELRES)->EnableWindow(true); |
104 |
|
|
105 |
|
|
106 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
107 |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
108 |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
119 |
{ |
{ |
120 |
CDialog::OnInitDialog(); |
CDialog::OnInitDialog(); |
121 |
|
|
122 |
|
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
123 |
|
checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT ); |
124 |
|
checkouts->InsertColumn(0,"Inits"); |
125 |
|
checkouts->InsertColumn(1,"Start date"); |
126 |
|
checkouts->InsertColumn(2,"Return date"); |
127 |
|
checkouts->InsertColumn(3,"Number of days"); |
128 |
|
checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
129 |
|
checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
130 |
|
checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
131 |
|
checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER); |
132 |
|
|
133 |
|
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
134 |
|
reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT ); |
135 |
|
reservations->InsertColumn(0,"#"); |
136 |
|
reservations->InsertColumn(1,"Inits"); |
137 |
|
reservations->InsertColumn(2,"Reservation date"); |
138 |
|
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
139 |
|
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
140 |
|
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
145 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
146 |
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
147 |
|
|
148 |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
149 |
|
|
150 |
if (status == "Ledig") |
if (status == "Ledig") { |
151 |
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
152 |
|
GetDlgItem(IDC_RESERVE)->EnableWindow(false); |
153 |
|
} |
154 |
|
|
155 |
if (status == "Udlånt") |
if (status == "Udlånt") |
156 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
157 |
if (status == "Reserveret") |
if (status == "Reserveret") |
163 |
return TRUE; |
return TRUE; |
164 |
} |
} |
165 |
|
|
166 |
|
///////////////////////////////////////////// |
167 |
|
// a normal EditControl is prettier than a greyed out read-only |
168 |
|
// So to simulate a read-only field, we reload the data every time the |
169 |
|
// user tries to modify the data |
170 |
void ResultDetailsDialog::OnEnChangeBarcode() |
void ResultDetailsDialog::OnEnChangeBarcode() |
171 |
{ |
{ |
172 |
LoadData(); |
LoadData(); |
187 |
LoadData(); |
LoadData(); |
188 |
} |
} |
189 |
|
|
|
|
|
|
|
|
190 |
void ResultDetailsDialog::OnEnChangeStatus() |
void ResultDetailsDialog::OnEnChangeStatus() |
191 |
{ |
{ |
192 |
LoadData(); |
LoadData(); |
193 |
} |
} |
194 |
|
|
|
|
|
195 |
void ResultDetailsDialog::OnBnClickedClose() |
void ResultDetailsDialog::OnBnClickedClose() |
196 |
{ |
{ |
197 |
OnOK(); |
OnOK(); |
198 |
} |
} |
199 |
|
|
200 |
|
////////////////////////////////////////////////// |
201 |
|
|
202 |
|
void ResultDetailsDialog::OnBnClickedReturn() |
203 |
|
{ |
204 |
|
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode; |
205 |
|
|
206 |
|
CommonStorage::Instance()->getDBLayer()->ReturnEquipment(barcode); |
207 |
|
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch(); |
208 |
|
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults(); |
209 |
|
OnOK(); |
210 |
|
} |
211 |
|
|
212 |
|
void ResultDetailsDialog::OnBnClickedCheckout() |
213 |
|
{ |
214 |
|
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
215 |
|
CheckoutDialog check; |
216 |
|
|
217 |
|
check.m_checkoutMode = true; |
218 |
|
|
219 |
|
|
220 |
|
Reservation topReservation; |
221 |
|
if (status == "Reserveret") { |
222 |
|
topReservation = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[0]; |
223 |
|
check.m_reservedTo = topReservation.inits; |
224 |
|
} |
225 |
|
|
226 |
|
if (check.DoModal() == IDOK) |
227 |
|
{ |
228 |
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); |
229 |
|
Person p = dblayer->GetPerson(check.m_inits); |
230 |
|
|
231 |
|
Equipment eq; |
232 |
|
GetDlgItem(IDC_BARCODE)->GetWindowText(eq.barcode); |
233 |
|
|
234 |
|
dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) ); |
235 |
|
|
236 |
|
if (status == "Reserveret") { //if the equipment was reserved, we must delete the reservation |
237 |
|
dblayer->DeleteReservation(eq.barcode, topReservation.reservationID); |
238 |
|
} |
239 |
|
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch(); |
240 |
|
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults(); |
241 |
|
OnOK(); |
242 |
|
} |
243 |
|
} |
244 |
|
|
245 |
|
void ResultDetailsDialog::OnBnClickedReserve() |
246 |
|
{ |
247 |
|
CheckoutDialog check; |
248 |
|
check.m_checkoutMode = false; |
249 |
|
if (check.DoModal() == IDOK) |
250 |
|
{ |
251 |
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); |
252 |
|
Person p = dblayer->GetPerson(check.m_inits); |
253 |
|
CString barcode; |
254 |
|
GetDlgItem(IDC_BARCODE)->GetWindowText(barcode); |
255 |
|
dblayer->EquipmentReservation(barcode,p); |
256 |
|
|
257 |
|
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch(); |
258 |
|
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults(); |
259 |
|
LoadListControls(); |
260 |
|
|
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
void ResultDetailsDialog::OnBnClickedDelres() |
265 |
|
{ |
266 |
|
int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark(); |
267 |
|
if (sel != -1) { |
268 |
|
CString reservationID = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[sel].reservationID; |
269 |
|
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode; |
270 |
|
CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID); |
271 |
|
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch(); |
272 |
|
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults(); |
273 |
|
LoadListControls(); |
274 |
|
} else { |
275 |
|
MessageBox("No reservation is selected"); |
276 |
|
} |
277 |
|
} |