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 |
|
|
14 |
// ResultDetailsDialog dialog |
// ResultDetailsDialog dialog |
15 |
|
|
37 |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
38 |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
39 |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
40 |
|
ON_BN_CLICKED(IDC_RETURN, OnBnClickedReturn) |
41 |
|
ON_BN_CLICKED(IDC_CHECKOUT, OnBnClickedCheckout) |
42 |
|
ON_BN_CLICKED(IDC_RESERVE, OnBnClickedReserve) |
43 |
|
ON_BN_CLICKED(IDC_DELRES, OnBnClickedDelres) |
44 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
45 |
|
|
46 |
|
|
69 |
|
|
70 |
//load Equipment::checkouts |
//load Equipment::checkouts |
71 |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
72 |
|
checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT ); |
73 |
checkouts->InsertColumn(0,"Inits"); |
checkouts->InsertColumn(0,"Inits"); |
74 |
checkouts->InsertColumn(1,"Start date"); |
checkouts->InsertColumn(1,"Start date"); |
75 |
checkouts->InsertColumn(2,"Return date"); |
checkouts->InsertColumn(2,"Return date"); |
88 |
|
|
89 |
// load Equipment::reservations |
// load Equipment::reservations |
90 |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
91 |
reservations->InsertColumn(0,"Inits"); |
reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT ); |
92 |
reservations->InsertColumn(1,"Start date"); |
reservations->InsertColumn(0,"#"); |
93 |
reservations->InsertColumn(2,"Number of days"); |
reservations->InsertColumn(1,"Inits"); |
94 |
|
reservations->InsertColumn(2,"Reservation date"); |
95 |
|
|
96 |
|
|
97 |
for (int i=0; i<currentdata.reservations.size(); i++) { |
for (int i=0; i<currentdata.reservations.size(); i++) { |
98 |
int nItem = reservations->InsertItem(i, currentdata.reservations[i].inits); |
CString tmp; |
99 |
reservations->SetItemText(nItem,1, currentdata.reservations[i].startdate); |
tmp.Format("%d", i+1); |
100 |
reservations->SetItemText(nItem,2, currentdata.reservations[i].numdays); |
int nItem = reservations->InsertItem(i, tmp); |
101 |
|
reservations->SetItemText(nItem,1, currentdata.reservations[i].inits); |
102 |
|
reservations->SetItemText(nItem,2, currentdata.reservations[i].startdate); |
103 |
|
|
104 |
} |
} |
105 |
|
|
106 |
|
if (currentdata.reservations.size() > 0) |
107 |
|
GetDlgItem(IDC_DELRES)->EnableWindow(true); |
108 |
|
|
109 |
|
|
110 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
111 |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
112 |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
130 |
|
|
131 |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
132 |
|
|
133 |
if (status == "Ledig") |
if (status == "Ledig") { |
134 |
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
135 |
|
GetDlgItem(IDC_RESERVE)->EnableWindow(false); |
136 |
|
} |
137 |
|
|
138 |
if (status == "Udlånt") |
if (status == "Udlånt") |
139 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
140 |
if (status == "Reserveret") |
if (status == "Reserveret") |
146 |
return TRUE; |
return TRUE; |
147 |
} |
} |
148 |
|
|
149 |
|
///////////////////////////////////////////// |
150 |
|
// a normal EditControl is prettier than a greyed out read-only |
151 |
|
// So to simulate a read-only field, we reload the data every time the |
152 |
|
// user tries to modify the data |
153 |
void ResultDetailsDialog::OnEnChangeBarcode() |
void ResultDetailsDialog::OnEnChangeBarcode() |
154 |
{ |
{ |
155 |
LoadData(); |
LoadData(); |
170 |
LoadData(); |
LoadData(); |
171 |
} |
} |
172 |
|
|
|
|
|
|
|
|
173 |
void ResultDetailsDialog::OnEnChangeStatus() |
void ResultDetailsDialog::OnEnChangeStatus() |
174 |
{ |
{ |
175 |
LoadData(); |
LoadData(); |
176 |
} |
} |
177 |
|
|
|
|
|
178 |
void ResultDetailsDialog::OnBnClickedClose() |
void ResultDetailsDialog::OnBnClickedClose() |
179 |
{ |
{ |
180 |
OnOK(); |
OnOK(); |
181 |
} |
} |
182 |
|
|
183 |
|
////////////////////////////////////////////////// |
184 |
|
|
185 |
|
void ResultDetailsDialog::OnBnClickedReturn() |
186 |
|
{ |
187 |
|
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode; |
188 |
|
|
189 |
|
CommonStorage::Instance()->getDBLayer()->ReturnEquipment(barcode); |
190 |
|
MessageBox("The Item is returned, but the changes won't show until the next query"); |
191 |
|
OnOK(); |
192 |
|
} |
193 |
|
|
194 |
|
void ResultDetailsDialog::OnBnClickedCheckout() |
195 |
|
{ |
196 |
|
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
197 |
|
CheckoutDialog check; |
198 |
|
|
199 |
|
check.m_checkoutMode = true; |
200 |
|
|
201 |
|
|
202 |
|
Reservation topReservation; |
203 |
|
if (status == "Reserveret") { |
204 |
|
topReservation = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[0]; |
205 |
|
check.m_reservedTo = topReservation.inits; |
206 |
|
} |
207 |
|
|
208 |
|
if (check.DoModal() == IDOK) |
209 |
|
{ |
210 |
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); |
211 |
|
Person p = dblayer->GetPerson(check.m_inits); |
212 |
|
|
213 |
|
Equipment eq; |
214 |
|
GetDlgItem(IDC_BARCODE)->GetWindowText(eq.barcode); |
215 |
|
|
216 |
|
dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) ); |
217 |
|
|
218 |
|
if (status == "Reserveret") { //if the equipment was reserved, we must delete the reservation |
219 |
|
dblayer->DeleteReservation(eq.barcode, topReservation.reservationID); |
220 |
|
} |
221 |
|
|
222 |
|
OnOK(); |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
|
void ResultDetailsDialog::OnBnClickedReserve() |
227 |
|
{ |
228 |
|
CheckoutDialog check; |
229 |
|
check.m_checkoutMode = false; |
230 |
|
if (check.DoModal() == IDOK) |
231 |
|
{ |
232 |
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); |
233 |
|
Person p = dblayer->GetPerson(check.m_inits); |
234 |
|
CString barcode; |
235 |
|
GetDlgItem(IDC_BARCODE)->GetWindowText(barcode); |
236 |
|
dblayer->EquipmentReservation(barcode,p); |
237 |
|
OnOK(); |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
void ResultDetailsDialog::OnBnClickedDelres() |
242 |
|
{ |
243 |
|
int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark(); |
244 |
|
if (sel != -1) { |
245 |
|
CString reservationID = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[sel].reservationID; |
246 |
|
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode; |
247 |
|
CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID); |
248 |
|
MessageBox("Reservation deleted, but won't show until next search"); |
249 |
|
} else { |
250 |
|
MessageBox("No reservation is selected"); |
251 |
|
} |
252 |
|
} |