6 |
#include "ResultDetailsDialog.h" |
#include "ResultDetailsDialog.h" |
7 |
#include ".\resultdetailsdialog.h" |
#include ".\resultdetailsdialog.h" |
8 |
#include "CommonStorage.h" |
#include "CommonStorage.h" |
9 |
|
#include "DatabaseLayer.h" |
10 |
|
#include "CheckoutDialog.h" |
11 |
|
|
12 |
// ResultDetailsDialog dialog |
// ResultDetailsDialog dialog |
13 |
|
|
35 |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
36 |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
37 |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
38 |
|
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 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
43 |
|
|
44 |
|
|
67 |
|
|
68 |
//load Equipment::checkouts |
//load Equipment::checkouts |
69 |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
70 |
|
checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT ); |
71 |
checkouts->InsertColumn(0,"Inits"); |
checkouts->InsertColumn(0,"Inits"); |
72 |
checkouts->InsertColumn(1,"Start date"); |
checkouts->InsertColumn(1,"Start date"); |
73 |
checkouts->InsertColumn(2,"Return date"); |
checkouts->InsertColumn(2,"Return date"); |
86 |
|
|
87 |
// load Equipment::reservations |
// load Equipment::reservations |
88 |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
89 |
reservations->InsertColumn(0,"Inits"); |
reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT ); |
90 |
reservations->InsertColumn(1,"Start date"); |
reservations->InsertColumn(0,"#"); |
91 |
reservations->InsertColumn(2,"Number of days"); |
reservations->InsertColumn(1,"Inits"); |
92 |
|
reservations->InsertColumn(2,"Reservation date"); |
93 |
|
|
94 |
|
|
95 |
for (int i=0; i<currentdata.reservations.size(); i++) { |
for (int i=0; i<currentdata.reservations.size(); i++) { |
96 |
int nItem = reservations->InsertItem(i, currentdata.reservations[i].inits); |
CString tmp; |
97 |
reservations->SetItemText(nItem,1, currentdata.reservations[i].startdate); |
tmp.Format("%d", i+1); |
98 |
reservations->SetItemText(nItem,2, currentdata.reservations[i].numdays); |
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 |
} |
} |
103 |
|
|
104 |
|
if (currentdata.reservations.size() > 0) |
105 |
|
GetDlgItem(IDC_DELRES)->EnableWindow(true); |
106 |
|
|
107 |
|
|
108 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
109 |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
110 |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
128 |
|
|
129 |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
130 |
|
|
131 |
if (status == "Ledig") |
if (status == "Ledig") { |
132 |
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
133 |
|
GetDlgItem(IDC_RESERVE)->EnableWindow(false); |
134 |
|
} |
135 |
|
|
136 |
if (status == "Udlånt") |
if (status == "Udlånt") |
137 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
138 |
if (status == "Reserveret") |
if (status == "Reserveret") |
144 |
return TRUE; |
return TRUE; |
145 |
} |
} |
146 |
|
|
147 |
|
///////////////////////////////////////////// |
148 |
|
// 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 |
void ResultDetailsDialog::OnEnChangeBarcode() |
void ResultDetailsDialog::OnEnChangeBarcode() |
152 |
{ |
{ |
153 |
LoadData(); |
LoadData(); |
168 |
LoadData(); |
LoadData(); |
169 |
} |
} |
170 |
|
|
|
|
|
|
|
|
171 |
void ResultDetailsDialog::OnEnChangeStatus() |
void ResultDetailsDialog::OnEnChangeStatus() |
172 |
{ |
{ |
173 |
LoadData(); |
LoadData(); |
174 |
} |
} |
175 |
|
|
|
|
|
176 |
void ResultDetailsDialog::OnBnClickedClose() |
void ResultDetailsDialog::OnBnClickedClose() |
177 |
{ |
{ |
178 |
OnOK(); |
OnOK(); |
179 |
} |
} |
180 |
|
|
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 |
|
} |